You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/06/20 13:49:54 UTC
svn commit: r669865 - in
/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix:
components/util/DefaultFileMarshaler.java jbi/jaxp/SourceTransformer.java
Author: gertv
Date: Fri Jun 20 04:49:54 2008
New Revision: 669865
URL: http://svn.apache.org/viewvc?rev=669865&view=rev
Log:
SM-1415: Allow specifying an encoding on the DefaultFileMarshaler
Modified:
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java?rev=669865&r1=669864&r2=669865&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java Fri Jun 20 04:49:54 2008
@@ -19,9 +19,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
import javax.jbi.JBIException;
import javax.jbi.messaging.MessageExchange;
@@ -54,10 +56,15 @@
private Expression fileName = FILE_NAME_EXPRESSION;
private Expression content = FILE_CONTENT_EXPRESSION;
+ private String encoding;
public void readMessage(MessageExchange exchange, NormalizedMessage message,
InputStream in, String path) throws IOException, JBIException {
- message.setContent(new StreamSource(in, path));
+ if (encoding == null) {
+ message.setContent(new StreamSource(in, path));
+ } else {
+ message.setContent(new StreamSource(new InputStreamReader(in, Charset.forName(encoding)), path));
+ }
message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
message.setProperty(FILE_PATH_PROPERTY, path);
}
@@ -97,6 +104,14 @@
public void setFileName(Expression fileName) {
this.fileName = fileName;
}
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
// Implementation methods
//-------------------------------------------------------------------------
@@ -134,9 +149,10 @@
throw new NoMessageContentAvailableException(exchange);
}
try {
- getTransformer().toResult(src, new StreamResult(out));
+ getTransformer().toResult(src, new StreamResult(out), encoding);
} catch (TransformerException e) {
throw new MessagingException(e);
}
}
+
}
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java?rev=669865&r1=669864&r2=669865&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java Fri Jun 20 04:49:54 2008
@@ -97,17 +97,31 @@
}
/**
- * Converts the given input Source into the required result
+ * Converts the given input Source into the required result, using the default charset
*/
public void toResult(Source source, Result result) throws TransformerException {
+ toResult(source, result, defaultCharset);
+ }
+
+ /**
+ * Converts the given input Source into the required result, using the specified encoding
+ * @param source the input Source
+ * @param result the output Result
+ * @param charset the required charset, if you specify <code>null</code> the default charset will be used
+ */
+ public void toResult(Source source, Result result, String charset)
+ throws TransformerConfigurationException, TransformerException {
if (source == null) {
return;
}
+ if (charset == null) {
+ charset = defaultCharset;
+ }
Transformer transformer = createTransfomer();
if (transformer == null) {
throw new TransformerException("Could not create a transformer - JAXP is misconfigured!");
}
- transformer.setOutputProperty(OutputKeys.ENCODING, defaultCharset);
+ transformer.setOutputProperty(OutputKeys.ENCODING, charset);
transformer.transform(source, result);
}