ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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;
//    }
}