camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1414838 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerNamespaceTest.java
Date Wed, 28 Nov 2012 17:46:52 GMT
Author: davsclaus
Date: Wed Nov 28 17:46:50 2012
New Revision: 1414838

URL: http://svn.apache.org/viewvc?rev=1414838&view=rev
Log:
CAMEL-5826: Fixed issue with XML streaming tokenizer dealing with inheriting namespaces from
parent tag. Thanks to Rich Newcomb for the patch.

Added:
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerNamespaceTest.java
      - copied unchanged from r1414837, camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerNamespaceTest.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1414836
  Merged /camel/branches/camel-2.10.x:r1414837

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java?rev=1414838&r1=1414837&r2=1414838&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java
(original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/support/TokenXMLPairExpressionIterator.java
Wed Nov 28 17:46:50 2012
@@ -41,6 +41,7 @@ public class TokenXMLPairExpressionItera
 
     private static final Pattern NAMESPACE_PATTERN = Pattern.compile("xmlns(:\\w+|)=\\\"(.*?)\\\"");
     private static final String SCAN_TOKEN_REGEX = "(\\s+.*?|)>";
+    private static final String SCAN_TOKEN_NS_PREFIX_REGEX = "(.{1,15}?:|)";
     protected final String inheritNamespaceToken;
 
     public TokenXMLPairExpressionIterator(String startToken, String endToken, String inheritNamespaceToken)
{
@@ -81,15 +82,22 @@ public class TokenXMLPairExpressionItera
         XMLTokenPairIterator(String startToken, String endToken, String inheritNamespaceToken,
InputStream in, String charset) {
             super(startToken, endToken, true, in, charset);
 
-            // remove any ending > as we need to support attributes on the tags, so we
need to use a reg exp pattern
-            String token = startToken.substring(0, startToken.length() - 1) + SCAN_TOKEN_REGEX;
-            this.startTokenPattern = Pattern.compile(token);
-            this.scanEndToken = endToken.substring(0, endToken.length() - 1) + SCAN_TOKEN_REGEX;
+            // remove any beginning < and ending > as we need to support ns prefixes
and attributes, so we use a reg exp patterns
+            StringBuilder tokenSb = new StringBuilder("<").append(SCAN_TOKEN_NS_PREFIX_REGEX).
+                                append(startToken.substring(1, startToken.length() - 1)).append(SCAN_TOKEN_REGEX);
+            this.startTokenPattern = Pattern.compile(tokenSb.toString());
+            
+            tokenSb = new StringBuilder("</").append(SCAN_TOKEN_NS_PREFIX_REGEX).
+                                append(endToken.substring(2, endToken.length() - 1)).append(SCAN_TOKEN_REGEX);
+            this.scanEndToken = tokenSb.toString();
+            
             this.inheritNamespaceToken = inheritNamespaceToken;
             if (inheritNamespaceToken != null) {
-                token = inheritNamespaceToken.substring(0, inheritNamespaceToken.length()
- 1) + SCAN_TOKEN_REGEX;
+                // the inherit namespace token may itself have a namespace prefix
+                tokenSb = new StringBuilder("<").append(SCAN_TOKEN_NS_PREFIX_REGEX).
+                                append(inheritNamespaceToken.substring(1, inheritNamespaceToken.length()
- 1)).append(SCAN_TOKEN_REGEX);  
                 // the namespaces on the parent tag can be in multi line, so we need to instruct
the dot to support multilines
-                this.inheritNamespaceTokenPattern = Pattern.compile(token, Pattern.MULTILINE
| Pattern.DOTALL);
+                this.inheritNamespaceTokenPattern = Pattern.compile(tokenSb.toString(), Pattern.MULTILINE
| Pattern.DOTALL);
             }
         }
 
@@ -125,17 +133,26 @@ public class TokenXMLPairExpressionItera
                 next = next.substring(index);
             }
 
+            // make sure the end tag matches the begin tag if the tag has a namespace prefix
+            String tag = ObjectHelper.before(next, ">");
+            StringBuilder endTagSb = new StringBuilder("</");
+            int firstSpaceIndex = tag.indexOf(" ");
+            if (firstSpaceIndex > 0) {
+                endTagSb.append(tag.substring(1, firstSpaceIndex)).append(">");
+            } else {
+                endTagSb.append(tag.substring(1, tag.length())).append(">");
+            }
+            
             // build answer accordingly to whether namespaces should be inherited or not
             StringBuilder sb = new StringBuilder();
             if (inheritNamespaceToken != null && rootTokenNamespaces != null) {
                 // append root namespaces to local start token
-                String tag = ObjectHelper.before(next, ">");
                 // grab the text
                 String text = ObjectHelper.after(next, ">");
                 // build result with inherited namespaces
-                next = sb.append(tag).append(rootTokenNamespaces).append(">").append(text).append(endToken).toString();
+                next = sb.append(tag).append(rootTokenNamespaces).append(">").append(text).append(endTagSb.toString()).toString();
             } else {
-                next = sb.append(next).append(endToken).toString();
+                next = sb.append(next).append(endTagSb.toString()).toString();
             }
 
             return next;



Mime
View raw message