camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r908466 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java
Date Wed, 10 Feb 2010 12:15:13 GMT
Author: davsclaus
Date: Wed Feb 10 12:15:12 2010
New Revision: 908466

URL: http://svn.apache.org/viewvc?rev=908466&view=rev
Log:
CAMEL-1877: XPathBuilder now supports reading xpath factory defined as a system property.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
    camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=908466&r1=908465&r2=908466&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Wed
Feb 10 12:15:12 2010
@@ -20,6 +20,7 @@
 import java.io.StringReader;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import javax.xml.namespace.QName;
@@ -358,9 +359,29 @@
     public XPathFactory getXPathFactory() throws XPathFactoryConfigurationException {
         if (xpathFactory == null) {
             if (objectModelUri != null) {
+                LOG.info("Using objectModelUri " + objectModelUri + " when creating XPathFactory");
                 xpathFactory = XPathFactory.newInstance(objectModelUri);
+                return xpathFactory;
+            }
+
+            // read system property and see if there is a factory set
+            Properties properties = System.getProperties();
+            for (Map.Entry prop : properties.entrySet()) {
+                String key = (String) prop.getKey();
+                if (key.startsWith(XPathFactory.DEFAULT_PROPERTY_NAME)) {
+                    String uri = ObjectHelper.after(key, ":");
+                    if (uri != null) {
+                        LOG.info("Using system property " + key + " with value: " + prop.getValue()
+ " when creating XPathFactory");
+                        xpathFactory = XPathFactory.newInstance(uri);
+                        return xpathFactory;
+                    }
+                }
+            }
+
+            if (xpathFactory == null) {
+                LOG.debug("Creating default XPathFactory");
+                xpathFactory = XPathFactory.newInstance();
             }
-            xpathFactory = XPathFactory.newInstance();
         }
         return xpathFactory;
     }

Modified: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java?rev=908466&r1=908465&r2=908466&view=diff
==============================================================================
--- camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java
(original)
+++ camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java
Wed Feb 10 12:15:12 2010
@@ -92,4 +92,19 @@
         assertEquals("def", result);
         // END SNIPPET: e3
     }
+
+    @Test
+    public void testXPathFunctionTokenizeUsingSystemProperty() throws Exception {
+        // START SNIPPET: e4
+        // set system property with the XPath factory to use which is Saxon 
+        System.setProperty(XPathFactory.DEFAULT_PROPERTY_NAME + ":" + "http://saxon.sf.net/jaxp/xpath/om",
"net.sf.saxon.xpath.XPathFactoryImpl");
+
+        // create a builder to evaluate the xpath using saxon
+        XPathBuilder builder = XPathBuilder.xpath("tokenize(/foo/bar, '_')[2]");
+
+        // evaluate as a String result
+        String result = builder.evaluate(context, "<foo><bar>abc_def_ghi</bar></foo>");
+        assertEquals("def", result);
+        // END SNIPPET: e4
+    }
 }



Mime
View raw message