camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1153812 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/component/xslt/ test/java/org/apache/camel/component/xslt/ test/resources/org/apache/camel/component/xslt/
Date Thu, 04 Aug 2011 09:45:22 GMT
Author: davsclaus
Date: Thu Aug  4 09:45:21 2011
New Revision: 1153812

URL: http://svn.apache.org/viewvc?rev=1153812&view=rev
Log:
CAMEL-4305: Fixed xslt component not being able to load the stylesheet from a file system.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteFileTest.java
      - copied, changed from r1153781, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/XsltRouteFileTest.xml
      - copied, changed from r1153781, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/camelContext.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=1153812&r1=1153811&r2=1153812&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Thu Aug  4 09:45:21 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.xslt;
 
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.Map;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerFactory;
@@ -31,6 +33,7 @@ import org.apache.camel.converter.jaxp.X
 import org.apache.camel.impl.ProcessorEndpoint;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
 
 /**
  * An <a href="http://camel.apache.org/xslt.html">XSLT Component</a>
@@ -149,7 +152,23 @@ public class XsltComponent extends Resou
     private void loadResource(XsltBuilder xslt, Resource resource) throws TransformerConfigurationException
{
         log.trace("{} loading schema resource: {}", this, resource);
         try {
-            xslt.setTransformerInputStream(resource.getInputStream());
+            if (resource instanceof UrlResource) {
+                // prefer to use file when a file based url
+                File file = resource.getFile();
+                if (file != null) {
+                    // check if the file exists and report a better error as the XSLT
+                    // will just say it cannot compile the stylesheet file
+                    if (!file.exists()) {
+                        throw new FileNotFoundException("File: " + file + " not found.");
+                    }
+                    xslt.setTransformerFile(file);
+                } else {
+                    xslt.setTransformerURL(resource.getURL());
+                }
+            } else {
+                // fallback and use input stream
+                xslt.setTransformerInputStream(resource.getInputStream());
+            }
         } catch (Exception e) {
             // include information about the resource in the caused exception, so its easier
for
             // end users to know which resource failed

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteFileTest.java
(from r1153781, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteFileTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteFileTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteTest.java&r1=1153781&r2=1153812&rev=1153812&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltRouteFileTest.java
Thu Aug  4 09:45:21 2011
@@ -16,48 +16,15 @@
  */
 package org.apache.camel.component.xslt;
 
-import java.util.List;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version 
  */
-public class XsltRouteTest extends SpringTestSupport {
-
-    public void testSendMessageAndHaveItTransformed() throws Exception {
-        MockEndpoint endpoint = getMockEndpoint("mock:result");
-        endpoint.expectedMessageCount(1);
-
-        template.sendBody("direct:start",
-                "<mail><subject>Hey</subject><body>Hello world!</body></mail>");
-
-        assertMockEndpointsSatisfied();
-
-        List<Exchange> list = endpoint.getReceivedExchanges();
-        Exchange exchange = list.get(0);
-        String xml = exchange.getIn().getBody(String.class);
-
-        assertNotNull("The transformed XML should not be null", xml);
-        assertTrue(xml.indexOf("transformed") > -1);
-        // the cheese tag is in the transform.xsl
-        assertTrue(xml.indexOf("cheese") > -1);
-        assertTrue(xml.indexOf("<subject>Hey</subject>") > -1);
-        assertTrue(xml.indexOf("<body>Hello world!</body>") > -1);
-
-        TestBean bean = getMandatoryBean(TestBean.class, "testBean");
-        assertEquals("bean.subject", "Hey", bean.getSubject());
-    }
-
-    protected int getExpectedRouteCount() {
-        return 0;
-    }
+public class XsltRouteFileTest extends XsltRouteTest {
 
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/component/xslt/camelContext.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/xslt/XsltRouteFileTest.xml");
     }
 }

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/XsltRouteFileTest.xml
(from r1153781, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/camelContext.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/XsltRouteFileTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/XsltRouteFileTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/camelContext.xml&r1=1153781&r2=1153812&rev=1153812&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/camelContext.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/XsltRouteFileTest.xml
Thu Aug  4 09:45:21 2011
@@ -26,7 +26,7 @@
   <camelContext xmlns="http://camel.apache.org/schema/spring">
     <route>
       <from uri="direct:start"/>
-      <to uri="xslt:org/apache/camel/component/xslt/transform.xsl"/>
+      <to uri="xslt:file:src/test/resources/org/apache/camel/component/xslt/transform.xsl"/>
       <multicast>
         <bean ref="testBean"/>
         <to uri="mock:result"/>



Mime
View raw message