diff --git a/src/main/java/com/jcabi/xml/StrictXML.java b/src/main/java/com/jcabi/xml/StrictXML.java index d5d0903b..1e18ee51 100755 --- a/src/main/java/com/jcabi/xml/StrictXML.java +++ b/src/main/java/com/jcabi/xml/StrictXML.java @@ -158,7 +158,7 @@ public XML merge(final NamespaceContext context) { @Override public Node node() { - return this.origin.node(); + return this.origin.deepCopy(); } @Override @@ -270,7 +270,7 @@ private static Collection validate( validator.setErrorHandler( new XMLDocument.ValidationHandler(errors) ); - final DOMSource dom = new DOMSource(xml.node()); + final DOMSource dom = new DOMSource(xml.inner()); for (int retry = 1; retry <= max; ++retry) { try { validator.validate(dom); diff --git a/src/main/java/com/jcabi/xml/XML.java b/src/main/java/com/jcabi/xml/XML.java index 395c1bfc..cfa30423 100644 --- a/src/main/java/com/jcabi/xml/XML.java +++ b/src/main/java/com/jcabi/xml/XML.java @@ -46,8 +46,8 @@ * // ... * } * - *

You can always get DOM node out of this abstraction using {@link #node()} - * method. + *

You can always get DOM node out of this abstraction using {@link #inner()} + * or {@link #deepCopy()} methods. * *

{@code toString()} must produce a full XML. * @@ -165,7 +165,7 @@ public interface XML { * This method works exactly the same as {@link #deepCopy()}. * @return DOM node */ -// @Deprecated + @Deprecated Node node(); /** diff --git a/src/main/java/com/jcabi/xml/XMLDocument.java b/src/main/java/com/jcabi/xml/XMLDocument.java index f8688cdc..0ea0c0b7 100644 --- a/src/main/java/com/jcabi/xml/XMLDocument.java +++ b/src/main/java/com/jcabi/xml/XMLDocument.java @@ -310,14 +310,7 @@ public int hashCode() { @Override public Node node() { - final Node casted = this.cache; - final Node answer; - if (casted instanceof Document) { - answer = casted.cloneNode(true); - } else { - answer = XMLDocument.createImportedNode(casted); - } - return answer; + return this.deepCopy(); } @Override @@ -327,7 +320,14 @@ public Node inner() { @Override public Node deepCopy() { - return this.node(); + final Node casted = this.cache; + final Node answer; + if (casted instanceof Document) { + answer = casted.cloneNode(true); + } else { + answer = XMLDocument.createImportedNode(casted); + } + return answer; } @Override diff --git a/src/main/java/com/jcabi/xml/XSLDocument.java b/src/main/java/com/jcabi/xml/XSLDocument.java index 2da2d66e..50138095 100644 --- a/src/main/java/com/jcabi/xml/XSLDocument.java +++ b/src/main/java/com/jcabi/xml/XSLDocument.java @@ -434,7 +434,7 @@ private void transformInto(final XML xml, final Result result) { trans.setErrorListener(errors); final long start = System.nanoTime(); try { - trans.transform(new DOMSource(xml.node()), result); + trans.transform(new DOMSource(xml.inner()), result); } catch (final TransformerException ex) { final StringBuilder summary = new StringBuilder( String.join("; ", errors.summary()) diff --git a/src/test/java/com/jcabi/xml/XMLDocumentTest.java b/src/test/java/com/jcabi/xml/XMLDocumentTest.java index 38c59fb0..c4acda03 100644 --- a/src/test/java/com/jcabi/xml/XMLDocumentTest.java +++ b/src/test/java/com/jcabi/xml/XMLDocumentTest.java @@ -190,7 +190,7 @@ void printsWithNamespace() { new XMLDocument( new XMLDocument( "" - ).node() + ).inner() ).toString(), Matchers.containsString("a:boom") ); @@ -202,11 +202,11 @@ void retrievesDomNode() throws Exception { this.getClass().getResource("simple.xml") ); MatcherAssert.assertThat( - doc.nodes("/root/simple").get(0).node().getNodeName(), + doc.nodes("/root/simple").get(0).inner().getNodeName(), Matchers.equalTo("simple") ); MatcherAssert.assertThat( - doc.nodes("//simple").get(0).node().getNodeType(), + doc.nodes("//simple").get(0).inner().getNodeType(), Matchers.equalTo(Node.ELEMENT_NODE) ); } @@ -392,7 +392,7 @@ void takesNodeInMultipleThreads() throws Exception { final Runnable runnable = () -> { try { MatcherAssert.assertThat( - new XMLDocument(xml.node()).toString(), + new XMLDocument(xml.inner()).toString(), Matchers.containsString(">5555<") ); done.incrementAndGet(); @@ -434,11 +434,11 @@ void performsXpathCalculations() { void buildsDomNode() { final XML doc = new XMLDocument(""); MatcherAssert.assertThat( - doc.node(), + doc.inner(), Matchers.instanceOf(Document.class) ); MatcherAssert.assertThat( - doc.nodes("/f").get(0).node(), + doc.nodes("/f").get(0).inner(), Matchers.instanceOf(Element.class) ); } @@ -486,7 +486,7 @@ void preservesXmlNamespaces() { @Test void preservesImmutability() { final XML xml = new XMLDocument(""); - final Node node = xml.nodes("/r1/a").get(0).node(); + final Node node = xml.nodes("/r1/a").get(0).deepCopy(); node.appendChild(node.getOwnerDocument().createElement("h9")); MatcherAssert.assertThat( xml,