XMPParse.java
6.0 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.airport.util.parse;
import com.airport.util.Utils;
import java.io.IOException;
import java.io.StringReader;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;
public class XMPParse {
public XMPParse() {
}
public static final Date nodeValue2Date(String xmlFile, String xmlNodePath) {
String str = getNodeValue(xmlFile, xmlNodePath);
return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : null;
}
public static final Date nodeValue2Date(String xmlFile, String xmlNodePath, Date date) {
String str = getNodeValue(xmlFile, xmlNodePath);
return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : date;
}
public static final Date nodeAttribute2Date(String xmlFile, String xmlNodePath, String attributeName, Date date) {
String str = getNodeAttribute(xmlFile, xmlNodePath, attributeName, "");
return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : date;
}
public static final String getNodeValue(String xmlFile, String xmlNodePath) {
String[] nodes = xmlNodePath.split("/");
new Document();
SAXBuilder builder = new SAXBuilder();
Element root = null;
LinkedList<SubNode> listNode = new LinkedList();
String value = "";
Document document;
try {
document = builder.build(xmlFile);
for(int i = 1; i < nodes.length; ++i) {
SubNode snode;
if (i > 1) {
snode = (SubNode)listNode.getLast();
List<Element> eList = snode.getElement().getChildren(nodes[i]);
if (eList != null && eList.size() > 0) {
SubNode s1 = new SubNode((Element)eList.get(0));
listNode.add(s1);
}
} else if (1 == i) {
root = document.getRootElement();
snode = new SubNode(root);
listNode.add(snode);
}
}
SubNode n = (SubNode)listNode.getLast();
value = n.getElement().getText();
n = null;
} catch (Exception var15) {
var15.printStackTrace();
} finally {
listNode.clear();
document = null;
root = null;
builder = null;
nodes = null;
}
System.out.println("key=" + xmlNodePath + " value=" + value);
return value;
}
public static final String getNodeValueFromXmlString(String xmlString, String xmlNodePath) throws Exception {
String[] nodes = xmlNodePath.split("/");
new Document();
SAXBuilder builder = new SAXBuilder();
Element root = null;
LinkedList<SubNode> listNode = new LinkedList();
String value = "";
Document document;
try {
StringReader xmlReader = new StringReader(xmlString);
InputSource xmlSource = new InputSource(xmlReader);
document = builder.build(xmlSource);
for(int i = 1; i < nodes.length; ++i) {
SubNode snode;
if (i > 1) {
snode = (SubNode)listNode.getLast();
List<Element> eList = snode.getElement().getChildren(nodes[i]);
if (eList != null && eList.size() > 0) {
SubNode s1 = new SubNode((Element)eList.get(0));
listNode.add(s1);
}
} else if (1 == i) {
root = document.getRootElement();
snode = new SubNode(root);
listNode.add(snode);
}
}
SubNode n = (SubNode)listNode.getLast();
value = n.getElement().getText();
n = null;
return value;
} catch (Exception var17) {
var17.printStackTrace();
throw var17;
} finally {
listNode.clear();
document = null;
root = null;
builder = null;
nodes = null;
}
}
public static final String getNodeAttribute(String xmlFile, String xmlNodePath, String attributeName, String defaultValue) {
String[] nodes = xmlNodePath.split("/");
new Document();
SAXBuilder builder = new SAXBuilder();
Element root = null;
LinkedList<SubNode> listNode = new LinkedList();
String value = "";
Document document;
try {
document = builder.build(xmlFile);
for(int i = 1; i < nodes.length; ++i) {
SubNode snode;
if (i > 1) {
snode = (SubNode)listNode.getLast();
List<Element> eList = snode.getElement().getChildren(nodes[i]);
if (eList != null && eList.size() > 0) {
SubNode s1 = new SubNode((Element)eList.get(0));
listNode.add(s1);
}
} else if (1 == i) {
root = document.getRootElement();
snode = new SubNode(root);
listNode.add(snode);
}
}
SubNode n = (SubNode)listNode.getLast();
value = n.getElement().getAttributeValue(attributeName, defaultValue);
n = null;
} catch (JDOMException var18) {
var18.printStackTrace();
} catch (IOException var19) {
var19.printStackTrace();
} finally {
listNode.clear();
document = null;
root = null;
builder = null;
nodes = null;
}
System.out.println("key=" + xmlNodePath + " node attrivte value=" + value);
return value;
}
}