Rewrite converting Node to GPathResult
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e657822b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e657822b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e657822b Branch: refs/heads/master Commit: e657822b7d905af1951765211dae7d205f18acaf Parents: c9e26a5 Author: Dominik Adam Przybysz <alien11...@gmail.com> Authored: Sun Aug 17 22:38:56 2014 +0200 Committer: Dominik Adam Przybysz <alien11...@gmail.com> Committed: Sun Aug 17 22:38:56 2014 +0200 ---------------------------------------------------------------------- .../camel/groovy/converter/GPathResultConverter.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e657822b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java index e5008a8..f3c9118 100644 --- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java +++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java @@ -4,7 +4,9 @@ import groovy.util.XmlSlurper; import groovy.util.slurpersupport.GPathResult; import groovy.xml.StreamingMarkupBuilder; import org.apache.camel.Converter; +import org.apache.camel.Exchange; import org.apache.camel.StringSource; +import org.apache.camel.converter.jaxp.XmlConverter; import org.w3c.dom.Node; import org.xml.sax.SAXException; @@ -21,21 +23,20 @@ import java.io.StringWriter; @Converter public class GPathResultConverter { + private final XmlConverter xmlConverter = new XmlConverter(); + @Converter - public static GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException { + public GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException { return new XmlSlurper().parseText(input); } @Converter - public static GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException { + public GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException { return fromString(input.getText()); } @Converter - public static GPathResult fromNode(Node input) throws IOException, SAXException, ParserConfigurationException, TransformerException { - StringWriter writer = new StringWriter(); - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.transform(new DOMSource(input), new StreamResult(writer)); - return fromString(writer.toString()); + public GPathResult fromNode(Node input, Exchange exchange) throws IOException, SAXException, ParserConfigurationException, TransformerException { + return fromString(xmlConverter.toString(input, exchange)); } }