camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject git commit: CAMEL-7468: allow a null namespace map for unqualified elements matching
Date Fri, 04 Jul 2014 08:57:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master fb8cff7c3 -> c69feb066


CAMEL-7468: allow a null namespace map for unqualified elements matching


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

Branch: refs/heads/master
Commit: c69feb0661aa353ce86f2abb43ba75a8a17c794a
Parents: fb8cff7
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Wed Jul 2 13:50:15 2014 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Jul 4 10:56:23 2014 +0200

----------------------------------------------------------------------
 .../support/XMLTokenExpressionIterator.java     |  2 +-
 .../support/XMLTokenExpressionIteratorTest.java | 33 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c69feb06/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java
b/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java
index 655feef..a9ca796 100644
--- a/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java
+++ b/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java
@@ -151,7 +151,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements
Nam
                     String pfx = d > 0 ? s.substring(0, d) : "";
                     this.splitpath[i] = 
                         new AttributedQName(
-                            "*".equals(pfx) ? "*" : nsmap.get(pfx), d > 0 ? s.substring(d
+ 1) : s, pfx);
+                            "*".equals(pfx) ? "*" : nsmap == null ? "" : nsmap.get(pfx),
d > 0 ? s.substring(d + 1) : s, pfx);
                 }
             }
             

http://git-wip-us.apache.org/repos/asf/camel/blob/c69feb06/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorTest.java
b/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorTest.java
index 3954038..f787f2a 100644
--- a/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorTest.java
@@ -155,6 +155,7 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
         "<child some_attr='c' anotherAttr='c' xmlns:g=\"urn:g\" xmlns:c=\"urn:c\"></child>",
     };
 
+    // note that there is no preceding sibling to the extracted child
     private static final String[] RESULTS_CHILD_NO_NS_MIXED_WRAPPED = {
         "<?xml version='1.0' encoding='UTF-8'?><g:greatgrandparent xmlns:g='urn:g'><grandparent>"
             + "<parent some_attr='1' xmlns:c='urn:c' xmlns=\"urn:c\">"
@@ -164,6 +165,23 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
             + "<child some_attr='c' anotherAttr='c'></child></c:parent></grandparent></g:greatgrandparent>",
     };
 
+    private static final String[] RESULTS_CHILD_NS_MIXED = {
+        "<x:child xmlns:x='urn:c' some_attr='b' anotherAttr='b' xmlns='urn:c' xmlns:g='urn:g'
xmlns:c='urn:c'/>",
+        "<c:child some_attr='d' anotherAttr='d' xmlns:g=\"urn:g\" xmlns:c=\"urn:c\"/>"
+    };
+
+    // note that there is a preceding sibling to the extracted child
+    private static final String[] RESULTS_CHILD_NS_MIXED_WRAPPED = {
+        "<?xml version='1.0' encoding='UTF-8'?><g:greatgrandparent xmlns:g='urn:g'><grandparent>"
+            + "<parent some_attr='1' xmlns:c='urn:c' xmlns=\"urn:c\">"
+            + "<child some_attr='a' anotherAttr='a' xmlns=''></child>"
+            + "<x:child xmlns:x='urn:c' some_attr='b' anotherAttr='b'/></parent></grandparent></g:greatgrandparent>",
+        "<?xml version='1.0' encoding='UTF-8'?><g:greatgrandparent xmlns:g='urn:g'><grandparent>"
+            + "<c:parent some_attr='2' xmlns:c='urn:c'>"
+            + "<child some_attr='c' anotherAttr='c'></child>"
+            + "<c:child some_attr='d' anotherAttr='d'/></c:parent></grandparent></g:greatgrandparent>"
+    };
+
     private static final String[] RESULTS_PARENT_WRAPPED = {
         "<?xml version='1.0' encoding='UTF-8'?>"
             + "<g:greatgrandparent xmlns:g='urn:g'><grandparent><uncle/><aunt>emma</aunt>"
@@ -277,6 +295,21 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
         invokeAndVerify("//child", 'i', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED),
RESULTS_CHILD_NO_NS_MIXED);
     }
 
+    public void testExtractSomeQualifiedChild() throws Exception {
+        nsmap.put("", "urn:c");
+        invokeAndVerify("//child", 'w', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED),
RESULTS_CHILD_NS_MIXED_WRAPPED);
+    }
+
+    public void testExtractSomeQualifiedChildInjected() throws Exception {
+        nsmap.put("", "urn:c");
+        invokeAndVerify("//child", 'i', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED),
RESULTS_CHILD_NS_MIXED);
+    }
+
+    public void testExtractWithNullNamespaceMap() throws Exception {
+        nsmap = null;
+        invokeAndVerify("//child", 'i', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED),
RESULTS_CHILD_NO_NS_MIXED);
+    }
+
     public void testExtractChildWithAncestorGGPdGP() throws Exception {
         invokeAndVerify("/G:greatgrandparent/grandparent//C:child", 
                         'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);


Mime
View raw message