Commit in servicemix/base/src/main/java/org/servicemix/components on MAIN
util/CopyTransformer.java+25-11.4 -> 1.5
    /TransformComponentSupport.java+20-81.6 -> 1.7
xslt/XsltComponent.java+2-21.9 -> 1.10
+47-11
3 modified files
fix for SM-64 to allow attachments to be copied in transform components

servicemix/base/src/main/java/org/servicemix/components/util
CopyTransformer.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- CopyTransformer.java	30 Aug 2005 11:29:52 -0000	1.4
+++ CopyTransformer.java	13 Sep 2005 10:39:31 -0000	1.5
@@ -20,6 +20,7 @@
 import org.servicemix.jbi.jaxp.SourceTransformer;
 import org.servicemix.jbi.jaxp.StringSource;
 
+import javax.activation.DataHandler;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
@@ -31,7 +32,7 @@
 /**
  * A simple transformer which copies the properties and content from the source message to the destination message.
  *
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 public class CopyTransformer implements MessageTransformer {
 
@@ -62,14 +63,37 @@
             }
         }
         to.setContent(content);
+        
+        copyAttachments(from, to);
         return true;
     }
 
+    /**
+     * Copies all of the properties from one message to another
+     * 
+     * @param from the message containing the properties
+     * @param to the destination messages where the properties are set
+     */
     public static void copyProperties(NormalizedMessage from, NormalizedMessage to) {
         for (Iterator iter = from.getPropertyNames().iterator(); iter.hasNext();) {
             String name = (String) iter.next();
             Object value = from.getProperty(name);
             to.setProperty(name, value);
+        }
+    }
+
+    /**
+     * Copies the attachments from a message to another message
+     * 
+     * @param from the message with the attachments
+     * @param to the message to which attachments are added
+     * @throws MessagingException if an attachment could not be added 
+     */
+    public static void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException {
+        for (Iterator iter = from.getAttachmentNames().iterator(); iter.hasNext();) {
+            String name = (String) iter.next();
+            DataHandler value = from.getAttachment(name);
+            to.addAttachment(name, value);
         }
     }
 }

servicemix/base/src/main/java/org/servicemix/components/util
TransformComponentSupport.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- TransformComponentSupport.java	31 Aug 2005 15:39:38 -0000	1.6
+++ TransformComponentSupport.java	13 Sep 2005 10:39:31 -0000	1.7
@@ -31,10 +31,11 @@
 /**
  * A useful base class for a transform component.
  *
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
  */
 public abstract class TransformComponentSupport extends ComponentSupport implements MessageExchangeListener {
     private boolean copyProperties = true;
+    private boolean copyAttachments = true;
 
 
     public void onMessageExchange(MessageExchange exchange) throws MessagingException {
@@ -87,14 +88,25 @@
     }
 
 
-    protected void copyProperties(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) {
+    public boolean isCopyAttachments() {
+        return copyAttachments;
+    }
+
+
+    public void setCopyAttachments(boolean copyAttachmenets) {
+        this.copyAttachments = copyAttachmenets;
+    }
+
+
+    /**
+     * If enabled the properties and attachments are copied to the destination message
+     */
+    protected void copyPropertiesAndAttachments(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
         if (isCopyProperties()) {
-            for (Iterator iter = in.getPropertyNames().iterator(); iter.hasNext();) {
-                String name = (String) iter.next();
-                Object value = in.getProperty(name);
-                out.setProperty(name, value);
-    
-            }
+            CopyTransformer.copyProperties(in, out);
+        }
+        if (isCopyAttachments()) {
+            CopyTransformer.copyAttachments(in, out);
         }
     }
 }

servicemix/base/src/main/java/org/servicemix/components/xslt
XsltComponent.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- XsltComponent.java	31 Aug 2005 15:39:38 -0000	1.9
+++ XsltComponent.java	13 Sep 2005 10:39:31 -0000	1.10
@@ -47,7 +47,7 @@
  * href="">JAXP</a> to perform the XSLT
  * transformation.
  * 
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
  */
 public class XsltComponent extends TransformComponentSupport implements MessageExchangeListener {
 
@@ -115,7 +115,7 @@
         try {
             Transformer transformer = createTransformer(exchange, in);
             configureTransformer(transformer, exchange, in);
-            copyProperties(exchange, in, out);
+            copyPropertiesAndAttachments(exchange, in, out);
             transformContent(transformer, exchange, in, out);
             return shouldOutputResult(transformer);
         }
CVSspam 0.2.8



Reply via email to