camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9207: Fixed test and issue when grouping xml tokenizer
Date Sun, 03 Jan 2016 10:20:11 GMT
Repository: camel
Updated Branches:
  refs/heads/master 23b653879 -> ef9e179a5


CAMEL-9207: Fixed test and issue when grouping xml tokenizer


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

Branch: refs/heads/master
Commit: ef9e179a54ee1f1181ea3262161435f39873cd75
Parents: 23b6538
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jan 3 11:19:58 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jan 3 11:19:58 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/builder/ExpressionBuilder.java    | 17 +++++++++++++++++
 .../camel/language/tokenizer/TokenizeLanguage.java |  8 +++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ef9e179a/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 e0ef026..f83554b 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
@@ -1339,6 +1339,23 @@ public final class ExpressionBuilder {
         };
     }
 
+    public static Expression groupXmlIteratorExpression(final Expression expression, final
int group) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                // evaluate expression as iterator
+                Iterator<?> it = expression.evaluate(exchange, Iterator.class);
+                ObjectHelper.notNull(it, "expression: " + expression + " evaluated on " +
exchange + " must return an java.util.Iterator");
+                // must use GroupTokenIterator in xml mode as we want to concat the xml parts
into a single message
+                return new GroupTokenIterator(exchange, it, null, group);
+            }
+
+            @Override
+            public String toString() {
+                return "group " + expression + " " + group + " times";
+            }
+        };
+    }
+
     public static Expression groupIteratorExpression(final Expression expression, final String
token, final int group) {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ef9e179a/camel-core/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java
b/camel-core/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java
index 24b177d..aa18750 100644
--- a/camel-core/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/tokenizer/TokenizeLanguage.java
@@ -124,9 +124,11 @@ public class TokenizeLanguage implements Language, IsSingleton {
 
         // if group then wrap answer in group expression
         if (group > 0) {
-            // only include group token if not xml
-            String groupToken = isXml() ? null : token;
-            answer = ExpressionBuilder.groupIteratorExpression(answer, groupToken, group);
+            if (isXml()) {
+                answer = ExpressionBuilder.groupXmlIteratorExpression(answer, group);
+            } else {
+                answer = ExpressionBuilder.groupIteratorExpression(answer, token, group);
+            }
         }
 
         return answer;


Mime
View raw message