CAMEL-8182: Add documentType option to xml dsl. Thanks to Stephan Siano for the 
patch.


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

Branch: refs/heads/master
Commit: 9277eacd5e78ffb6f30c8624d343a82fce935233
Parents: 780c096
Author: Claus Ibsen <[email protected]>
Authored: Mon Jan 19 14:32:26 2015 +0100
Committer: Claus Ibsen <[email protected]>
Committed: Mon Jan 19 14:32:26 2015 +0100

----------------------------------------------------------------------
 .../camel/model/language/XPathExpression.java   | 33 ++++++++++++++++++++
 .../camel/language/xpath/XPathLanguageTest.xml  |  8 ++---
 2 files changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9277eacd/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java 
b/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
index ba0e580..fc0bfcb 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/language/XPathExpression.java
@@ -37,6 +37,8 @@ import org.apache.camel.util.ObjectHelper;
 @XmlRootElement(name = "xpath")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class XPathExpression extends NamespaceAwareExpression {
+    @XmlAttribute(name = "documentType")
+    private String documentTypeName;
     @XmlAttribute(name = "resultType")
     private String resultTypeName;
     @XmlAttribute(name = "saxon")
@@ -50,6 +52,8 @@ public class XPathExpression extends NamespaceAwareExpression 
{
     @XmlAttribute(name = "headerName")
     private String headerName;
     @XmlTransient
+    private Class<?> documentType;
+    @XmlTransient
     private Class<?> resultType;
     @XmlTransient
     private XPathFactory xpathFactory;
@@ -69,6 +73,22 @@ public class XPathExpression extends 
NamespaceAwareExpression {
         return "xpath";
     }
 
+    public Class<?> getDocumentType() {
+        return documentType;
+    }
+
+    public void setDocumentType(Class<?> documentType) {
+        this.documentType = documentType;
+    }
+
+    public String getDocumentTypeName() {
+        return documentTypeName;
+    }
+
+    public void setDocumentTypeName(String documentTypeName) {
+        this.documentTypeName = documentTypeName;
+    }
+
     public Class<?> getResultType() {
         return resultType;
     }
@@ -135,6 +155,13 @@ public class XPathExpression extends 
NamespaceAwareExpression {
 
     @Override
     public Expression createExpression(CamelContext camelContext) {
+        if (documentType == null && documentTypeName != null) {
+            try {
+                documentType = 
camelContext.getClassResolver().resolveMandatoryClass(documentTypeName);
+            } catch (ClassNotFoundException e) {
+                throw ObjectHelper.wrapRuntimeCamelException(e);
+            }
+        }
         if (resultType == null && resultTypeName != null) {
             try {
                 resultType = 
camelContext.getClassResolver().resolveMandatoryClass(resultTypeName);
@@ -154,6 +181,9 @@ public class XPathExpression extends 
NamespaceAwareExpression {
 
     @Override
     protected void configureExpression(CamelContext camelContext, Expression 
expression) {
+        if (documentType != null) {
+            setProperty(expression, "documentType", documentType);
+        }
         if (resultType != null) {
             setProperty(expression, "resultType", resultType);
         }
@@ -179,6 +209,9 @@ public class XPathExpression extends 
NamespaceAwareExpression {
 
     @Override
     protected void configurePredicate(CamelContext camelContext, Predicate 
predicate) {
+        if (documentType != null) {
+            setProperty(predicate, "documentType", documentType);
+        }
         if (resultType != null) {
             setProperty(predicate, "resultType", resultType);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/9277eacd/components/camel-saxon/src/test/resources/org/apache/camel/language/xpath/XPathLanguageTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-saxon/src/test/resources/org/apache/camel/language/xpath/XPathLanguageTest.xml
 
b/components/camel-saxon/src/test/resources/org/apache/camel/language/xpath/XPathLanguageTest.xml
index 67f93d5..e1f4485 100644
--- 
a/components/camel-saxon/src/test/resources/org/apache/camel/language/xpath/XPathLanguageTest.xml
+++ 
b/components/camel-saxon/src/test/resources/org/apache/camel/language/xpath/XPathLanguageTest.xml
@@ -33,7 +33,7 @@
     <route>
       <from uri="direct:testSaxonWithFlag"/>
       <setBody>
-        <xpath saxon="true" resultType="java.lang.String" 
logNamespaces="true">tokenize(a, '\|')</xpath>
+        <xpath saxon="true" documentType="javax.xml.transform.sax.SAXSource" 
resultType="java.lang.String" logNamespaces="true">tokenize(a, '\|')</xpath>
       </setBody>
       <log message="Test Saxon with flag: ${body}"/>
       <to uri="mock:testSaxonWithFlagResult"/>
@@ -42,7 +42,7 @@
     <route>
       <from uri="direct:testSaxonWithFactory"/>
       <setBody>
-        <xpath factoryRef="saxonFactory" resultType="java.lang.String" 
logNamespaces="true">tokenize(a, '\|')</xpath>
+        <xpath factoryRef="saxonFactory" 
documentType="org.xml.sax.InputSource" resultType="java.lang.String" 
logNamespaces="true">tokenize(a, '\|')</xpath>
       </setBody>
       <log message="Test Saxon with factory: ${body}"/>
       <to uri="mock:testSaxonWithFactoryResult"/>
@@ -64,7 +64,7 @@
     <route>
       <from uri="direct:testSaxonWithFlagPredicate"/>
       <filter>
-        <xpath saxon="true" resultType="java.lang.String">tokenize(a, '\|')[1] 
= 'Hello'</xpath>
+        <xpath saxon="true" documentType="javax.xml.transform.sax.SAXSource" 
resultType="java.lang.String">tokenize(a, '\|')[1] = 'Hello'</xpath>
         <log message="Test Saxon with flag: ${body}"/>
         <to uri="mock:testSaxonWithFlagResultPredicate"/>
       </filter>
@@ -73,7 +73,7 @@
     <route>
       <from uri="direct:testSaxonWithFactoryPredicate"/>
       <filter>
-        <xpath factoryRef="saxonFactory" 
resultType="java.lang.String">tokenize(a, '\|')[1] = 'Hello'</xpath>
+        <xpath factoryRef="saxonFactory" 
documentType="org.xml.sax.InputSource" 
resultType="java.lang.String">tokenize(a, '\|')[1] = 'Hello'</xpath>
         <log message="Test Saxon with factory: ${body}"/>
         <to uri="mock:testSaxonWithFactoryResultPredicate"/>
       </filter>

Reply via email to