You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/01/05 16:10:38 UTC

svn commit: r731592 - in /activemq/camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Author: janstey
Date: Mon Jan  5 07:10:38 2009
New Revision: 731592

URL: http://svn.apache.org/viewvc?rev=731592&view=rev
Log:
Merged revisions 731590 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r731590 | janstey | 2009-01-05 11:34:33 -0330 (Mon, 05 Jan 2009) | 1 line
  
  CAMEL-1225 - Remove duplicate type converter, they were both doing exactly the same thing.
........

Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=731592&r1=731591&r2=731592&view=diff
==============================================================================
--- activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Mon Jan  5 07:10:38 2009
@@ -42,18 +42,13 @@
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URL;
-import java.util.Properties;
 
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
+import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.util.CollectionStringBuffer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -67,6 +62,7 @@
 @Converter
 public final class IOConverter {
     private static final transient Log LOG = LogFactory.getLog(IOConverter.class);
+    private static XmlConverter xmlConverter;
 
     /**
      * Utility classes should not have a public constructor.
@@ -151,10 +147,18 @@
 
     @Converter
     public static InputStream toInputStrean(DOMSource source) throws TransformerException, IOException {
-        ByteArrayInputStream bais = new ByteArrayInputStream(toString(source).getBytes());
+        XmlConverter xmlConverter = createXmlConverter();
+        ByteArrayInputStream bais = new ByteArrayInputStream(xmlConverter.toString(source).getBytes());
         return bais;
     }
 
+    private static XmlConverter createXmlConverter() {
+        if (xmlConverter == null) {
+            xmlConverter = new XmlConverter();
+        }
+        return xmlConverter;
+    }
+
     @Converter
     public static String toString(byte[] data, Exchange exchange) {
         if (exchange != null) {
@@ -256,11 +260,6 @@
     }
 
     @Converter
-    public static String toString(Source source) throws TransformerException, IOException {
-        return toString(source, null);
-    }
-
-    @Converter
     public static InputStream toInputStream(byte[] data) {
         return new ByteArrayInputStream(data);
     }
@@ -299,22 +298,4 @@
         }
         os.flush();
     }
-
-    protected static String toString(Source source, Properties props) throws TransformerException, IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        try {
-            StreamResult sr = new StreamResult(bos);
-            Transformer trans = TransformerFactory.newInstance().newTransformer();
-            if (props == null) {
-                props = new Properties();
-                props.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
-            }
-            trans.setOutputProperties(props);
-            trans.transform(source, sr);
-        } finally {
-            bos.close();
-        }
-        return bos.toString();
-    }
-
 }