13
13
import javax .xml .xpath .XPathConstants ;
14
14
import javax .xml .xpath .XPathFactory ;
15
15
import java .io .Reader ;
16
+ import java .io .StringReader ;
16
17
import java .util .ArrayList ;
17
18
import java .util .List ;
18
19
import java .util .Properties ;
@@ -25,22 +26,52 @@ public class XPathParser {
25
26
private Properties variables ;
26
27
private XPath xpath ;
27
28
28
- public XPathParser (Reader reader , boolean validation , EntityResolver entityResolver , Properties variables ) {
29
- this .validation = validation ;
30
- this .entityResolver = entityResolver ;
31
- this .variables = variables ;
32
- this .document = createDocument (reader );
33
- XPathFactory factory = XPathFactory .newInstance ();
34
- this .xpath = factory .newXPath ();
29
+ public XPathParser (String xml ) {
30
+ commonConstructor (createDocument (new StringReader (xml )), false , null , null );
35
31
}
36
32
37
- public XPathParser (Document document , boolean validation , EntityResolver entityResolver , Properties variables ) {
38
- this .validation = validation ;
39
- this .entityResolver = entityResolver ;
40
- this .variables = variables ;
41
- this .document = document ;
42
- XPathFactory factory = XPathFactory .newInstance ();
43
- this .xpath = factory .newXPath ();
33
+ public XPathParser (Reader reader ) {
34
+ commonConstructor (createDocument (reader ), false , null , null );
35
+ }
36
+
37
+ public XPathParser (Document document ) {
38
+ commonConstructor (document , false , null , null );
39
+ }
40
+
41
+ public XPathParser (String xml , boolean validation ) {
42
+ commonConstructor (createDocument (new StringReader (xml )), validation , null , null );
43
+ }
44
+
45
+ public XPathParser (Reader reader , boolean validation ) {
46
+ commonConstructor (createDocument (reader ), validation , null , null );
47
+ }
48
+
49
+ public XPathParser (Document document , boolean validation ) {
50
+ commonConstructor (document , validation , null , null );
51
+ }
52
+
53
+ public XPathParser (String xml , boolean validation , Properties variables ) {
54
+ commonConstructor (createDocument (new StringReader (xml )), validation , variables , null );
55
+ }
56
+
57
+ public XPathParser (Reader reader , boolean validation , Properties variables ) {
58
+ commonConstructor (createDocument (reader ), validation , variables , null );
59
+ }
60
+
61
+ public XPathParser (Document document , boolean validation , Properties variables ) {
62
+ commonConstructor (document , validation , variables , null );
63
+ }
64
+
65
+ public XPathParser (String xml , boolean validation , Properties variables , EntityResolver entityResolver ) {
66
+ commonConstructor (createDocument (new StringReader (xml )), validation , variables , entityResolver );
67
+ }
68
+
69
+ public XPathParser (Reader reader , boolean validation , Properties variables , EntityResolver entityResolver ) {
70
+ commonConstructor (createDocument (reader ), validation , variables , entityResolver );
71
+ }
72
+
73
+ public XPathParser (Document document , boolean validation , Properties variables , EntityResolver entityResolver ) {
74
+ commonConstructor (document , validation , variables , entityResolver );
44
75
}
45
76
46
77
public void setVariables (Properties variables ) {
@@ -65,6 +96,38 @@ public Boolean evalBoolean(Object root, String expression) {
65
96
return (Boolean ) evaluate (expression , root , XPathConstants .BOOLEAN );
66
97
}
67
98
99
+ public Short evalShort (String expression ) {
100
+ return evalShort (document , expression );
101
+ }
102
+
103
+ public Short evalShort (Object root , String expression ) {
104
+ return Short .valueOf (evalString (root , expression ));
105
+ }
106
+
107
+ public Integer evalInteger (String expression ) {
108
+ return evalInteger (document , expression );
109
+ }
110
+
111
+ public Integer evalInteger (Object root , String expression ) {
112
+ return Integer .valueOf (evalString (root , expression ));
113
+ }
114
+
115
+ public Long evalLong (String expression ) {
116
+ return evalLong (document , expression );
117
+ }
118
+
119
+ public Long evalLong (Object root , String expression ) {
120
+ return Long .valueOf (evalString (root , expression ));
121
+ }
122
+
123
+ public Float evalFloat (String expression ) {
124
+ return evalFloat (document , expression );
125
+ }
126
+
127
+ public Float evalFloat (Object root , String expression ) {
128
+ return Float .valueOf (evalString (root , expression ));
129
+ }
130
+
68
131
public Double evalDouble (String expression ) {
69
132
return evalDouble (document , expression );
70
133
}
@@ -137,4 +200,13 @@ public void warning(SAXParseException exception) throws SAXException {
137
200
}
138
201
}
139
202
203
+ private void commonConstructor (Document document , boolean validation , Properties variables , EntityResolver entityResolver ) {
204
+ this .validation = validation ;
205
+ this .entityResolver = entityResolver ;
206
+ this .variables = variables ;
207
+ this .document = document ;
208
+ XPathFactory factory = XPathFactory .newInstance ();
209
+ this .xpath = factory .newXPath ();
210
+ }
211
+
140
212
}
0 commit comments