@@ -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 (XMLDocument .configuredDFactory (), 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 (XMLDocument .configuredDFactory (), 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,10 +176,11 @@ 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
/**
@@ -201,12 +196,12 @@ public XMLDocument(final Source source) {
201
196
* @param file XML file
202
197
* @throws FileNotFoundException In case of I/O problems
203
198
*/
204
- public XMLDocument (final File file ) throws FileNotFoundException {
205
- this (new TextResource ( file ). toString ());
199
+ public XMLDocument (final Path file ) throws FileNotFoundException {
200
+ this (new DomParser ( XMLDocument . configuredDFactory (), file . toFile ()). document ());
206
201
}
207
202
208
203
/**
209
- * Public ctor, from XML in a file .
204
+ * Public ctor, from input stream .
210
205
*
211
206
* <p>The object is created with a default implementation of
212
207
* {@link NamespaceContext}, which already defines a
@@ -215,11 +210,16 @@ public XMLDocument(final File file) throws FileNotFoundException {
215
210
* <p>An {@link IllegalArgumentException} is thrown if the parameter
216
211
* passed is not in XML format.
217
212
*
218
- * @param file XML file
219
- * @throws FileNotFoundException In case of I/O problems
213
+ * <p>The provided input stream will be closed automatically after
214
+ * getting data from it.
215
+ *
216
+ * @param stream The input stream, which will be closed automatically
217
+ * @throws IOException In case of I/O problem
220
218
*/
221
- public XMLDocument (final Path file ) throws FileNotFoundException {
222
- this (file .toFile ());
219
+ @ SuppressWarnings ("PMD.ConstructorOnlyInitializesOrCallOtherConstructors" )
220
+ public XMLDocument (final InputStream stream ) throws IOException {
221
+ this (new TextResource (stream ).toString ());
222
+ stream .close ();
223
223
}
224
224
225
225
/**
@@ -257,25 +257,17 @@ public XMLDocument(final URI uri) throws IOException {
257
257
}
258
258
259
259
/**
260
- * Public ctor, from input stream .
260
+ * Public ctor, from a DOM node .
261
261
*
262
262
* <p>The object is created with a default implementation of
263
263
* {@link NamespaceContext}, which already defines a
264
264
* number of namespaces, see {@link XMLDocument#XMLDocument(String)}.
265
265
*
266
- * <p>An {@link IllegalArgumentException} is thrown if the parameter
267
- * passed is not in XML format.
268
- *
269
- * <p>The provided input stream will be closed automatically after
270
- * getting data from it.
271
- *
272
- * @param stream The input stream, which will be closed automatically
273
- * @throws IOException In case of I/O problem
266
+ * @param node DOM source
267
+ * @since 0.2
274
268
*/
275
- @ SuppressWarnings ("PMD.ConstructorOnlyInitializesOrCallOtherConstructors" )
276
- public XMLDocument (final InputStream stream ) throws IOException {
277
- this (new TextResource (stream ).toString ());
278
- stream .close ();
269
+ public XMLDocument (final Node node ) {
270
+ this (node , new XPathContext (), !(node instanceof Document ));
279
271
}
280
272
281
273
/**
@@ -316,8 +308,24 @@ public int hashCode() {
316
308
return this .cache .hashCode ();
317
309
}
318
310
319
- @ Override
311
+ /**
312
+ * Retrieve DOM node, represented by this wrapper.
313
+ * This method works exactly the same as {@link #deepCopy()}.
314
+ * @deprecated Use {@link #inner()} or {@link #deepCopy()} instead.
315
+ * @return Deep copy of the inner DOM node.
316
+ */
317
+ @ Deprecated
320
318
public Node node () {
319
+ return this .deepCopy ();
320
+ }
321
+
322
+ @ Override
323
+ public Node inner () {
324
+ return this .cache ;
325
+ }
326
+
327
+ @ Override
328
+ public Node deepCopy () {
321
329
final Node casted = this .cache ;
322
330
final Node answer ;
323
331
if (casted instanceof Document ) {
0 commit comments