camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r909280 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/xml/ camel-core/src/main/java/org/apache/camel/util/ components/camel-spring/src/main/java/org/apache/camel/component/xslt/ components/camel-spring...
Date Fri, 12 Feb 2010 07:50:45 GMT
Author: davsclaus
Date: Fri Feb 12 07:50:43 2010
New Revision: 909280

URL: http://svn.apache.org/viewvc?rev=909280&view=rev
Log:
Merged revisions 909028 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r909028 | davsclaus | 2010-02-11 16:40:28 +0100 (Thu, 11 Feb 2010) | 1 line
  
  CAMEL-2463: xslt component now supports using xsl:include where the included files is loaded
from classpath and relative according to the endpoint configured location.
........

Added:
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
      - copied, changed from r909028, camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java
      - copied, changed from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java
      - copied, changed from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java
      - copied, changed from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/component/staff_other_template.xsl
      - copied unchanged from r909028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/staff_other_template.xsl
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_classpath.xsl
      - copied unchanged from r909028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_classpath.xsl
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_relative.xsl
      - copied unchanged from r909028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_relative.xsl
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_relative_other.xsl
      - copied unchanged from r909028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/staff_include_relative_other.xsl
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/MainTest.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb 12 07:50:43 2010
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
 923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801084,801196,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063,818182-818354,818744,818747,819475,819956,820152,820168,821272,821290,822655,823013,823018,823031,823102,823177,823575,824218,824721,825760,825765,828288,828333,832647,833285,833289,833350,833370,833381,833419,835511,880655,880667,883713,884525,884750,885876,887196,895119,896772,898201,901634,902688,903638,903970,904365,904440,904442,905171,905241,905585,905883,906013,906068,906342,908925
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
 923,781974,781993,782557,782594,782681,782886,782918-782923,783204,783248,783363,783639,783704,785564,785584,785599,787206,787581,787598,787605,787928,788393,789121,789703,790560,790936,791379,791476,791767,792038,792381,792398,792899,793359,793518,793547-793555,793862,793935,794237,794368,794550,794967,795790,798027,798052,798063,798489,798864,799252,800340,800785,800797,801084,801196,801960,802307,802478,803559,807476,810751,812937,814493,816105,817654,818063,818182-818354,818744,818747,819475,819956,820152,820168,821272,821290,822655,823013,823018,823031,823102,823177,823575,824218,824721,825760,825765,828288,828333,832647,833285,833289,833350,833370,833381,833419,835511,880655,880667,883713,884525,884750,885876,887196,895119,896772,898201,901634,902688,903638,903970,904365,904440,904442,905171,905241,905585,905883,906013,906068,906342,908925,909028

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?rev=909280&r1=909279&r2=909280&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
Fri Feb 12 07:50:43 2010
@@ -23,13 +23,14 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Templates;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.camel.Exchange;
@@ -53,6 +54,7 @@
     private Templates template;
     private ResultHandlerFactory resultHandlerFactory = new StringResultHandlerFactory();
     private boolean failOnNullBody = true;
+    private URIResolver uriResolver;
 
     public XsltBuilder() {
     }
@@ -157,6 +159,14 @@
         return this;
     }
 
+    /**
+     * Sets a custom URI resolver to be used
+     */
+    public XsltBuilder uriResolver(URIResolver uriResolver) {
+        setUriResolver(uriResolver);
+        return this;
+    }
+
     // Properties
     // -------------------------------------------------------------------------
 
@@ -199,10 +209,15 @@
      * @throws TransformerConfigurationException is thrown if creating a XSLT transformer
