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:04:33 UTC
svn commit: r731590 -
/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
Author: janstey
Date: Mon Jan 5 07:04:33 2009
New Revision: 731590
URL: http://svn.apache.org/viewvc?rev=731590&view=rev
Log:
CAMEL-1225 - Remove duplicate type converter, they were both doing exactly the same thing.
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=731590&r1=731589&r2=731590&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Mon Jan 5 07:04:33 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();
- }
-
}