You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/10/15 22:30:12 UTC

svn commit: r464270 - in /incubator/servicemix/trunk/servicemix-components/src: main/java/org/apache/servicemix/components/xslt/ test/java/org/apache/servicemix/components/xslt/ test/resources/org/apache/servicemix/components/xslt/

Author: gnodet
Date: Sun Oct 15 13:30:11 2006
New Revision: 464270

URL: http://svn.apache.org/viewvc?view=rev&rev=464270
Log:
SM-705: Static Parameter map injected into XsltComponent

Added:
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl
    incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml
Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java?view=diff&rev=464270&r1=464269&r2=464270
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java (original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java Sun Oct 15 13:30:11 2006
@@ -21,6 +21,7 @@
 import java.io.StringWriter;
 import java.net.URL;
 import java.util.Iterator;
+import java.util.Map;
 
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
@@ -62,6 +63,7 @@
     private boolean disableOutput;
     private boolean useStringBuffer = true;
     private boolean forceDocIfDom = true;
+    private Map xsltParameters;
 
     /**
      * @return the forceDocIfDom
@@ -127,6 +129,20 @@
         this.useStringBuffer = useStringBuffer;
     }
 
+    /**
+     * @return the xsltParameters
+     */
+    public Map getXsltParameters() {
+        return xsltParameters;
+    }
+
+    /**
+     * @param xsltParameters the xsltParameters to set
+     */
+    public void setXsltParameters(Map xsltParameters) {
+        this.xsltParameters = xsltParameters;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
     protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
@@ -243,6 +259,13 @@
             String name = (String) iter.next();
             Object value = in.getProperty(name);
             transformer.setParameter(name, value);
+        }
+        if (xsltParameters != null) {
+            for (Iterator iter = xsltParameters.keySet().iterator(); iter.hasNext();) {
+                String name = (String) iter.next();
+                Object value = xsltParameters.get(name);
+                transformer.setParameter(name, value);
+            }
         }
         transformer.setParameter("exchange", exchange);
         transformer.setParameter("in", in);

Added: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java?view=auto&rev=464270
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java (added)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java Sun Oct 15 13:30:11 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.servicemix.components.xslt;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Node;
+
+/**
+ * @author rbuckland
+ * @version $Revision$
+ */
+public class XsltParameterTest extends TestSupport {
+
+    public void testSendMessagesToJmsThenReceiveItTransformItThenRepublishAndReceive() throws Exception {
+       QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+        InOut exchange = client.createInOutExchange();
+        exchange.setService(service);
+
+        NormalizedMessage message = exchange.getInMessage();
+        message.setContent(new StringSource(createMessageXmlText(777888)));
+        client.sendSync(exchange);
+
+        NormalizedMessage outMessage = exchange.getOutMessage();
+
+        Source content = outMessage.getContent();
+        Node node = transformer.toDOMNode(content);
+
+        String value = textValueOfXPath(node, "//param");
+        String integer = textValueOfXPath(node, "//integer");
+
+        assertTrue(value.equals("cheeseyCheese"));
+        assertTrue(integer.equals("4002"));
+
+    }
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/servicemix-parameter-test.xml");
+    }
+}

Added: incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl?view=auto&rev=464270
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl (added)
+++ incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl Sun Oct 15 13:30:11 2006
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    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.
+
+-->
+<xsl:stylesheet
+  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+  version='1.0'>
+
+  <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+  <xsl:param name="stringParam"/>
+  <xsl:param name="integerParam"/>
+
+  <xsl:template match="*">
+  <rootNode>
+     <param><xsl:value-of select="$stringParam"/></param>
+     <integer><xsl:value-of select="$integerParam"/></integer>
+    </rootNode>
+  </xsl:template>
+
+</xsl:stylesheet>

Added: incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml?view=auto&rev=464270
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml (added)
+++ incubator/servicemix/trunk/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml Sun Oct 15 13:30:11 2006
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+          xmlns:foo="http://servicemix.org/cheese/">
+
+  <!-- the JBI container -->
+  <sm:container id="jbi" embedded="true">
+    <sm:activationSpecs>
+
+      <!-- START SNIPPET: xslt -->
+      <sm:activationSpec componentName="transformer" service="foo:transformer">
+        <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+          <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/parameter-test.xsl"/>
+          <property name="xsltParameters">
+              <map>
+                  <entry key="stringParam" value="cheeseyCheese"/>
+                  <entry key="integerParam" value-ref="javaIntegerObject"/>
+              </map>
+          </property>
+        </bean></sm:component>
+      </sm:activationSpec>
+      <!-- END SNIPPET: xslt -->
+
+    </sm:activationSpecs>
+  </sm:container>
+
+  <bean id="javaIntegerObject" class="java.lang.Integer">
+      <constructor-arg index="0" value="4002"/>
+  </bean>
+
+  <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+    <constructor-arg ref="jbi"/>
+  </bean>
+
+
+</beans>