You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/10/27 10:52:52 UTC

svn commit: r1189681 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/xml/ camel-core/src/main/java/org/apache/camel/converter/jaxp/ components/camel-saxon/src/main/java/org/apache/camel/component/xquery/

Author: davsclaus
Date: Thu Oct 27 08:52:51 2011
New Revision: 1189681

URL: http://svn.apache.org/viewvc?rev=1189681&view=rev
Log:
CAMEL-4588: Converting to DOMSource should accept Node instead of Document, as it can then accept more types.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
    camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?rev=1189681&r1=1189680&r2=1189681&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java Thu Oct 27 08:52:51 2011
@@ -37,7 +37,7 @@ import javax.xml.transform.sax.SAXSource
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ExpectedBodyTypeException;
@@ -385,7 +385,9 @@ public class XsltBuilder implements Proc
             return false;
         } else if (body instanceof String) {
             return false;
-        } else if (body instanceof Document) {
+        } else if (body instanceof byte[]) {
+            return false;
+        } else if (body instanceof Node) {
             return false;
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=1189681&r1=1189680&r2=1189681&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Thu Oct 27 08:52:51 2011
@@ -174,21 +174,22 @@ public class XmlConverter {
     }
 
     /**
-     * Converts the given Document to a Source
+     * Converts the given Node to a Source
+     * @deprecated  use toDOMSource instead
      */
-    @Converter
-    public DOMSource toDOMSource(Document document) {
-        return new DOMSource(document);
+    @Deprecated
+    public Source toSource(Node node) {
+        return toDOMSource(node);
     }
 
     /**
      * Converts the given Node to a Source
      */
     @Converter
-    public Source toSource(Node node) {
+    public DOMSource toDOMSource(Node node) {
         return new DOMSource(node);
     }
-    
+
     /**
      * Converts the given String to a Source
      */
@@ -333,7 +334,6 @@ public class XmlConverter {
         return toSAXSource(toSource(source), exchange);
     }
 
-    
     /**
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not
      * supported (making it easy to derive from this class to add new kinds of conversion).
@@ -346,6 +346,17 @@ public class XmlConverter {
     }    
     
     /**
+     * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not
+     * supported (making it easy to derive from this class to add new kinds of conversion).
+     * @throws XMLStreamException
+     */
+    @Converter
+    public StAXSource toStAXSource(byte[] in, Exchange exchange) throws XMLStreamException {
+        XMLStreamReader r = new StaxConverter().createXMLStreamReader(new ByteArrayInputStream(in), exchange);
+        return new StAXSource(r);
+    }
+
+    /**
      * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
      * supported (making it easy to derive from this class to add new kinds of conversion).
      *
@@ -364,8 +375,16 @@ public class XmlConverter {
     public SAXSource toSAXSource(InputStream source, Exchange exchange) throws IOException, SAXException, TransformerException {
         return toSAXSource(toStreamSource(source), exchange);
     }
-    
-    
+
+    /**
+     * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
+     * supported (making it easy to derive from this class to add new kinds of conversion).
+     */
+    @Converter
+    public SAXSource toSAXSource(byte[] in, Exchange exchange) throws IOException, SAXException, TransformerException {
+        return toSAXSource(toStreamSource(in, exchange), exchange);
+    }
+
     /**
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not
      * supported (making it easy to derive from this class to add new kinds of conversion).
@@ -641,6 +660,7 @@ public class XmlConverter {
     public DOMSource toDOMSourceFromSAX(SAXSource source) throws IOException, SAXException, ParserConfigurationException, TransformerException {
         return new DOMSource(toDOMNodeFromSAX(source));
     }
+
     @Converter
     public DOMSource toDOMSourceFromStAX(StAXSource source) throws IOException, SAXException, ParserConfigurationException, TransformerException {
         return new DOMSource(toDOMNodeFromStAX(source));
@@ -652,6 +672,7 @@ public class XmlConverter {
         toResult(source, result);
         return result.getNode();
     }
+
     @Converter
     public Node toDOMNodeFromStAX(StAXSource source) throws ParserConfigurationException, IOException, SAXException, TransformerException {
         DOMResult result = new DOMResult();

Modified: camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java?rev=1189681&r1=1189680&r2=1189681&view=diff
==============================================================================
--- camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java (original)
+++ camel/trunk/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java Thu Oct 27 08:52:51 2011
@@ -527,7 +527,9 @@ public abstract class XQueryBuilder impl
             return false;
         } else if (body instanceof String) {
             return false;
-        } else if (body instanceof Document) {
+        } else if (body instanceof byte[]) {
+            return false;
+        } else if (body instanceof Node) {
             return false;
         }