Author: hadrian
Date: Wed Aug 22 14:44:19 2012
New Revision: 1376079

URL: http://svn.apache.org/viewvc?rev=1376079&view=rev
Log:
CAMEL-5505. Patch applied with thanks to Alexander Titov

Added:
    
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
   (with props)
    
camel/branches/camel-2.10.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
Modified:
    
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java

Modified: 
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=1376079&r1=1376078&r2=1376079&view=diff
==============================================================================
--- 
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
 (original)
+++ 
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
 Wed Aug 22 14:44:19 2012
@@ -117,8 +117,6 @@ public class XsltComponent extends Defau
         // default to use the cache option from the component if the endpoint 
did not have the contentCache parameter
         boolean cache = getAndRemoveParameter(parameters, "contentCache", 
Boolean.class, contentCache);
 
-        configureXslt(xslt, uri, remaining, parameters);
-
         // if its a http uri, then append additional parameters as they are 
part of the uri
         if (ResourceHelper.isHttpUri(resourceUri)) {
             resourceUri = ResourceHelper.appendParameters(resourceUri, 
parameters);
@@ -136,6 +134,8 @@ public class XsltComponent extends Defau
         }
         // set resolver before input stream as resolver is used when loading 
the input stream
         xslt.setUriResolver(resolver);
+        
+        configureXslt(xslt, uri, remaining, parameters);
 
         return new XsltEndpoint(uri, this, xslt, resourceUri, cache);
     }

Added: 
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java?rev=1376079&view=auto
==============================================================================
--- 
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
 (added)
+++ 
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
 Wed Aug 22 14:44:19 2012
@@ -0,0 +1,85 @@
+/**
+ * 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.camel.component.xslt;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class XsltCustomizeURIResolverTest extends ContextTestSupport {
+
+       private static final transient Logger LOG = LoggerFactory
+                       .getLogger(XsltCustomizeURIResolverTest.class);
+
+       private final String EXPECTED_XML_CONSTANT = "<data>FOO DATA</data>";
+
+       public void testXsltCustomURIResolverDirectInRouteUri() throws 
Exception {
+               MockEndpoint mock = 
getMockEndpoint("mock:resultURIResolverDirect");
+               mock.expectedMessageCount(1);
+
+               mock.message(0).body().contains(EXPECTED_XML_CONSTANT);
+
+               assertMockEndpointsSatisfied();
+       }
+
+       @Override
+       protected RouteBuilder createRouteBuilder() throws Exception {
+               return new RouteBuilder() {
+                       @Override
+                       public void configure() throws Exception {
+                               
from("file:src/test/data/?fileName=staff.xml&noop=true")
+                                               
.to("xslt:org/apache/camel/component/xslt/include_not_existing_resource.xsl?uriResolver=#customURIResolver")
+                                               
.to("mock:resultURIResolverDirect");
+                       }
+               };
+       }
+
+       private URIResolver getCustomURIResolver() {
+               return new URIResolver() {
+
+                       @Override
+                       public Source resolve(String href, String base)
+                                       throws TransformerException {
+                               Source constantResult = new StreamSource(
+                                               new ByteArrayInputStream(
+                                                               
EXPECTED_XML_CONSTANT.getBytes()));
+                               return constantResult;
+                       }
+               };
+       }
+
+       @Override
+       protected JndiRegistry createRegistry() throws Exception {
+               JndiRegistry registry = super.createRegistry();
+               URIResolver customURIResolver = getCustomURIResolver();
+               registry.bind("customURIResolver", customURIResolver);
+               return registry;
+       }
+}

Propchange: 
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/xslt/XsltCustomizeURIResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
camel/branches/camel-2.10.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl?rev=1376079&view=auto
==============================================================================
--- 
camel/branches/camel-2.10.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
 (added)
+++ 
camel/branches/camel-2.10.x/camel-core/src/test/resources/org/apache/camel/component/xslt/include_not_existing_resource.xsl
 Wed Aug 22 14:44:19 2012
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+    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:template match="/">
+       Data in file:
+        <xsl:copy-of select="document('notExistingExternalFile.xml')"/>
+    </xsl:template>
+    
+</xsl:stylesheet>
\ No newline at end of file


Reply via email to