camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1071901 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/converter/jaxp/XmlConverter.java test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
Date Fri, 18 Feb 2011 06:57:40 GMT
Author: davsclaus
Date: Fri Feb 18 06:57:40 2011
New Revision: 1071901

URL: http://svn.apache.org/viewvc?rev=1071901&view=rev
Log:
CAMEL-3681: Added byte[] to DOMSource converter.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java

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=1071901&r1=1071900&r2=1071901&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
Fri Feb 18 06:57:40 2011
@@ -54,6 +54,7 @@ import org.xml.sax.XMLReader;
 
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
+import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -286,7 +287,21 @@ public class XmlConverter {
         }
     }
 
-    
+    /**
+     * Converts the source instance to a {@link DOMSource} 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 DOMSource toDOMSource(byte[] bytes) throws IOException, SAXException, ParserConfigurationException
{
+        InputStream is = new ByteArrayInputStream(bytes);
+        try {
+            return toDOMSource(is);
+        } finally {
+            IOHelper.close(is);
+        }
+    }
+
+
     /**
      * 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).

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java?rev=1071901&r1=1071900&r2=1071901&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
Fri Feb 18 06:57:40 2011
@@ -116,6 +116,17 @@ public class XmlConverterTest extends Co
         assertSame(source, out);
     }
 
+    public void testToDomSourceByByteArray() throws Exception {
+        XmlConverter conv = new XmlConverter();
+
+        byte[] bytes = "<foo>bar</foo>".getBytes();
+        DOMSource source = conv.toDOMSource(bytes);
+        assertNotNull(source);
+
+        byte[] out = conv.toByteArray(source, null);
+        assertEquals(new String(bytes), new String(out));
+    }
+
     public void testToDomSourceByStaxSource() throws Exception {
         XmlConverter conv = new XmlConverter();
 



Mime
View raw message