You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ay...@apache.org on 2014/06/02 10:36:12 UTC
[1/2] git commit: add spring config for CAMEL-7468 and consolidate
the configuration options
Repository: camel
Updated Branches:
refs/heads/master f17f778c8 -> c04e4d029
add spring config for CAMEL-7468 and consolidate the configuration options
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c04e4d02
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c04e4d02
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c04e4d02
Branch: refs/heads/master
Commit: c04e4d02902481670fb952fa56a13cadb29c9cbb
Parents: 2272138
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Sat May 31 00:09:24 2014 +0200
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Mon Jun 2 10:19:31 2014 +0200
----------------------------------------------------------------------
camel-core/pom.xml | 23 +++--
.../apache/camel/builder/ExpressionBuilder.java | 5 +-
.../apache/camel/builder/ExpressionClause.java | 12 ++-
.../camel/builder/ExpressionClauseSupport.java | 14 ++-
.../org/apache/camel/builder/ValueBuilder.java | 12 +++
.../language/tokenizer/XMLTokenizeLanguage.java | 37 ++++----
.../model/language/XMLTokenizerExpression.java | 21 +++--
.../support/XMLTokenExpressionIterator.java | 48 ++++++----
.../org/apache/camel/model/language/jaxb.index | 1 +
.../camel/language/XMLTokenSplitTest.java | 94 ++++++++++++++++++++
.../tokenizer/XMLTokenizeLanguageTest.java | 2 +-
.../tokenizer/XMLTokenizeWrapLanguageTest.java | 2 +-
.../support/XMLTokenExpressionIteratorTest.java | 66 +++++++++-----
components/camel-spring/pom.xml | 15 ++++
.../camel/language/SpringXMLTokenSplitTest.java | 36 ++++++++
.../camel/language/SpringXMLTokenSplitTest.xml | 39 ++++++++
16 files changed, 336 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/pom.xml
----------------------------------------------------------------------
diff --git a/camel-core/pom.xml b/camel-core/pom.xml
index 905b5fe..6051d23 100644
--- a/camel-core/pom.xml
+++ b/camel-core/pom.xml
@@ -169,14 +169,6 @@
<scope>test</scope>
</dependency>
- <!-- xmltokenizer using woodstox -->
- <dependency>
- <groupId>org.codehaus.woodstox</groupId>
- <artifactId>woodstox-core-asl</artifactId>
- <version>${woodstox-version}</version>
- <scope>test</scope>
- </dependency>
-
</dependencies>
@@ -502,6 +494,21 @@
</dependency>
</dependencies>
</profile>
+ <profile>
+ <id>woodstox</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <!-- xmltokenizer using woodstox -->
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>woodstox-core-asl</artifactId>
+ <version>${woodstox-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
</profiles>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index 8af5f57..44624d8 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -25,7 +25,6 @@ import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
@@ -1232,10 +1231,10 @@ public final class ExpressionBuilder {
return new TokenXMLExpressionIterator(tagName, inheritNamespaceTagName);
}
- public static Expression tokenizeXMLAwareExpression(String path, boolean wrap) {
+ public static Expression tokenizeXMLAwareExpression(String path, char mode) {
ObjectHelper.notEmpty(path, "path");
- return new XMLTokenExpressionIterator(path, wrap);
+ return new XMLTokenExpressionIterator(path, mode);
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
index 8830961..6c05b15 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
@@ -569,12 +569,16 @@ public class ExpressionClause<T> extends ExpressionDefinition {
return delegate.tokenizeXMLPair(tagName, inheritNamespaceTagName, group);
}
- public T tokenizeXML(String path, boolean wrap, Namespaces namespaces) {
- return tokenizeXML(path, wrap, namespaces, 0);
+ public T xtokenize(String path, Namespaces namespaces) {
+ return xtokenize(path, 'i', namespaces);
}
- public T tokenizeXML(String path, boolean wrap, Namespaces namespaces, int group) {
- return delegate.tokenizeXML(path, wrap, namespaces, group);
+ public T xtokenize(String path, char mode, Namespaces namespaces) {
+ return xtokenize(path, mode, namespaces, 0);
+ }
+
+ public T xtokenize(String path, char mode, Namespaces namespaces, int group) {
+ return delegate.xtokenize(path, mode, namespaces, group);
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
index e647122..2d31a27 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
@@ -604,9 +604,19 @@ public class ExpressionClauseSupport<T> {
return result;
}
- public T tokenizeXML(String path, boolean wrap, Namespaces namespaces, int group) {
+ /**
+ * Evaluates an XML token expression on the message body with XML content
+ *
+ * @param path the xpath like path notation specifying the child nodes to tokenize
+ * @param mode one of 'i', 'w', or 'u' to inject the namespaces to the token, to
+ * wrap the token with its ancestor contet, or to unwrap to its element child
+ * @param namespaces the namespace map to the namespace bindings
+ * @param group to group by the given number
+ * @return
+ */
+ public T xtokenize(String path, char mode, Namespaces namespaces, int group) {
XMLTokenizerExpression expression = new XMLTokenizerExpression(path);
- expression.setWrap(wrap);
+ expression.setMode(Character.toString(mode));
expression.setNamespaces(namespaces.getNamespaces());
if (group > 0) {
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
index 31c4b96..e83400d 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
@@ -23,6 +23,8 @@ import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
+import org.apache.camel.builder.xml.Namespaces;
+import org.apache.camel.spi.NamespaceAware;
import org.apache.camel.util.ExpressionToPredicateAdapter;
/**
@@ -182,6 +184,16 @@ public class ValueBuilder implements Expression, Predicate {
return new ValueBuilder(newExp);
}
+ public ValueBuilder xtokenize(String path, Namespaces namespaces) {
+ return xtokenize(path, 'i', namespaces);
+ }
+
+ public ValueBuilder xtokenize(String path, char mode, Namespaces namespaces) {
+ Expression newExp = ExpressionBuilder.tokenizeXMLAwareExpression(path, mode);
+ ((NamespaceAware)newExp).setNamespaces(namespaces.getNamespaces());
+ return new ValueBuilder(newExp);
+ }
+
public ValueBuilder tokenizePair(String startToken, String endToken, boolean includeTokens) {
Expression newExp = ExpressionBuilder.tokenizePairExpression(startToken, endToken, includeTokens);
return new ValueBuilder(newExp);
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguage.java b/camel-core/src/main/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguage.java
index 46b06f7..aa16aa9 100644
--- a/camel-core/src/main/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguage.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.language.tokenizer;
-import java.util.Map;
-
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
import org.apache.camel.builder.ExpressionBuilder;
@@ -30,37 +28,38 @@ import org.apache.camel.util.ObjectHelper;
* <p/>
* This xmltokenizer language can operate in the following modes:
* <ul>
+ * <li>inject - injecting the contextual namespace bindings into the extracted token</li>
* <li>wrap - wrapping the extracted token in its ancestor context</li>
- * <li>injected - injecting the contextual namespace bindings into the extracted token</li>
+ * <li>unwrap - unwrapping the extracted token to its child content</li>
* </ul>
*/
public class XMLTokenizeLanguage extends LanguageSupport {
private String path;
private String headerName;
- private boolean wrap;
+ private char mode;
private int group;
- public static Expression tokenize(String token) {
- return tokenize(token, false);
+ public static Expression tokenize(String path) {
+ return tokenize(path, 'i');
}
- public static Expression tokenize(String token, boolean wrap) {
+ public static Expression tokenize(String path, char mode) {
XMLTokenizeLanguage language = new XMLTokenizeLanguage();
- language.setPath(token);
- language.setWrap(wrap);
+ language.setPath(path);
+ language.setMode(mode);
return language.createExpression(null);
}
- public static Expression tokenize(String headerName, String token) {
- return tokenize(headerName, token, false);
+ public static Expression tokenize(String headerName, String path) {
+ return tokenize(headerName, path, 'i');
}
- public static Expression tokenize(String headerName, String token, boolean wrap) {
+ public static Expression tokenize(String headerName, String path, char mode) {
XMLTokenizeLanguage language = new XMLTokenizeLanguage();
language.setHeaderName(headerName);
- language.setPath(token);
- language.setWrap(wrap);
+ language.setPath(path);
+ language.setMode(mode);
return language.createExpression(null);
}
@@ -74,7 +73,7 @@ public class XMLTokenizeLanguage extends LanguageSupport {
public Expression createExpression() {
ObjectHelper.notNull(path, "token");
- Expression answer = ExpressionBuilder.tokenizeXMLAwareExpression(path, wrap);
+ Expression answer = ExpressionBuilder.tokenizeXMLAwareExpression(path, mode);
// if group then wrap answer in group expression
if (group > 0) {
@@ -108,12 +107,12 @@ public class XMLTokenizeLanguage extends LanguageSupport {
this.headerName = headerName;
}
- public boolean isWrap() {
- return wrap;
+ public char getMode() {
+ return mode;
}
- public void setWrap(boolean wrap) {
- this.wrap = wrap;
+ public void setMode(char mode) {
+ this.mode = mode;
}
public int getGroup() {
return group;
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java b/camel-core/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
index a9e36fa..7052ab7 100644
--- a/camel-core/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
@@ -25,20 +25,19 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
import org.apache.camel.language.tokenizer.XMLTokenizeLanguage;
-import org.apache.camel.util.ExpressionToPredicateAdapter;
/**
* For expressions and predicates using a body or header tokenizer.
*
* @see XMLTokenizeLanguage
*/
-@XmlRootElement(name = "xmlTokenize")
+@XmlRootElement(name = "xtokenize")
@XmlAccessorType(XmlAccessType.FIELD)
public class XMLTokenizerExpression extends NamespaceAwareExpression {
@XmlAttribute
private String headerName;
@XmlAttribute
- private Boolean wrap;
+ private String mode;
@XmlAttribute
private Integer group;
@@ -62,12 +61,12 @@ public class XMLTokenizerExpression extends NamespaceAwareExpression {
this.headerName = headerName;
}
- public void setWrap(boolean wrap) {
- this.wrap = wrap;
+ public void setMode(String mode) {
+ this.mode = mode;
}
- public Boolean getWrap() {
- return wrap;
+ public String getMode() {
+ return mode;
}
public Integer getGroup() {
@@ -81,16 +80,16 @@ public class XMLTokenizerExpression extends NamespaceAwareExpression {
@Override
protected void configureExpression(CamelContext camelContext, Expression expression) {
super.configureExpression(camelContext, expression);
- if (wrap != null) {
- setProperty(expression, "wrap", wrap);
+ if (mode != null) {
+ setProperty(expression, "mode", mode);
}
}
@Override
protected void configurePredicate(CamelContext camelContext, Predicate predicate) {
super.configurePredicate(camelContext, predicate);
- if (wrap != null) {
- setProperty(predicate, "wrap", wrap);
+ if (mode != null) {
+ setProperty(predicate, "mode", mode);
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/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 a8b8aa8..2273e85 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
@@ -48,13 +48,13 @@ import org.slf4j.LoggerFactory;
*/
public class XMLTokenExpressionIterator extends ExpressionAdapter implements NamespaceAware {
protected final String path;
- protected boolean wrap;
+ protected char mode;
protected Map<String, String> nsmap;
- public XMLTokenExpressionIterator(String path, boolean wrap) {
+ public XMLTokenExpressionIterator(String path, char mode) {
ObjectHelper.notEmpty(path, "path");
this.path = path;
- this.wrap = wrap;
+ this.mode = mode;
}
@Override
@@ -62,12 +62,16 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
this.nsmap = nsmap;
}
- public void setWrap(boolean wrap) {
- this.wrap = wrap;
+ public void setMode(char mode) {
+ this.mode = mode;
+ }
+
+ public void setMode(String mode) {
+ this.mode = mode != null ? mode.charAt(0) : 0;
}
protected Iterator<?> createIterator(InputStream in, Exchange exchange) throws XMLStreamException {
- XMLTokenIterator iterator = new XMLTokenIterator(path, nsmap, wrap, in, exchange);
+ XMLTokenIterator iterator = new XMLTokenIterator(path, nsmap, mode, in, exchange);
return iterator;
}
@@ -121,7 +125,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
private AttributedQName[] splitpath;
private int index;
- private boolean wrap;
+ private char mode;
private RecordableInputStream in;
private XMLStreamReader reader;
private List<QName> path;
@@ -136,7 +140,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
private Object nextToken;
- public XMLTokenIterator(String path, Map<String, String> nsmap, boolean wrap, InputStream in, Exchange exchange) throws XMLStreamException {
+ public XMLTokenIterator(String path, Map<String, String> nsmap, char mode, InputStream in, Exchange exchange) throws XMLStreamException {
final String[] sl = path.substring(1).split("/");
this.splitpath = new AttributedQName[sl.length];
for (int i = 0; i < sl.length; i++) {
@@ -150,7 +154,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
}
}
- this.wrap = wrap;
+ this.mode = mode != 0 ? mode : 'i';
String charset = IOHelper.getCharsetName(exchange, false);
this.in = new RecordableInputStream(in, charset);
this.reader = new StaxConverter().createXMLStreamReader(this.in, exchange);
@@ -165,10 +169,10 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
this.path = new ArrayList<QName>();
// wrapped mode needs the segments and the injected mode needs the namespaces
- if (wrap) {
+ if (this.mode == 'w') {
this.segments = new ArrayList<String>();
this.segmentlog = new ArrayList<QName>();
- } else {
+ } else if (this.mode == 'i') {
this.namespaces = new ArrayList<Map<String, String>>();
}
@@ -297,7 +301,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
popName();
String token = createContextualToken(getCurrenText());
- if (!wrap) {
+ if (mode == 'i') {
popNamespaces();
}
@@ -306,7 +310,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
private String createContextualToken(String token) {
StringBuilder sb = new StringBuilder();
- if (wrap) {
+ if (mode == 'w') {
for (int i = 0; i < segments.size(); i++) {
sb.append(segments.get(i));
}
@@ -316,7 +320,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
sb.append("</").append(makeName(q)).append(">");
}
- } else {
+ } else if (mode == 'i') {
final String stag = token.substring(0, token.indexOf('>') + 1);
Set<String> skip = new HashSet<String>();
Matcher matcher = NAMESPACE_PATTERN.matcher(stag);
@@ -343,6 +347,12 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
}
}
sb.append(token.substring(stag.length() - (empty ? 2 : 1)));
+ } else if (mode == 'u') {
+ int bp = token.indexOf(">");
+ int ep = token.lastIndexOf("</");
+ if (bp > 0 && ep > 0) {
+ sb.append(token.substring(bp + 1, ep));
+ }
}
return sb.toString();
@@ -363,11 +373,11 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
String token = getCurrenText();
LOG.trace("token={}", token);
- if (!backtrack && wrap) {
+ if (!backtrack && mode == 'w') {
pushSegment(name, token);
}
pushName(name);
- if (!wrap) {
+ if (mode == 'i') {
pushNamespaces(reader);
}
backtrack = false;
@@ -396,7 +406,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
LOG.trace("ee={}", endname);
popName();
- if (!wrap) {
+ if (mode == 'i') {
popNamespaces();
}
@@ -405,7 +415,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
// reactive backtrack if not backtracking and update the track depth
backtrack = true;
trackdepth--;
- if (wrap) {
+ if (mode == 'w') {
while (!endname.equals(peekLog())) {
pc++;
popLog();
@@ -414,7 +424,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
}
if (backtrack) {
- if (wrap) {
+ if (mode == 'w') {
for (int i = 0; i < pc; i++) {
popSegment();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
index 7dce959..aa9653b 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/language/jaxb.index
@@ -36,5 +36,6 @@ SpELExpression
SqlExpression
TokenizerExpression
VtdXmlExpression
+XMLTokenizerExpression
XPathExpression
XQueryExpression
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/test/java/org/apache/camel/language/XMLTokenSplitTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/XMLTokenSplitTest.java b/camel-core/src/test/java/org/apache/camel/language/XMLTokenSplitTest.java
new file mode 100644
index 0000000..c2cd263
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/language/XMLTokenSplitTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.language;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.xml.Namespaces;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ *
+ */
+public class XMLTokenSplitTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/xtokenizer");
+ deleteDirectory("target/xtokenizer2");
+ super.setUp();
+ }
+
+ public void testXMLToken() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:split");
+ mock.expectedMessageCount(3);
+ mock.message(0).body().isEqualTo("<order id=\"1\" xmlns=\"http:acme.com\">Camel in Action</order>");
+ mock.message(1).body().isEqualTo("<order id=\"2\" xmlns=\"http:acme.com\">ActiveMQ in Action</order>");
+ mock.message(2).body().isEqualTo("<order id=\"3\" xmlns=\"http:acme.com\">DSL in Action</order>");
+
+ String body = createBody();
+ template.sendBodyAndHeader("file:target/xtokenizer", body, Exchange.FILE_NAME, "orders.xml");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testXMLToken2() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:split");
+ mock.expectedMessageCount(3);
+ mock.message(0).body().isEqualTo("<order id=\"1\" xmlns=\"http:acme.com\">Camel in Action</order>");
+ mock.message(1).body().isEqualTo("<order id=\"2\" xmlns=\"http:acme.com\">ActiveMQ in Action</order>");
+ mock.message(2).body().isEqualTo("<order id=\"3\" xmlns=\"http:acme.com\">DSL in Action</order>");
+
+ String body = createBody();
+ template.sendBodyAndHeader("file:target/xtokenizer2", body, Exchange.FILE_NAME, "orders.xml");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected String createBody() {
+ StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>\n");
+ sb.append("<orders xmlns=\"http:acme.com\">\n");
+ sb.append(" <order id=\"1\">Camel in Action</order>\n");
+ sb.append(" <order id=\"2\">ActiveMQ in Action</order>\n");
+ sb.append(" <order id=\"3\">DSL in Action</order>\n");
+ sb.append(" <order id=\"4\" xmlns=\"\">Illegal Action</order>\n");
+ sb.append("</orders>");
+ return sb.toString();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ Namespaces ns = new Namespaces("", "http:acme.com");
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ from("file:target/xtokenizer")
+ // split the order child tags, and inherit namespaces from the orders root tag
+ .split().xtokenize("//orders/order", ns)
+ .to("mock:split");
+ // END SNIPPET: e1
+
+ from("file:target/xtokenizer2")
+ // split the order child tags, and inherit namespaces from the orders root tag
+ .split(body().xtokenize("//orders/order", ns))
+ .to("mock:split");
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguageTest.java
index d5c0689..e223ca6 100644
--- a/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeLanguageTest.java
@@ -123,7 +123,7 @@ public class XMLTokenizeLanguageTest extends ContextTestSupport {
Namespaces ns = new Namespaces("C", "urn:c");
public void configure() {
from("direct:start")
- .split().tokenizeXML("//C:child", false, ns)
+ .split().xtokenize("//C:child", ns)
.to("mock:result")
.end();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeWrapLanguageTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeWrapLanguageTest.java b/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeWrapLanguageTest.java
index 1d5d913..6733979 100644
--- a/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeWrapLanguageTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/tokenizer/XMLTokenizeWrapLanguageTest.java
@@ -126,7 +126,7 @@ public class XMLTokenizeWrapLanguageTest extends ContextTestSupport {
Namespaces ns = new Namespaces("C", "urn:c");
public void configure() {
from("direct:start")
- .split().tokenizeXML("//C:child", true, ns)
+ .split().xtokenize("//C:child", 'w', ns)
.to("mock:result")
.end();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/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 fe0c8bf..20866fc 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
@@ -184,6 +184,11 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
"<aunt xmlns:g=\"urn:g\"/>"
};
+ private static final String[] RESULTS_AUNT_UNWRAPPED = {
+ "emma",
+ ""
+ };
+
private static final String[] RESULTS_NULL = {
};
@@ -202,85 +207,100 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
public void testExtractChild() throws Exception {
- invokeAndVerify("//C:child", true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ invokeAndVerify("//C:child", 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildInjected() throws Exception {
- invokeAndVerify("//C:child", false, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
+ invokeAndVerify("//C:child", 'i', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
}
public void testExtractChildNSMixed() throws Exception {
- invokeAndVerify("//*:child", true, new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED_WRAPPED);
+ invokeAndVerify("//*:child", 'w', new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED_WRAPPED);
}
public void testExtractChildNSMixedInjected() throws Exception {
- invokeAndVerify("//*:child", false, new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED);
+ invokeAndVerify("//*:child", 'i', new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED);
}
public void testExtractAnyChild() throws Exception {
- invokeAndVerify("//*:child", true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ invokeAndVerify("//*:child", 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractCxxxd() throws Exception {
- invokeAndVerify("//C:c*d", false, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
+ invokeAndVerify("//C:c*d", 'i', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
}
public void testExtractUnqualifiedChild() throws Exception {
- invokeAndVerify("//child", true, new ByteArrayInputStream(TEST_BODY), RESULTS_NULL);
+ invokeAndVerify("//child", 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_NULL);
}
public void testExtractChildWithAncestorGGPdGP() throws Exception {
invokeAndVerify("/G:greatgrandparent/grandparent//C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildWithAncestorGGPdP() throws Exception {
invokeAndVerify("/G:greatgrandparent//C:parent/C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildWithAncestorGPddP() throws Exception {
invokeAndVerify("//grandparent//C:parent/C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildWithAncestorGPdP() throws Exception {
invokeAndVerify("//grandparent/C:parent/C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildWithAncestorP() throws Exception {
invokeAndVerify("//C:parent/C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
public void testExtractChildWithAncestorGGPdGPdP() throws Exception {
invokeAndVerify("/G:greatgrandparent/grandparent/C:parent/C:child",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
}
- public void textExtractParent() throws Exception {
+ public void testExtractParent() throws Exception {
invokeAndVerify("//C:parent",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_PARENT_WRAPPED);
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_PARENT_WRAPPED);
}
- public void textExtractParentInjected() throws Exception {
+ public void testExtractParentInjected() throws Exception {
invokeAndVerify("//C:parent",
- false, new ByteArrayInputStream(TEST_BODY), RESULTS_PARENT);
+ 'i', new ByteArrayInputStream(TEST_BODY), RESULTS_PARENT);
}
- public void textExtractAunt() throws Exception {
+ public void testExtractAuntWC1() throws Exception {
+ invokeAndVerify("//a*t",
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT_WRAPPED);
+ }
+
+ public void testExtractAuntWC2() throws Exception {
+ invokeAndVerify("//au?t",
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT_WRAPPED);
+ }
+
+ public void testExtractAunt() throws Exception {
+ invokeAndVerify("//aunt",
+ 'w', new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT_WRAPPED);
+ }
+
+ public void testExtractAuntInjected() throws Exception {
invokeAndVerify("//aunt",
- true, new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT_WRAPPED);
+ 'i', new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT);
}
- public void textExtractAuntInjected() throws Exception {
+ public void testExtractAuntUnwrapped() throws Exception {
invokeAndVerify("//aunt",
- false, new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT);
+ 'u', new ByteArrayInputStream(TEST_BODY), RESULTS_AUNT_UNWRAPPED);
}
- private void invokeAndVerify(String path, boolean wrap, InputStream in, String[] expected) throws Exception {
- XMLTokenExpressionIterator xtei = new XMLTokenExpressionIterator(path, wrap);
+ private void invokeAndVerify(String path, char mode, InputStream in, String[] expected) throws Exception {
+ XMLTokenExpressionIterator xtei = new XMLTokenExpressionIterator(path, mode);
xtei.setNamespaces(nsmap);
Iterator<?> it = xtei.createIterator(in, exchange);
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/components/camel-spring/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml
index d6eb313..f388482 100644
--- a/components/camel-spring/pom.xml
+++ b/components/camel-spring/pom.xml
@@ -467,6 +467,21 @@
<platform.skip.tests>org/apache/camel/spring/management/**/*.java</platform.skip.tests>
</properties>
</profile>
+ <profile>
+ <id>woodstox</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <!-- xmltokenizer using woodstox -->
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>woodstox-core-asl</artifactId>
+ <version>${woodstox-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
</profiles>
<reporting>
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/components/camel-spring/src/test/java/org/apache/camel/language/SpringXMLTokenSplitTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/language/SpringXMLTokenSplitTest.java b/components/camel-spring/src/test/java/org/apache/camel/language/SpringXMLTokenSplitTest.java
new file mode 100644
index 0000000..f367986
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/language/SpringXMLTokenSplitTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.language;
+
+import org.apache.camel.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ *
+ */
+public class SpringXMLTokenSplitTest extends XMLTokenSplitTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/language/SpringXMLTokenSplitTest.xml");
+ }
+
+ @Override
+ public void testXMLToken2() throws Exception {
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c04e4d02/components/camel-spring/src/test/resources/org/apache/camel/language/SpringXMLTokenSplitTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/language/SpringXMLTokenSplitTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/language/SpringXMLTokenSplitTest.xml
new file mode 100644
index 0000000..98e8525
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/language/SpringXMLTokenSplitTest.xml
@@ -0,0 +1,39 @@
+<?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: e1 -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring" xmlns:s="http:acme.com">
+ <route>
+ <from uri="file:target/xtokenizer"/>
+ <split>
+ <!-- split the file using XML tokenizer, where we grab the order tag,
+ and inject the namespaces declarations from its ancestor nodes -->
+ <xtokenize>//s:orders/s:order</xtokenize>
+ <to uri="mock:split"/>
+ </split>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: e1 -->
+
+</beans>
[2/2] git commit: add wildcard handling and fix the default nsdecl
handling for the injected mode for CAMEL-7468
Posted by ay...@apache.org.
add wildcard handling and fix the default nsdecl handling for the injected mode for CAMEL-7468
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/22721385
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/22721385
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/22721385
Branch: refs/heads/master
Commit: 22721385334aace46c3b9943a1d715024c17ff73
Parents: f17f778
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Fri May 30 18:32:34 2014 +0200
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Mon Jun 2 10:19:31 2014 +0200
----------------------------------------------------------------------
.../support/TokenXMLExpressionIterator.java | 3 -
.../support/XMLTokenExpressionIterator.java | 68 ++++++++++++++++----
.../support/XMLTokenExpressionIteratorTest.java | 63 +++++++++++++++++-
3 files changed, 116 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/22721385/camel-core/src/main/java/org/apache/camel/support/TokenXMLExpressionIterator.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/TokenXMLExpressionIterator.java b/camel-core/src/main/java/org/apache/camel/support/TokenXMLExpressionIterator.java
index 4192acf..497e63f 100644
--- a/camel-core/src/main/java/org/apache/camel/support/TokenXMLExpressionIterator.java
+++ b/camel-core/src/main/java/org/apache/camel/support/TokenXMLExpressionIterator.java
@@ -16,12 +16,9 @@
*/
package org.apache.camel.support;
-import java.io.ByteArrayOutputStream;
import java.io.Closeable;
-import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
http://git-wip-us.apache.org/repos/asf/camel/blob/22721385/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 111bdaa..a8b8aa8 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
@@ -119,7 +119,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
private static final Logger LOG = LoggerFactory.getLogger(XMLTokenIterator.class);
private static final Pattern NAMESPACE_PATTERN = Pattern.compile("xmlns(:\\w+|)\\s*=\\s*('[^']+'|\"[^\"]+\")");
- private QName[] splitpath;
+ private AttributedQName[] splitpath;
private int index;
private boolean wrap;
private RecordableInputStream in;
@@ -138,13 +138,15 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
public XMLTokenIterator(String path, Map<String, String> nsmap, boolean wrap, InputStream in, Exchange exchange) throws XMLStreamException {
final String[] sl = path.substring(1).split("/");
- this.splitpath = new QName[sl.length];
+ this.splitpath = new AttributedQName[sl.length];
for (int i = 0; i < sl.length; i++) {
String s = sl[i];
if (s.length() > 0) {
int d = s.indexOf(':');
String pfx = d > 0 ? s.substring(0, d) : "";
- this.splitpath[i] = new QName(nsmap.get(pfx), d > 0 ? s.substring(d + 1) : s, pfx);
+ this.splitpath[i] =
+ new AttributedQName(
+ "*".equals(pfx) ? "*" : nsmap.get(pfx), d > 0 ? s.substring(d + 1) : s, pfx);
}
}
@@ -154,7 +156,8 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
this.reader = new StaxConverter().createXMLStreamReader(this.in, exchange);
LOG.trace("reader.class: {}", reader.getClass());
- if (reader.getLocation().getCharacterOffset() < 0) {
+ int coff = reader.getLocation().getCharacterOffset();
+ if (coff != 0) {
LOG.error("XMLStreamReader {} not supporting Location");
throw new XMLStreamException("reader not supporting Location");
}
@@ -177,11 +180,11 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
return splitpath[index] == null;
}
- private QName current() {
+ private AttributedQName current() {
return splitpath[index + (isDoS() ? 1 : 0)];
}
- private QName ancestor() {
+ private AttributedQName ancestor() {
return index == 0 ? null : splitpath[index - 1];
}
@@ -335,7 +338,8 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
sb.append(token.substring(0, stag.length() - (empty ? 2 : 1)));
for (Entry<String, String> e : getCurrentNamespaceBindings().entrySet()) {
if (!skip.contains(e.getKey())) {
- sb.append(" xmlns:").append(e.getKey()).append("=").append(quote).append(e.getValue()).append(quote);
+ sb.append(e.getKey().length() == 0 ? " xmlns" : " xmlns:")
+ .append(e.getKey()).append("=").append(quote).append(e.getValue()).append(quote);
}
}
sb.append(token.substring(stag.length() - (empty ? 2 : 1)));
@@ -367,7 +371,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
pushNamespaces(reader);
}
backtrack = false;
- if (matches(name, current())) {
+ if (current().matches(name)) {
// mark the position of the match in the segments list
if (isBottom()) {
// final match
@@ -417,7 +421,7 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
}
if ((ancestor() == null && !isTop())
- || (ancestor() != null && matches(endname, ancestor()))) {
+ || (ancestor() != null && ancestor().matches(endname))) {
up();
}
}
@@ -437,10 +441,6 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
return pfx.length() == 0 ? qname.getLocalPart() : qname.getPrefix() + ":" + qname.getLocalPart();
}
- private static boolean matches(QName a, QName b) {
- return a.getNamespaceURI().equals(b.getNamespaceURI()) && a.getLocalPart().equals(b.getLocalPart());
- }
-
@Override
public boolean hasNext() {
return nextToken != null;
@@ -472,4 +472,46 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam
}
}
+ static class AttributedQName extends QName {
+ private static final long serialVersionUID = 9878370226894144L;
+ private Pattern lcpattern;
+ private boolean nsany;
+
+ public AttributedQName(String localPart) {
+ super(localPart);
+ checkWildcard("", localPart);
+ }
+
+ public AttributedQName(String namespaceURI, String localPart, String prefix) {
+ super(namespaceURI, localPart, prefix);
+ checkWildcard(namespaceURI, localPart);
+ }
+
+ public AttributedQName(String namespaceURI, String localPart) {
+ super(namespaceURI, localPart);
+ checkWildcard(namespaceURI, localPart);
+ }
+
+ public boolean matches(QName qname) {
+ return (nsany || getNamespaceURI().equals(qname.getNamespaceURI()))
+ && (lcpattern != null
+ ? lcpattern.matcher(qname.getLocalPart()).matches()
+ : getLocalPart().equals(qname.getLocalPart()));
+ }
+
+ private void checkWildcard(String nsa, String lcp) {
+ nsany = "*".equals(nsa);
+ boolean wc = false;
+ for (int i = 0; i < lcp.length(); i++) {
+ char c = lcp.charAt(i);
+ if (c == '?' || c == '*') {
+ wc = true;
+ break;
+ }
+ }
+ if (wc) {
+ lcpattern = Pattern.compile(lcp.replace(".", "\\.").replace("*", ".*").replace("?", "."));
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/22721385/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 67bb159..fe0c8bf 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
@@ -55,7 +55,21 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
+ "</c:parent>"
+ "</grandparent>"
+ "</g:greatgrandparent>").getBytes();
-
+
+ private static final byte[] TEST_BODY_NS_MIXED =
+ ("<?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'></child>"
+ + "<x:child xmlns:x='urn:c' some_attr='b' anotherAttr='b'/>"
+ + "</parent>"
+ + "<c:parent some_attr='2' xmlns:c='urn:c'>"
+ + "<child some_attr='c' anotherAttr='c' xmlns='urn:c'></child>"
+ + "<c:child some_attr='d' anotherAttr='d'/>"
+ + "</c:parent>"
+ + "</grandparent>"
+ + "</g:greatgrandparent>").getBytes();
+
private static final String[] RESULTS_CHILD_WRAPPED = {
"<?xml version='1.0' encoding='UTF-8'?>"
+ "<g:greatgrandparent xmlns:g='urn:g'><grandparent><uncle/><aunt>emma</aunt>"
@@ -89,6 +103,28 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
+ "</c:parent></grandparent></g:greatgrandparent>"
};
+ private static final String[] RESULTS_CHILD_MIXED = {
+ "<child some_attr='a' anotherAttr='a' xmlns=\"urn:c\" xmlns:g=\"urn:g\" xmlns:c=\"urn:c\"></child>",
+ "<x:child xmlns:x='urn:c' some_attr='b' anotherAttr='b' xmlns='urn:c' xmlns:g='urn:g' xmlns:c='urn:c'/>",
+ "<child some_attr='c' anotherAttr='c' xmlns='urn:c' xmlns:g='urn:g' xmlns:c='urn:c'></child>",
+ "<c:child some_attr='d' anotherAttr='d' xmlns:g=\"urn:g\" xmlns:c=\"urn:c\"/>"
+ };
+
+ private static final String[] RESULTS_CHILD_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'></child></parent></grandparent></g:greatgrandparent>",
+ "<?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\">"
+ + "<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' xmlns='urn:c'></child></c: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'>"
+ + "<c:child some_attr='d' anotherAttr='d'/></c:parent></grandparent></g:greatgrandparent>"
+ };
+
private static final String[] RESULTS_CHILD = {
"<c:child some_attr='a' anotherAttr='a' xmlns:g=\"urn:g\" xmlns:d=\"urn:d\" xmlns:c=\"urn:c\"></c:child>",
"<c:child some_attr='b' anotherAttr='b' xmlns:g=\"urn:g\" xmlns:d=\"urn:d\" xmlns:c=\"urn:c\"/>",
@@ -147,7 +183,10 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
"<aunt xmlns:g=\"urn:g\">emma</aunt>",
"<aunt xmlns:g=\"urn:g\"/>"
};
-
+
+ private static final String[] RESULTS_NULL = {
+ };
+
private Map<String, String> nsmap;
private Exchange exchange;
@@ -170,6 +209,26 @@ public class XMLTokenExpressionIteratorTest extends TestCase {
invokeAndVerify("//C:child", false, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
}
+ public void testExtractChildNSMixed() throws Exception {
+ invokeAndVerify("//*:child", true, new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED_WRAPPED);
+ }
+
+ public void testExtractChildNSMixedInjected() throws Exception {
+ invokeAndVerify("//*:child", false, new ByteArrayInputStream(TEST_BODY_NS_MIXED), RESULTS_CHILD_MIXED);
+ }
+
+ public void testExtractAnyChild() throws Exception {
+ invokeAndVerify("//*:child", true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);
+ }
+
+ public void testExtractCxxxd() throws Exception {
+ invokeAndVerify("//C:c*d", false, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD);
+ }
+
+ public void testExtractUnqualifiedChild() throws Exception {
+ invokeAndVerify("//child", true, new ByteArrayInputStream(TEST_BODY), RESULTS_NULL);
+ }
+
public void testExtractChildWithAncestorGGPdGP() throws Exception {
invokeAndVerify("/G:greatgrandparent/grandparent//C:child",
true, new ByteArrayInputStream(TEST_BODY), RESULTS_CHILD_WRAPPED);