Repository: camel
Updated Branches:
  refs/heads/master 08f065c3d -> 0e0d6e981


CAMEL-9591 - Support Saxon integrated extension functions


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

Branch: refs/heads/master
Commit: 4183cbb8b949f8ddfc689e4d954e33c7dd418db7
Parents: 08f065c
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Thu Feb 11 16:23:23 2016 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Feb 12 11:00:45 2016 +0100

----------------------------------------------------------------------
 .../camel/component/xslt/XsltEndpoint.java      | 43 ++++++++-
 .../apache/camel/component/xslt/XsltHelper.java | 69 +++++++++++++++
 .../xslt/extensions/MyExtensionFunction1.java   | 90 +++++++++++++++++++
 .../xslt/extensions/MyExtensionFunction2.java   | 93 ++++++++++++++++++++
 .../extensions/SaxonExtensionFunctionsTest.java | 54 ++++++++++++
 .../SaxonSpringExtensionFunctionsTest.java      | 38 ++++++++
 .../xslt/extensions/camelXsltContext.xml        | 37 ++++++++
 .../component/xslt/extensions/extensions.xslt   | 37 ++++++++
 8 files changed, 459 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java 
b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
index 4588b5c..33cf0f4 100644
--- a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.xslt;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.Source;
@@ -38,6 +39,7 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
@@ -49,11 +51,11 @@ import org.slf4j.LoggerFactory;
 @ManagedResource(description = "Managed XsltEndpoint")
 @UriEndpoint(scheme = "xslt", title = "XSLT", syntax = "xslt:resourceUri", 
producerOnly = true, label = "core,transformation")
 public class XsltEndpoint extends ProcessorEndpoint {
-
     public static final String SAXON_TRANSFORMER_FACTORY_CLASS_NAME = 
"net.sf.saxon.TransformerFactoryImpl";
 
     private static final Logger LOG = 
LoggerFactory.getLogger(XsltEndpoint.class);
 
+
     private volatile boolean cacheCleared;
     private volatile XsltBuilder xslt;
     private Map<String, Object> parameters;
@@ -71,6 +73,8 @@ public class XsltEndpoint extends ProcessorEndpoint {
     @UriParam
     private boolean saxon;
     @UriParam(label = "advanced")
+    private List<Object> saxonExtensionFunctions;
+    @UriParam(label = "advanced")
     private ResultHandlerFactory resultHandlerFactory;
     @UriParam(defaultValue = "true")
     private boolean failOnNullBody = true;
@@ -198,6 +202,30 @@ public class XsltEndpoint extends ProcessorEndpoint {
         this.saxon = saxon;
     }
 
+    public List<Object> getSaxonExtensionFunctions() {
+        return saxonExtensionFunctions;
+    }
+
+    /**
+     * Allows you to use a custom net.sf.saxon.lib.ExtensionFunctionDefinition.
+     * You would need to add Saxon to the classpath.
+     */
+    public void setSaxonExtensionFunctions(List<Object> extensionFunctions) {
+        this.saxonExtensionFunctions = extensionFunctions;
+    }
+
+    /**
+     * Allows you to use a custom net.sf.saxon.lib.ExtensionFunctionDefinition.
+     * You would need to add Saxon to the classpath.
+     */
+    public void setSaxonExtensionFunctions(String extensionFunctions) {
+        this.saxonExtensionFunctions = 
EndpointHelper.resolveReferenceListParameter(
+            getCamelContext(),
+            extensionFunctions,
+            Object.class
+        );
+    }
+
     public ResultHandlerFactory getResultHandlerFactory() {
         return resultHandlerFactory;
     }
@@ -351,7 +379,9 @@ public class XsltEndpoint extends ProcessorEndpoint {
             xslt.setConverter(converter);
         }
 
-        if (transformerFactoryClass == null && saxon) {
+        boolean useSaxon = false;
+        if (transformerFactoryClass == null && (saxon || 
saxonExtensionFunctions != null)) {
+            useSaxon = true;
             transformerFactoryClass = SAXON_TRANSFORMER_FACTORY_CLASS_NAME;
         }
 
@@ -361,6 +391,15 @@ public class XsltEndpoint extends ProcessorEndpoint {
             Class<?> factoryClass = 
getCamelContext().getClassResolver().resolveMandatoryClass(transformerFactoryClass,
 XsltComponent.class.getClassLoader());
             LOG.debug("Using TransformerFactoryClass {}", factoryClass);
             factory = (TransformerFactory) 
getCamelContext().getInjector().newInstance(factoryClass);
+
+            if (useSaxon) {
+                XsltHelper.registerSaxonExtensionFunctions(
+                    getCamelContext(),
+                    factoryClass,
+                    factory,
+                    saxonExtensionFunctions
+                );
+            }
         }
 
         if (factory != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/camel-core/src/main/java/org/apache/camel/component/xslt/XsltHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/xslt/XsltHelper.java 
b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltHelper.java
new file mode 100644
index 0000000..529fd68
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/xslt/XsltHelper.java
@@ -0,0 +1,69 @@
+/**
+ * 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.lang.reflect.Method;
+import java.util.List;
+import javax.xml.XMLConstants;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.camel.CamelContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class XsltHelper {
+    private static final Logger LOG = 
LoggerFactory.getLogger(XsltHelper.class);
+
+    private static final String SAXON_CONFIGURATION_CLASS_NAME = 
"net.sf.saxon.Configuration";
+    private static final String SAXON_EXTENDED_FUNCTION_DEFINITION_CLASS_NAME 
= "net.sf.saxon.lib.ExtensionFunctionDefinition";
+
+    private XsltHelper() {
+    }
+
+    public static void registerSaxonExtensionFunctions(
+            CamelContext camelContext, Class<?> factoryClass, 
TransformerFactory factory, List<Object> saxonExtensionFunctions) throws 
Exception {
+
+        if (saxonExtensionFunctions != null && 
!saxonExtensionFunctions.isEmpty()) {
+            Method method = factoryClass.getMethod("getConfiguration");
+            if (method != null) {
+                Object configuration = method.invoke(factory, null);
+                if (configuration != null) {
+                    Class<?> extensionClass = 
camelContext.getClassResolver().resolveMandatoryClass(
+                        SAXON_EXTENDED_FUNCTION_DEFINITION_CLASS_NAME, 
XsltComponent.class.getClassLoader()
+                    );
+
+                    method = 
configuration.getClass().getMethod("registerExtensionFunction", extensionClass);
+                    if (method != null) {
+                        
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+                        for (Object extensionFunction : 
saxonExtensionFunctions) {
+                            if (extensionClass.isInstance(extensionFunction)) {
+                                LOG.debug("Saxon.registerExtensionFunction 
{}", extensionFunction);
+                                method.invoke(configuration, 
extensionFunction);
+                            }
+                        }
+                    } else {
+                        LOG.warn("Unable to get reference to method 
registerExtensionFunction on {}", configuration.getClass().getName());
+                    }
+                } else {
+                    LOG.warn("Unable to get Saxon configuration ({}) on {}", 
SAXON_CONFIGURATION_CLASS_NAME, factory.getClass().getName());
+                }
+            } else {
+                LOG.warn("Unable to get reference to method getConfiguration 
on {}", factoryClass.getName());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction1.java
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction1.java
 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction1.java
new file mode 100644
index 0000000..251f7a0
--- /dev/null
+++ 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction1.java
@@ -0,0 +1,90 @@
+/*
+ * 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.extensions;
+
+import net.sf.saxon.expr.XPathContext;
+import net.sf.saxon.lib.ExtensionFunctionCall;
+import net.sf.saxon.lib.ExtensionFunctionDefinition;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.Sequence;
+import net.sf.saxon.om.SequenceTool;
+import net.sf.saxon.om.StructuredQName;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.tree.iter.SingletonIterator;
+import net.sf.saxon.value.Int64Value;
+import net.sf.saxon.value.SequenceType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MyExtensionFunction1 extends ExtensionFunctionDefinition {
+
+       private static final long serialVersionUID = 1L;
+       
+       private static final Logger LOG = 
LoggerFactory.getLogger(MyExtensionFunction1.class);
+
+       @Override
+    public StructuredQName getFunctionQName() {
+        return new StructuredQName("", "http://mytest/";, 
"myExtensionFunction1");
+    }
+
+    @Override
+    public int getMinimumNumberOfArguments() {
+        return 2;
+    }
+
+    @Override
+    public int getMaximumNumberOfArguments() {
+        return 2;
+    }
+
+    @Override
+    public SequenceType[] getArgumentTypes() {
+        return new SequenceType[] { SequenceType.SINGLE_INTEGER, 
SequenceType.SINGLE_INTEGER };
+    }
+
+    @Override
+    public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+       int resultCardinality = 1;
+       return 
SequenceType.makeSequenceType(SequenceType.SINGLE_INTEGER.getPrimaryType(), 
resultCardinality);
+    }
+
+    @Override
+    public ExtensionFunctionCall makeCallExpression() {
+       return new ExtensionFunctionCall() {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+               public Sequence call(XPathContext xPathContext, Sequence[] 
arguments) throws XPathException {
+                               // 1st argument (mandatory, index 0)
+                   Int64Value arg1 = (Int64Value) 
arguments[0].iterate().next();
+                   int arg1Int = 
arg1.getDecimalValue().toBigInteger().intValue();
+       
+                   // 2nd argument (mandatory, index 1)
+                   Int64Value arg2 = (Int64Value) 
arguments[1].iterate().next();
+                   int arg2Int = 
arg2.getDecimalValue().toBigInteger().intValue();
+                   
+                   // Functionality goes here
+                   int resultInt = arg1Int + arg2Int;
+       
+                   Item result = new Int64Value(resultInt);
+                   return 
SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
+               }
+               };
+    }
+       
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction2.java
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction2.java
 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction2.java
new file mode 100644
index 0000000..f694233
--- /dev/null
+++ 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/MyExtensionFunction2.java
@@ -0,0 +1,93 @@
+/*
+ * 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.extensions;
+
+import net.sf.saxon.expr.XPathContext;
+import net.sf.saxon.lib.ExtensionFunctionCall;
+import net.sf.saxon.lib.ExtensionFunctionDefinition;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.Sequence;
+import net.sf.saxon.om.SequenceTool;
+import net.sf.saxon.om.StructuredQName;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.tree.iter.SingletonIterator;
+import net.sf.saxon.value.SequenceType;
+import net.sf.saxon.value.StringValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MyExtensionFunction2 extends ExtensionFunctionDefinition {
+
+       private static final long serialVersionUID = 1L;
+       
+       private static final Logger LOG = 
LoggerFactory.getLogger(MyExtensionFunction2.class);
+
+       @Override
+    public StructuredQName getFunctionQName() {
+        return new StructuredQName("", "http://mytest/";, 
"myExtensionFunction2");
+    }
+
+    @Override
+    public int getMinimumNumberOfArguments() {
+        return 1;
+    }
+
+    @Override
+    public int getMaximumNumberOfArguments() {
+        return 2;
+    }
+
+    @Override
+    public SequenceType[] getArgumentTypes() {
+        return new SequenceType[] { SequenceType.SINGLE_STRING, 
SequenceType.OPTIONAL_STRING };
+    }
+
+    @Override
+    public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+       int resultCardinality = 1;
+       return 
SequenceType.makeSequenceType(SequenceType.SINGLE_STRING.getPrimaryType(), 
resultCardinality);
+    }
+
+    @Override
+    public ExtensionFunctionCall makeCallExpression() {
+       return new ExtensionFunctionCall() {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+               public Sequence call(XPathContext xPathContext, Sequence[] 
arguments) throws XPathException {
+                               // 1st argument (mandatory, index 0)
+                   StringValue arg1 = (StringValue) 
arguments[0].iterate().next();
+                   String arg1Str = arg1.getStringValue();
+       
+                   // 2nd argument (optional, index 1)
+                   String arg2Str = ""; 
+                       if ( arguments.length > 1 ) {
+                               StringValue arg2 = (StringValue) 
arguments[1].iterate().next();
+                               arg2Str = arg2.getStringValue();
+                       }
+                   
+                   // Functionality goes here
+                   String resultStr = arg1Str + arg2Str;
+       
+                   Item result = new StringValue(resultStr);
+                   return 
SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
+               }
+               };
+    }
+       
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonExtensionFunctionsTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonExtensionFunctionsTest.java
 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonExtensionFunctionsTest.java
new file mode 100644
index 0000000..ae1531d
--- /dev/null
+++ 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonExtensionFunctionsTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.extensions;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class SaxonExtensionFunctionsTest extends CamelTestSupport {
+    private static final String XSLT_PATH = 
"org/apache/camel/component/xslt/extensions/extensions.xslt";
+    private static final String XSLT_RESULT = "<?xml version=\"1.0\" 
encoding=\"UTF-8\"?><Test1>3</Test1><Test2>abccde</Test2><Test3>xyz</Test3>";
+
+    @Test
+    public void testExtensions() {
+        String result = template().requestBody("direct:extensions", 
"<dummy/>", String.class);
+        assertNotNull(result);
+        assertEquals(XSLT_RESULT, result);
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = new JndiRegistry(createJndiContext());
+        registry.bind("function1", new MyExtensionFunction1());
+        registry.bind("function2", new MyExtensionFunction2());
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:extensions")
+                    
.toF("xslt:%s?saxonExtensionFunctions=#function1,#function2", XSLT_PATH)
+                        
.to("log:org.apache.camel.component.xslt.extensions?level=INFO");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonSpringExtensionFunctionsTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonSpringExtensionFunctionsTest.java
 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonSpringExtensionFunctionsTest.java
new file mode 100644
index 0000000..4c3708a
--- /dev/null
+++ 
b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/extensions/SaxonSpringExtensionFunctionsTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.extensions;
+
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SaxonSpringExtensionFunctionsTest extends CamelSpringTestSupport {
+    private static final String XSLT_RESULT = "<?xml version=\"1.0\" 
encoding=\"UTF-8\"?><Test1>3</Test1><Test2>abccde</Test2><Test3>xyz</Test3>";
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/xslt/extensions/camelXsltContext.xml");
+    }
+
+    @Test
+    public void testExtensions() {
+        String result = template().requestBody("direct:extensions", 
"<dummy/>", String.class);
+        assertNotNull(result);
+        assertEquals(XSLT_RESULT, result);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/camelXsltContext.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/camelXsltContext.xml
 
b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/camelXsltContext.xml
new file mode 100644
index 0000000..d875259
--- /dev/null
+++ 
b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/camelXsltContext.xml
@@ -0,0 +1,37 @@
+<?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="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+    <route>
+      <from uri="direct:extensions"/>
+      <to 
uri="xslt:org/apache/camel/component/xslt/extensions/extensions.xslt?saxonExtensionFunctions=#function1,#function2"/>
+      <to uri="log:org.apache.camel.component.xslt.extensions?level=INFO"/>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+  
+  <bean id="function1" 
class="org.apache.camel.component.xslt.extensions.MyExtensionFunction1"/>
+  <bean id="function2" 
class="org.apache.camel.component.xslt.extensions.MyExtensionFunction2"/>
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/4183cbb8/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/extensions.xslt
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/extensions.xslt
 
b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/extensions.xslt
new file mode 100644
index 0000000..3bd9fdc
--- /dev/null
+++ 
b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/extensions/extensions.xslt
@@ -0,0 +1,37 @@
+<?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.
+-->
+<xsl:stylesheet version="2.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+    xmlns:func="http://mytest/"; 
+    exclude-result-prefixes="func">
+
+       <xsl:output method="xml" encoding="UTF-8" indent="no" />
+
+       <xsl:template match="/">
+               <Test1>
+            <xsl:value-of select="func:myExtensionFunction1(1, 2)"/>
+        </Test1>
+        <Test2>
+            <xsl:value-of select="func:myExtensionFunction2('abc', 'cde')"/>
+        </Test2>
+        <Test3>
+            <xsl:value-of select="func:myExtensionFunction2('xyz')"/>
+        </Test3>
+       </xsl:template>
+
+</xsl:stylesheet>

Reply via email to