@@ -106,6 +106,22 @@ public final class XMLDocument implements XML {
106
106
*/
107
107
private final transient Node cache ;
108
108
109
+ /**
110
+ * Public ctor, from a source.
111
+ *
112
+ * <p>The object is created with a default implementation of
113
+ * {@link NamespaceContext}, which already defines a
114
+ * number of namespaces, see {@link XMLDocument#XMLDocument(String)}.
115
+ *
116
+ * <p>An {@link IllegalArgumentException} is thrown if the parameter
117
+ * passed is not in XML format.
118
+ *
119
+ * @param source Source of XML document
120
+ */
121
+ public XMLDocument (final Source source ) {
122
+ this (XMLDocument .transform (source ));
123
+ }
124
+
109
125
/**
110
126
* Public ctor, from XML as a text.
111
127
*
@@ -125,11 +141,7 @@ public final class XMLDocument implements XML {
125
141
* @param text XML document body
126
142
*/
127
143
public XMLDocument (final String text ) {
128
- this (
129
- new DomParser (FACTORY , text ).document (),
130
- new XPathContext (),
131
- false
132
- );
144
+ this (new DomParser (XMLDocument .configuredDFactory (), text ).document ());
133
145
}
134
146
135
147
/**
@@ -151,29 +163,11 @@ public XMLDocument(final String text) {
151
163
* @param data The XML body
152
164
*/
153
165
public XMLDocument (final byte [] data ) {
154
- this (
155
- new DomParser (FACTORY , data ).document (),
156
- new XPathContext (),
157
- false
158
- );
166
+ this (new DomParser (XMLDocument .configuredDFactory (), data ).document ());
159
167
}
160
168
161
169
/**
162
- * Public ctor, from a DOM node.
163
- *
164
- * <p>The object is created with a default implementation of
165
- * {@link NamespaceContext}, which already defines a
166
- * number of namespaces, see {@link XMLDocument#XMLDocument(String)}.
167
- *
168
- * @param node DOM source
169
- * @since 0.2
170
- */
171
- public XMLDocument (final Node node ) {
172
- this (node , new XPathContext (), !(node instanceof Document ));
173
- }
174
-
175
- /**
176
- * Public ctor, from a source.
170
+ * Public ctor, from XML in a file.
177
171
*
178
172
* <p>The object is created with a default implementation of
179
173
* {@link NamespaceContext}, which already defines a
@@ -182,14 +176,15 @@ public XMLDocument(final Node node) {
182
176
* <p>An {@link IllegalArgumentException} is thrown if the parameter
183
177
* passed is not in XML format.
184
178
*
185
- * @param source Source of XML document
179
+ * @param file XML file
180
+ * @throws FileNotFoundException In case of I/O problems
186
181
*/
187
- public XMLDocument (final Source source ) {
188
- this (XMLDocument .transform ( source ), new XPathContext (), false );
182
+ public XMLDocument (final File file ) throws FileNotFoundException {
183
+ this (new DomParser ( XMLDocument .configuredDFactory ( ), file ). document () );
189
184
}
190
185
191
186
/**
192
- * Public ctor, from XML in a file .
187
+ * Public ctor, from input stream .
193
188
*
194
189
* <p>The object is created with a default implementation of
195
190
* {@link NamespaceContext}, which already defines a
@@ -198,12 +193,15 @@ public XMLDocument(final Source source) {
198
193
* <p>An {@link IllegalArgumentException} is thrown if the parameter
199
194
* passed is not in XML format.
200
195
*
201
- * @param file XML file
202
- * @throws FileNotFoundException In case of I/O problems
196
+ * <p>The provided input stream will be closed automatically after
197
+ * getting data from it.
198
+ *
199
+ * @param stream The input stream, which will be closed automatically
200
+ * @throws IOException In case of I/O problem
203
201
*/
204
- public XMLDocument ( final File file ) throws FileNotFoundException {
205
- // this(new TextResource(file).toString());
206
- this (new DomParser (FACTORY , file ).document ());
202
+ @ SuppressWarnings ( "PMD.ConstructorOnlyInitializesOrCallOtherConstructors" )
203
+ public XMLDocument ( final InputStream stream ) throws IOException {
204
+ this (new DomParser (XMLDocument . configuredDFactory (), stream ).document ());
207
205
}
208
206
209
207
/**
@@ -220,7 +218,7 @@ public XMLDocument(final File file) throws FileNotFoundException {
220
218
* @throws FileNotFoundException In case of I/O problems
221
219
*/
222
220
public XMLDocument (final Path file ) throws FileNotFoundException {
223
- this (file .toFile ());
221
+ this (new DomParser ( XMLDocument . configuredDFactory (), file .toFile ()). document ());
224
222
}
225
223
226
224
/**
@@ -258,25 +256,17 @@ public XMLDocument(final URI uri) throws IOException {
258
256
}
259
257
260
258
/**
261
- * Public ctor, from input stream .
259
+ * Public ctor, from a DOM node .
262
260
*
263
261
* <p>The object is created with a default implementation of
264
262
* {@link NamespaceContext}, which already defines a
265
263
* number of namespaces, see {@link XMLDocument#XMLDocument(String)}.
266
264
*
267
- * <p>An {@link IllegalArgumentException} is thrown if the parameter
268
- * passed is not in XML format.
269
- *
270
- * <p>The provided input stream will be closed automatically after
271
- * getting data from it.
272
- *
273
- * @param stream The input stream, which will be closed automatically
274
- * @throws IOException In case of I/O problem
265
+ * @param node DOM source
266
+ * @since 0.2
275
267
*/
276
- @ SuppressWarnings ("PMD.ConstructorOnlyInitializesOrCallOtherConstructors" )
277
- public XMLDocument (final InputStream stream ) throws IOException {
278
- this (new TextResource (stream ).toString ());
279
- stream .close ();
268
+ public XMLDocument (final Node node ) {
269
+ this (node , new XPathContext (), !(node instanceof Document ));
280
270
}
281
271
282
272
/**
@@ -488,7 +478,7 @@ public Collection<SAXParseException> validate(final Schema schema) {
488
478
* @return A cloned node imported in a dedicated document.
489
479
*/
490
480
private static Node createImportedNode (final Node node ) {
491
- final DocumentBuilderFactory factory = FACTORY ;
481
+ final DocumentBuilderFactory factory = XMLDocument . configuredDFactory () ;
492
482
final DocumentBuilder builder ;
493
483
try {
494
484
builder = factory .newDocumentBuilder ();
@@ -609,8 +599,6 @@ private static Node transform(final Source source) {
609
599
return result .getNode ();
610
600
}
611
601
612
- private static final DocumentBuilderFactory FACTORY = XMLDocument .configuredDFactory ();
613
-
614
602
/**
615
603
* Create new {@link DocumentBuilderFactory} and configure it.
616
604
* @return Configured factory
0 commit comments