Author: cschneider
Date: Thu Aug 25 13:30:37 2011
New Revision: 1161561

URL: http://svn.apache.org/viewvc?rev=1161561&view=rev
Log:
Move BytesSource and StringSource from converter to api as they are used from 
several places including util which should not know about converters

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/BytesSource.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/StringSource.java
Removed:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/SourceCache.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/BytesSourceTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyStreamsTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamSourceContentBasedRouterTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidatingProcessorFromSourceTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/BytesSource.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/BytesSource.java?rev=1161561&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/BytesSource.java 
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/BytesSource.java Thu 
Aug 25 13:30:37 2011
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Serializable;
+
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * A helper class which provides a JAXP {@link javax.xml.transform.Source 
Source} from a byte[]
+ * which can be read as many times as required.
+ *
+ * @version 
+ */
+public class BytesSource extends StreamSource implements Serializable {
+    private static final long serialVersionUID = 124123201106542082L;
+
+    private final byte[] data;
+
+    public BytesSource(byte[] data) {
+        if (data == null) {
+                   throw new IllegalArgumentException("data must be 
specified");
+               }
+        this.data = data;
+    }
+
+    public BytesSource(byte[] data, String systemId) {
+       this(data);
+        setSystemId(systemId);
+    }
+
+    public InputStream getInputStream() {
+        return new ByteArrayInputStream(data);
+    }
+
+    public Reader getReader() {
+        return new InputStreamReader(getInputStream());
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public String toString() {
+        return "BytesSource[" + new String(data) + "]";
+    }
+}

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/StringSource.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/StringSource.java?rev=1161561&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/StringSource.java 
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/StringSource.java Thu 
Aug 25 13:30:37 2011
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel;
+
+import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A helper class which provides a JAXP {@link javax.xml.transform.Source 
Source} from a String which can
+ * be read as many times as required. Encoding is default UTF-8.
+ *
+ * @version 
+ */
+public class StringSource extends StreamSource implements Externalizable {
+    private String text;
+    private String encoding = "UTF-8";
+
+    public StringSource() {
+    }
+
+    public StringSource(String text) {
+        if (text == null) {
+                   throw new IllegalArgumentException("text must be 
specified");
+               }
+        this.text = text;
+    }
+
+    public StringSource(String text, String systemId) {
+        this(text);
+        if (systemId == null) {
+                   throw new IllegalArgumentException("systemId must be 
specified");
+               }
+        setSystemId(systemId);
+    }
+
+    public StringSource(String text, String systemId, String encoding) {
+        this(text, systemId);
+        if (encoding == null) {
+                   throw new IllegalArgumentException("encoding must be 
specified");
+               }
+        this.encoding = encoding;
+    }
+
+    public InputStream getInputStream() {
+        try {
+            return new ByteArrayInputStream(text.getBytes(encoding));
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Reader getReader() {
+        return new StringReader(text);
+    }
+
+    public String toString() {
+        return "StringSource[" + text + "]";
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        int b = (text != null ? 0x01 : 0x00) + (encoding != null ? 0x02 : 0x00)
+                + (getPublicId() != null ? 0x04 : 0x00) + (getSystemId() != 
null ? 0x08 : 0x00);
+        out.writeByte(b);
+        if ((b & 0x01) != 0) {
+            out.writeUTF(text);
+        }
+        if ((b & 0x02) != 0) {
+            out.writeUTF(encoding);
+        }
+        if ((b & 0x04) != 0) {
+            out.writeUTF(getPublicId());
+        }
+        if ((b & 0x08) != 0) {
+            out.writeUTF(getSystemId());
+        }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
+        int b = in.readByte();
+        if ((b & 0x01) != 0) {
+            text = in.readUTF();
+        }
+        if ((b & 0x02) != 0) {
+            encoding = in.readUTF();
+        }
+        if ((b & 0x04) != 0) {
+            setPublicId(in.readUTF());
+        }
+        if ((b & 0x08) != 0) {
+            setSystemId(in.readUTF());
+        }
+    }
+}

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=1161561&r1=1161560&r2=1161561&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 Aug 25 13:30:37 2011
@@ -53,8 +53,10 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
+import org.apache.camel.StringSource;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/SourceCache.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/SourceCache.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/SourceCache.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/SourceCache.java
 Thu Aug 25 13:30:37 2011
@@ -20,11 +20,11 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.camel.StreamCache;
-import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.camel.StringSource;
 import org.apache.camel.util.IOHelper;
 
 /**
- * {@link org.apache.camel.StreamCache} implementation for {@link 
org.apache.camel.converter.jaxp.StringSource}s
+ * {@link org.apache.camel.StreamCache} implementation for {@link 
org.apache.camel.StringSource}s
  */
 public class SourceCache extends StringSource implements StreamCache {
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
 Thu Aug 25 13:30:37 2011
@@ -25,11 +25,11 @@ import javax.xml.transform.TransformerEx
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
-import org.apache.camel.converter.jaxp.BytesSource;
-import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.camel.StringSource;
 import org.apache.camel.util.IOHelper;
 
 /**

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java 
Thu Aug 25 13:30:37 2011
@@ -25,12 +25,12 @@ import java.util.Map;
 import java.util.TreeMap;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.StreamCache;
+import org.apache.camel.StringSource;
 import org.apache.camel.component.file.GenericFile;
-import org.apache.camel.converter.jaxp.BytesSource;
-import org.apache.camel.converter.jaxp.StringSource;
 
 /**
  * Some helper methods when working with {@link org.apache.camel.Message}.
@@ -192,22 +192,24 @@ public final class MessageHelper {
             return prepend + "[Body is null]";
         }
 
-        if (obj instanceof StringSource || obj instanceof BytesSource) {
-            // these two are okay
-        } else if (!allowStreams && obj instanceof StreamCache) {
-            return prepend + "[Body is instance of 
org.apache.camel.StreamCache]";
-        } else if (!allowStreams && obj instanceof StreamSource) {
-            return prepend + "[Body is instance of 
java.xml.transform.StreamSource]";
-        } else if (!allowStreams && obj instanceof InputStream) {
-            return prepend + "[Body is instance of java.io.InputStream]";
-        } else if (!allowStreams && obj instanceof OutputStream) {
-            return prepend + "[Body is instance of java.io.OutputStream]";
-        } else if (!allowStreams && obj instanceof Reader) {
-            return prepend + "[Body is instance of java.io.Reader]";
-        } else if (!allowStreams && obj instanceof Writer) {
-            return prepend + "[Body is instance of java.io.Writer]";
-        } else if (!allowFiles && (obj instanceof GenericFile || obj 
instanceof File)) {
-            return prepend + "[Body is file based: " + obj + "]";
+        if (!allowStreams) {
+               if (obj instanceof StreamSource  && !(obj instanceof 
StringSource || obj instanceof BytesSource)) {
+                       /* Generally do not log StreamSources but as 
StringSource and ByteSoure
+                        * are memory based     they are ok */
+                       return prepend + "[Body is instance of 
java.xml.transform.StreamSource]";
+               } else if (obj instanceof StreamCache) {
+                       return prepend + "[Body is instance of 
org.apache.camel.StreamCache]";
+               } else if (obj instanceof InputStream) {
+                       return prepend + "[Body is instance of 
java.io.InputStream]";
+               } else if (obj instanceof OutputStream) {
+                       return prepend + "[Body is instance of 
java.io.OutputStream]";
+               } else if (obj instanceof Reader) {
+                       return prepend + "[Body is instance of java.io.Reader]";
+               } else if (obj instanceof Writer) {
+                       return prepend + "[Body is instance of java.io.Writer]";
+               } else if (obj instanceof GenericFile || obj instanceof File) {
+                       return prepend + "[Body is file based: " + obj + "]";
+               }
         }
 
         // is the body a stream cache

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/StringSourceTest.java
 Thu Aug 25 13:30:37 2011
@@ -22,8 +22,9 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
 import junit.framework.TestCase;
+
+import org.apache.camel.StringSource;
 import org.apache.camel.TypeConverter;
-import org.apache.camel.converter.jaxp.StringSource;
 import org.apache.camel.impl.DefaultClassResolver;
 import org.apache.camel.impl.DefaultFactoryFinderResolver;
 import org.apache.camel.impl.DefaultPackageScanClassResolver;

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/BytesSourceTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/BytesSourceTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/BytesSourceTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/BytesSourceTest.java
 Thu Aug 25 13:30:37 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.converter.jaxp;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.ContextTestSupport;
 
 /**

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=1161561&r1=1161560&r2=1161561&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
 Thu Aug 25 13:30:37 2011
@@ -33,6 +33,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyStreamsTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyStreamsTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyStreamsTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LogDebugBodyStreamsTest.java
 Thu Aug 25 13:30:37 2011
@@ -21,9 +21,9 @@ import java.io.InputStream;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.StringSource;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.jaxp.StringSource;
 
 /**
  * @version 

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamSourceContentBasedRouterTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamSourceContentBasedRouterTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamSourceContentBasedRouterTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/StreamSourceContentBasedRouterTest.java
 Thu Aug 25 13:30:37 2011
@@ -21,9 +21,9 @@ import java.io.StringReader;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.StringSource;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.jaxp.StringSource;
 
 /**
  * Test for handling a StreamSource in a content-based router with XPath 
predicates

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidatingProcessorFromSourceTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidatingProcessorFromSourceTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidatingProcessorFromSourceTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidatingProcessorFromSourceTest.java
 Thu Aug 25 13:30:37 2011
@@ -18,7 +18,7 @@ package org.apache.camel.processor;
 
 import java.io.File;
 
-import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.camel.StringSource;
 import org.apache.camel.processor.validation.ValidatingProcessor;
 
 /**

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java?rev=1161561&r1=1161560&r2=1161561&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java
 Thu Aug 25 13:30:37 2011
@@ -22,13 +22,13 @@ import java.io.StringReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.camel.BytesSource;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
+import org.apache.camel.StringSource;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.jaxp.BytesSource;
-import org.apache.camel.converter.jaxp.StringSource;
 import org.apache.camel.converter.jaxp.XmlConverter;
 
 public class StreamCachingInterceptorTest extends ContextTestSupport {


Reply via email to