根据界面上的button增加、删除、重命名文件夹,名字是数据库下面某一表单的某一列的名字代码如下:
package com.efounder.finereport.plugin;
import com.efounder.bz.service.ServicePluginAdapter;
..........
import java.io.File;
public class FineReportModuleProcessPlugins extends ServicePluginAdapter {
public FineReportModuleProcessPlugins(){}
public Object prepareMDMLoader(MDMContext mdmContext,EFMDMDataModel mdmDataModel) throws Exception {
return null;
}
public Object processMDMLoader(MDMContext mdmContext,EFMDMDataModel mdmDataModel) throws Exception {
// 获取元数据
DCTMetaData dctMetaData = mdmContext.getDCTMetaData();
if ( dctMetaData == null ) return null;
JParamObject PO = mdmContext.getParamObject();
EFDataSet updateDataSet = mdmDataModel.getDataSet(mdmDataModel.getDCT_ID()+"_UPDATE");
EFDataSet insertDataSet = mdmDataModel.getDataSet(mdmDataModel.getDCT_ID()+"_INSERT");
EFDataSet deleteDataSet = mdmDataModel.getDataSet(mdmDataModel.getDCT_ID()+"_DELETE");
// updateFlie(updateDataSet);
insertFlie(insertDataSet);
deleteFlie(deleteDataSet);
return null;
}
//重命名
public static void updateFlie(EFDataSet updateDataSet){
String fileName="";
for(int i=0;i<updateDataSet.getRowCount();i++){
EFRowSet rowset = updateDataSet.getRowSet(i);
fileName = rowset.getString("MODULE_BH", "");
//得到enterprisesever
String eaiRoot = EAI.LocalUserHome;
//创建斜杠
String Separator = System.getProperty("file.separator");
if (eaiRoot.endsWith("/") || eaiRoot.endsWith("\\")) {
eaiRoot = eaiRoot.substring(0, eaiRoot.length() - 1);
eaiRoot = eaiRoot + Separator + "WEB-INF" + Separator + "reportlets";
}
File file = new File(eaiRoot);
if (file.exists()) {
file.renameTo(new File(fileName));
}
}
}
//新建
public static boolean insertFlie(EFDataSet insertDataSet){
String fileName="";
for(int i=0;i<insertDataSet.getRowCount();i++){
EFRowSet rowset = insertDataSet.getRowSet(i);
fileName = rowset.getString("MODULE_BH", ""); //MODULE_BH是列名
String eaiRoot = EAI.LocalUserHome;
String Separator = System.getProperty("file.separator");
if (eaiRoot.endsWith("/") || eaiRoot.endsWith("\\")) {
eaiRoot = eaiRoot.substring(0, eaiRoot.length() - 1);
eaiRoot = eaiRoot + Separator + "WEB-INF" + Separator + "reportlets";
}
File file = new File(eaiRoot+Separator+fileName);
//如果文件夹不存在则创建
if(!file.exists()&&!file.isDirectory()){
file .mkdir();
}else {
System.out.println("//目录存在");
}
}
return false;
}
//删除
public static boolean deleteFlie(EFDataSet deleteDataSet){
String fileName="";
boolean flag=false;
for(int i=0;i<deleteDataSet.getRowCount();i++){
EFRowSet rowset = deleteDataSet.getRowSet(i);
fileName = rowset.getString("MODULE_BH", "");
}
String eaiRoot = EAI.LocalUserHome;
String Separator = System.getProperty("file.separator");
if (eaiRoot.endsWith("/") || eaiRoot.endsWith("\\")) {
eaiRoot = eaiRoot.substring(0, eaiRoot.length() - 1);
eaiRoot = eaiRoot + Separator + "WEB-INF" + Separator + "reportlets";
}
File file = new File(eaiRoot+Separator+fileName);
// 路径为文件且不为空则进行删除
if (file.isDirectory() && file.exists()) {
file.delete();
flag = true;
}
return flag;
}
}