camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-6661 Supporting the href is empty in camel-xslt component with thanks to Rene
Date Tue, 31 Dec 2013 07:49:18 GMT
Updated Branches:
  refs/heads/master dd813094f -> b884f14ee


CAMEL-6661 Supporting the href is empty in camel-xslt component with thanks to Rene


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b884f14e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b884f14e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b884f14e

Branch: refs/heads/master
Commit: b884f14eead036461bdf5901575e178cfddfa6c8
Parents: dd81309
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Tue Dec 31 15:44:51 2013 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Tue Dec 31 15:48:50 2013 +0800

----------------------------------------------------------------------
 .../camel/builder/xml/XsltUriResolver.java      |  4 ++
 .../xslt/SaxonXslIncludetEmptyHrefTest.java     | 49 ++++++++++++++++++++
 .../component/xslt/transform_includes_data.xsl  | 29 ++++++++++++
 3 files changed, 82 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b884f14e/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
index 4a46b04..58dbb65 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
@@ -62,6 +62,10 @@ public class XsltUriResolver implements URIResolver {
     }
 
     public Source resolve(String href, String base) throws TransformerException {
+        // supports the empty href
+        if (ObjectHelper.isEmpty(href)) {
+            href = location;
+        }
         if (ObjectHelper.isEmpty(href)) {
             throw new TransformerException("include href is empty");
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/b884f14e/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXslIncludetEmptyHrefTest.java
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXslIncludetEmptyHrefTest.java
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXslIncludetEmptyHrefTest.java
new file mode 100644
index 0000000..ad7e14f
--- /dev/null
+++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXslIncludetEmptyHrefTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class SaxonXslIncludetEmptyHrefTest extends CamelTestSupport {
+
+    @Test
+    public void testXsltOutput() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        
+        mock.expectedBodiesReceived("<?xml version=\"1.0\" encoding=\"UTF-8\"?><MyDate>February</MyDate>");
+        mock.message(0).body().isInstanceOf(String.class);
+
+        template.sendBody("direct:start", "<root>1</root>");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("xslt:org/apache/camel/component/xslt/transform_includes_data.xsl")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b884f14e/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_includes_data.xsl
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_includes_data.xsl
b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_includes_data.xsl
new file mode 100644
index 0000000..610ab3a
--- /dev/null
+++ b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_includes_data.xsl
@@ -0,0 +1,29 @@
+<?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:date="http://exslt.org/dates-and-times" version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <date:months>
+        <date:month length="31" abbr="Jan">January</date:month>
+        <date:month length="28" abbr="Feb">February</date:month>
+    </date:months>
+    <xsl:template match="root">
+        <xsl:variable name="month-node" select="document('')/*/date:months/date:month[number(2)]"/>
+        <xsl:element name="MyDate">
+            <xsl:value-of select="$month-node"/>
+        </xsl:element>
+    </xsl:template>
+</xsl:stylesheet>


Mime
View raw message