From 86ee414a3a38a5038f9cfbcefbf55fab46e64378 Mon Sep 17 00:00:00 2001 From: George Aristy Date: Sun, 4 Mar 2018 13:13:15 -0400 Subject: [PATCH 1/3] Ability to directly append an XML to Directives --- pom.xml | 2 +- src/main/java/org/xembly/Directives.java | 12 ++++++++ src/test/java/org/xembly/DirectivesTest.java | 30 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ffc8adc..320f88f1 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ com.jcabi jcabi-xml - test + provided org.apache.commons diff --git a/src/main/java/org/xembly/Directives.java b/src/main/java/org/xembly/Directives.java index b15d239b..1beff2b3 100644 --- a/src/main/java/org/xembly/Directives.java +++ b/src/main/java/org/xembly/Directives.java @@ -29,6 +29,7 @@ */ package org.xembly; +import com.jcabi.xml.XML; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -254,6 +255,17 @@ public Directives append(final Iterable dirs) { return this; } + /** + * Appends the {@link XML xml}. + * @param xml The xml to append + * @return This object + * @see #append(java.lang.Iterable) + * @see Directives#copyOf(org.w3c.dom.Node) + */ + public Directives append(final XML xml) { + return this.append(Directives.copyOf(xml.node())); + } + /** * Add node to all current nodes. * @param name Name of the node to add diff --git a/src/test/java/org/xembly/DirectivesTest.java b/src/test/java/org/xembly/DirectivesTest.java index 6fcf2412..57789689 100644 --- a/src/test/java/org/xembly/DirectivesTest.java +++ b/src/test/java/org/xembly/DirectivesTest.java @@ -214,6 +214,36 @@ public void copiesExistingNode() throws Exception { ); } + /** + * Directives can copy an existing XML. + * @throws Exception If some problem inside + * @since 1.0 + */ + @Test + public void copiesExistingXml() throws Exception { + final Document dom = DocumentBuilderFactory.newInstance() + .newDocumentBuilder().newDocument(); + new Xembler( + new Directives().add("guys").append( + new XMLDocument( + StringUtils.join( + "", + "\u20ac", + " " + ) + ) + ) + ).apply(dom); + MatcherAssert.assertThat( + XhtmlMatchers.xhtml(dom), + XhtmlMatchers.hasXPaths( + "/guys/joe[@name = 'Joey']", + "/guys/joe[first and second]", + "/guys/joe/io[@a='x']/f[name='\u20ac']" + ) + ); + } + /** * Directives can understand case. * @throws Exception If some problem inside From cc19bb135c7976d30c1f3dfa112c5718034bb4e6 Mon Sep 17 00:00:00 2001 From: George Aristy Date: Tue, 13 Mar 2018 14:56:16 -0400 Subject: [PATCH 2/3] As per PR review: * Removed jcabi-xml as a runtime dependency * Directives.append now appends Nodes --- pom.xml | 2 +- src/main/java/org/xembly/Directives.java | 9 ++++----- src/test/java/org/xembly/DirectivesTest.java | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 320f88f1..2ffc8adc 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ com.jcabi jcabi-xml - provided + test org.apache.commons diff --git a/src/main/java/org/xembly/Directives.java b/src/main/java/org/xembly/Directives.java index 1beff2b3..07ba893d 100644 --- a/src/main/java/org/xembly/Directives.java +++ b/src/main/java/org/xembly/Directives.java @@ -29,7 +29,6 @@ */ package org.xembly; -import com.jcabi.xml.XML; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -256,14 +255,14 @@ public Directives append(final Iterable dirs) { } /** - * Appends the {@link XML xml}. - * @param xml The xml to append + * Appends the {@link Node node}. + * @param node The node to append * @return This object * @see #append(java.lang.Iterable) * @see Directives#copyOf(org.w3c.dom.Node) */ - public Directives append(final XML xml) { - return this.append(Directives.copyOf(xml.node())); + public Directives append(final Node node) { + return this.append(Directives.copyOf(node)); } /** diff --git a/src/test/java/org/xembly/DirectivesTest.java b/src/test/java/org/xembly/DirectivesTest.java index 57789689..56447d67 100644 --- a/src/test/java/org/xembly/DirectivesTest.java +++ b/src/test/java/org/xembly/DirectivesTest.java @@ -215,12 +215,12 @@ public void copiesExistingNode() throws Exception { } /** - * Directives can copy an existing XML. + * Appends an existing node. * @throws Exception If some problem inside * @since 1.0 */ @Test - public void copiesExistingXml() throws Exception { + public void appendsExistingNode() throws Exception { final Document dom = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); new Xembler( @@ -231,7 +231,7 @@ public void copiesExistingXml() throws Exception { "\u20ac", " " ) - ) + ).node() ) ).apply(dom); MatcherAssert.assertThat( From 35385af641c110c21c0b6af59835b9370a5d674b Mon Sep 17 00:00:00 2001 From: George Aristy Date: Thu, 15 Mar 2018 17:31:47 -0400 Subject: [PATCH 3/3] As per PR review: * Added missing @since javadoc tag --- src/main/java/org/xembly/Directives.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/xembly/Directives.java b/src/main/java/org/xembly/Directives.java index 07ba893d..cd2957d0 100644 --- a/src/main/java/org/xembly/Directives.java +++ b/src/main/java/org/xembly/Directives.java @@ -260,6 +260,7 @@ public Directives append(final Iterable dirs) { * @return This object * @see #append(java.lang.Iterable) * @see Directives#copyOf(org.w3c.dom.Node) + * @since 0.23 */ public Directives append(final Node node) { return this.append(Directives.copyOf(node));