failed.
      */
     public void setTransformerSource(Source source) throws TransformerConfigurationException
{
+        TransformerFactory factory = converter.getTransformerFactory();
+        if (getUriResolver() != null) {
+            factory.setURIResolver(getUriResolver());
+        }
+
         // Check that the call to newTemplates() returns a valid template instance.
         // In case of an xslt parse error, it will return null and we should stop the
         // deployment and raise an exception as the route will not be setup properly.
-        Templates templates = converter.getTransformerFactory().newTemplates(source);
+        Templates templates = factory.newTemplates(source);
         if (templates != null) {
             setTemplate(templates);
         } else {
@@ -243,6 +258,14 @@
         this.converter = converter;
     }
 
+    public URIResolver getUriResolver() {
+        return uriResolver;
+    }
+
+    public void setUriResolver(URIResolver uriResolver) {
+        this.uriResolver = uriResolver;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 
@@ -270,6 +293,11 @@
      * Configures the transformer with exchange specific parameters
      */
     protected void configureTransformer(Transformer transformer, Exchange exchange) {
+        if (uriResolver == null) {
+            uriResolver = new XsltUriResolver(null);
+        }
+        transformer.setURIResolver(uriResolver);
+
         transformer.clearParameters();
 
         addParameters(transformer, exchange.getProperties());

Copied: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
(from r909028, camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java?p2=camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java&r1=909028&r2=909280&rev=909280&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
Fri Feb 12 07:50:43 2010
@@ -23,7 +23,6 @@
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -45,11 +44,9 @@
 
     private static final transient Log LOG = LogFactory.getLog(XsltUriResolver.class); 
 
-    private final ClassResolver resolver;
     private final String location;
 
-    public XsltUriResolver(ClassResolver resolver, String location) {
-        this.resolver = resolver;
+    public XsltUriResolver(String location) {
         this.location = location;
     }
 
@@ -68,7 +65,7 @@
             }
 
             String name = ObjectHelper.after(href, ":");
-            InputStream is = resolver.loadResourceAsStream(name);
+            InputStream is = ObjectHelper.loadResourceAsStream(name);
             if (is == null) {
                 throw new TransformerException("Cannot find " + name + " in classpath");
             }

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=909280&r1=909279&r2=909280&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
Fri Feb 12 07:50:43 2010
@@ -354,6 +354,24 @@
     }
 
     /**
+     * Returns only the leading path (returns <tt>null</tt> if no path)
+     */
+    public static String onlyPath(String name) {
+        if (name == null) {
+            return null;
+        }
+        int pos = name.lastIndexOf('/');
+        if (pos == -1) {
+            pos = name.lastIndexOf(File.separator);
+        }
+        if (pos != -1) {
+            return name.substring(0, pos);
+        }
+        // no path
+        return null;
+    }
+
+    /**
      * Compacts a path by stacking it and reducing <tt>..</tt>
      */
     public static String compactPath(String path) {

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=909280&r1=909279&r2=909280&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Fri Feb 12 07:50:43 2010
@@ -17,12 +17,13 @@
 package org.apache.camel.component.xslt;
 
 import java.util.Map;
-
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.URIResolver;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.xml.XsltBuilder;
+import org.apache.camel.builder.xml.XsltUriResolver;
 import org.apache.camel.component.ResourceBasedComponent;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.impl.ProcessorEndpoint;
@@ -85,6 +86,11 @@
         if (factory != null) {
             xslt.getConverter().setTransformerFactory(factory);
         }
+
+        // set resolver before input stream as resolver is used when loading the input stream
+        URIResolver resolver = new XsltUriResolver(remaining);
+        xslt.setUriResolver(resolver);
+
         xslt.setTransformerInputStream(resource.getInputStream());
         configureXslt(xslt, uri, remaining, parameters);
         return new ProcessorEndpoint(uri, this, xslt);

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java
(from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java?p2=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java&r1=909028&r2=909280&rev=909280&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeClasspathTest.java
Fri Feb 12 07:50:43 2010
@@ -29,7 +29,7 @@
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         // the include file has the span style so check that its there
-        mock.message(0).constant("<span style=\"font-size=22px;\">Minnie Mouse</span>");
+        mock.message(0).body().contains("<span style=\"font-size=22px;\">Minnie Mouse</span>");
 
         assertMockEndpointsSatisfied();
     }
@@ -39,7 +39,7 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file:src/test/data/?fileName=staff.xml&noop=true")
+                from("file:src/test/data/staff.xml?noop=true")
                     .to("xslt:org/apache/camel/component/xslt/staff_include_classpath.xsl")
                     .to("log:foo")
                     .to("mock:result");

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java
(from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java?p2=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java&r1=909028&r2=909280&rev=909280&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeOtherTest.java
Fri Feb 12 07:50:43 2010
@@ -29,7 +29,7 @@
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         // the include file has the span style so check that its there
-        mock.message(0).constant("<span style=\"color:yellow;\">48</span>");
+        mock.message(0).body().contains("<span style=\"color:yellow;\">48</span>");
 
         assertMockEndpointsSatisfied();
     }
@@ -39,7 +39,7 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file:src/test/data/?fileName=staff.xml&noop=true")
+                from("file:src/test/data/staff.xml?noop=true")
                     .to("xslt:org/apache/camel/component/xslt/staff_include_relative_other.xsl")
                     .to("log:foo")
                     .to("mock:result");

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java
(from r909028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java?p2=camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java&r1=909028&r2=909280&rev=909280&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/component/xslt/XsltIncludeRelativeTest.java
Fri Feb 12 07:50:43 2010
@@ -29,7 +29,7 @@
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         // the include file has the span style so check that its there
-        mock.message(0).constant("<span style=\"font-size=22px;\">Minnie Mouse</span>");
+        mock.message(0).body().contains("<span style=\"font-size=22px;\">Minnie Mouse</span>");
 
         assertMockEndpointsSatisfied();
     }
@@ -39,7 +39,7 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file:src/test/data/?fileName=staff.xml&noop=true")
+                from("file:src/test/data/staff.xml?noop=true")
                     .to("xslt:org/apache/camel/component/xslt/staff_include_relative.xsl")
                     .to("log:foo")
                     .to("mock:result");

Modified: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/MainTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/MainTest.java?rev=909280&r1=909279&r2=909280&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/MainTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/MainTest.java
Fri Feb 12 07:50:43 2010
@@ -49,7 +49,8 @@
         CamelContext camelContext = contextList.get(0);
 
         MockEndpoint endpoint = camelContext.getEndpoint("mock:results", MockEndpoint.class);
-        endpoint.expectedMessageCount(2);
+        // in case we add more files in src/test/data
+        endpoint.expectedMinimumMessageCount(2);
         endpoint.assertIsSatisfied();
         List<Exchange> list = endpoint.getReceivedExchanges();
 



Mime
View raw message