package com.vci.server.omd.attribpool;
|
|
import java.io.File;
|
import java.sql.Timestamp;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Iterator;
|
import java.util.List;
|
import org.dom4j.Document;
|
import org.dom4j.DocumentException;
|
import org.dom4j.Element;
|
import org.dom4j.io.SAXReader;
|
|
import com.vci.common.log.ServerWithLog4j;
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.server.base.utility.AttributeHelper;
|
|
public class Xml2DBDelegate {
|
private static class InstanceHolder{
|
private static Xml2DBDelegate instance = new Xml2DBDelegate();
|
}
|
public static Xml2DBDelegate getInstance(){
|
return InstanceHolder.instance;
|
}
|
|
/**
|
* 最新的data文件
|
* @return
|
*/
|
private String getPath() {
|
String classPath = Xml2DBDelegate.class.getResource("").getPath();
|
String subPath;
|
String filePath;
|
if (classPath.contains("file:")) {
|
subPath = classPath.substring(classPath.indexOf("file:") + 6,
|
classPath.indexOf("plm-omd-server.jar"));
|
filePath = subPath + "properties/data_ap.xml";
|
} else {
|
subPath = classPath.substring(1, classPath.indexOf("PLM_PLMOMD"));
|
filePath = subPath + "PLM_PLMOMD/properties/data_ap.xml";
|
}
|
return handlerOS(filePath);
|
}
|
|
/**
|
* 处理不同OS的路径格式不同问题
|
* @param filePath
|
* @return
|
*/
|
private String handlerOS(String filePath){
|
String osName = System.getProperty("os.name");
|
//unix, linux
|
if(!osName.startsWith("Win")){
|
filePath = "/" + filePath.replace("\\", "/");
|
}
|
return filePath;
|
}
|
|
// private List<OldAttribItem> getOlds(){
|
// try{
|
// List<OldAttribItem> abItemList = new ArrayList<OldAttribItem>();
|
// OldAttribItem abItem = null;
|
// File xmlFile = new File(getPath());
|
// if(!xmlFile.exists()){
|
// return null;
|
// }
|
// SAXReader saxReader = new SAXReader();
|
//
|
// try {
|
// Document document = saxReader.read(xmlFile);
|
// Element rootNode = document.getRootElement();
|
// Element tableNode = rootNode.element(APServiceConstant.ATTRIBITEM);
|
// List<Element> rowNodes = tableNode.elements(APServiceConstant.ROW);
|
// for (Iterator<Element> i = rowNodes.iterator(); i.hasNext();) {
|
// Element rowNode = (Element) i.next();
|
// abItem = new OldAttribItem();
|
// abItem.name = rowNode.element("name").getText() == null ? ""
|
// : rowNode.element("name").getText();
|
// abItem.label = rowNode.element("label").getText() == null ? ""
|
// : rowNode.element("label").getText();
|
// abItem.descrip = rowNode.element("descrip").getText() == null ? ""
|
// : rowNode.element("descrip").getText();
|
// abItem.vtDataType = rowNode.element("vtDataType").getText() == null ? ""
|
// : rowNode.element("vtDataType").getText();
|
// abItem.defValue = rowNode.element("defValue").getText() == null ? ""
|
// : rowNode.element("defValue").getText();
|
// abItem.rage = rowNode.element("rage").getText() == null ? ""
|
// : rowNode.element("rage").getText();
|
// abItem.other = rowNode.element("other").getText() == null ? ""
|
// : rowNode.element("other").getText();
|
//
|
// abItemList.add(abItem);
|
// }
|
// } catch (DocumentException e) {
|
// //e.printStackTrace();
|
// ServerWithLog4j.logger.error(e);
|
// }
|
// return abItemList;
|
// }catch(Throwable e){
|
// //e.printStackTrace();
|
// ServerWithLog4j.logger.error(e);
|
// }
|
// return null;
|
// }
|
//
|
// public List<AttribItem> getNews(String userName){
|
// List<OldAttribItem> olds = getOlds();
|
// if(olds == null || olds.size() < 1){
|
// return null;
|
// }
|
// List<AttribItem> list = new ArrayList<AttribItem>();
|
// for(OldAttribItem old : olds){
|
// AttribItem o = new AttribItem();
|
// o.oid = ObjectUtility.getNewObjectID36();
|
// long time = Calendar.getInstance().getTimeInMillis();
|
// Timestamp ts = new Timestamp(time);
|
// o.ts = ApProvider.tsDF.format(ts);
|
// o.creator = userName;
|
// o.createTime = ApProvider.tsDF.format(ts);
|
// o.modifier = userName;
|
// o.modifyTime = ApProvider.tsDF.format(ts);
|
// o.name = old.name;
|
// o.label = old.label;
|
// o.description = old.descrip;
|
// o.vtDataType = old.vtDataType;
|
// o.defValue = old.defValue;
|
// o.rage = old.rage;
|
// o.other = old.other;
|
// list.add(o);
|
// }
|
// return list;
|
// }
|
}
|