camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1194910 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java main/java/org/apache/camel/support/TokenPairExpressionIterator.java test/java/org/apache/camel/processor/SplitTokenizerTest.java
Date Sat, 29 Oct 2011 15:53:29 GMT
Author: davsclaus
Date: Sat Oct 29 15:53:28 2011
New Revision: 1194910

URL: http://svn.apache.org/viewvc?rev=1194910&view=rev
Log:
CAMEL-4589: Polished

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java?rev=1194910&r1=1194909&r2=1194910&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java
Sat Oct 29 15:53:28 2011
@@ -18,7 +18,6 @@ package org.apache.camel.builder;
 
 import java.util.List;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.ErrorHandlerFactory;
 import org.apache.camel.Processor;
 import org.apache.camel.model.ModelCamelContext;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java?rev=1194910&r1=1194909&r2=1194910&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java
Sat Oct 29 15:53:28 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.support;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
 import java.util.Scanner;
@@ -64,7 +66,7 @@ public class TokenPairExpressionIterator
     /**
      * Iterator to walk the input stream
      */
-    private static final class TokenPairIterator implements Iterator {
+    private static final class TokenPairIterator implements Iterator, Closeable {
 
         private final String startToken;
         private final String endToken;
@@ -79,24 +81,23 @@ public class TokenPairExpressionIterator
             // this iterator will do look ahead as we may have data
             // after the last end token, which the scanner would find
             // so we need to be one step ahead of the scanner
-            this.image = hasNext() ? next() : null;
+            this.image = scanner.hasNext() ? next() : null;
         }
 
         @Override
         public boolean hasNext() {
-            // must look a head
-            boolean answer = scanner.hasNext();
-            if (!answer) {
-                scanner.close();
-            }
-            return answer;
+            return image != null;
         }
 
         @Override
         public Object next() {
             Object answer = image;
             // calculate next
-            image = hasNext() ? getNext() : null;
+            if (scanner.hasNext()) {
+                image = getNext();
+            } else {
+                image = null;
+            }
 
             if (answer == null) {
                 // first time the image may be null
@@ -111,13 +112,18 @@ public class TokenPairExpressionIterator
             // only grab text after the start token
             if (next != null && next.contains(startToken)) {
                 next = ObjectHelper.after(next, startToken);
-            }
 
-            // include tokens in answer
-            if (next != null) {
-                StringBuilder sb = new StringBuilder();
-                next = sb.append(startToken).append(next).append(endToken).toString();
+                // include tokens in answer
+                if (next != null) {
+                    StringBuilder sb = new StringBuilder();
+                    next = sb.append(startToken).append(next).append(endToken).toString();
+                }
+            } else {
+                // must have start token, otherwise we have reached beyond last tokens
+                // and should not return more data
+                return null;
             }
+
             return next;
         }
 
@@ -125,6 +131,11 @@ public class TokenPairExpressionIterator
         public void remove() {
             // noop
         }
+
+        @Override
+        public void close() throws IOException {
+            scanner.close();
+        }
     }
 
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerTest.java?rev=1194910&r1=1194909&r2=1194910&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitTokenizerTest.java
Sat Oct 29 15:53:28 2011
@@ -52,6 +52,25 @@ public class SplitTokenizerTest extends 
         assertMockEndpointsSatisfied();
     }
 
+    public void testSplitTokenizerD() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:split");
+        mock.expectedBodiesReceived("[Claus]", "[James]", "[Willem]");
+
+        template.sendBody("direct:d", "[Claus][James][Willem]");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testSplitTokenizerE() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:split");
+        mock.expectedBodiesReceived("<person>Claus</person>", "<person>James</person>",
"<person>Willem</person>");
+
+        String xml = "<persons><person>Claus</person><person>James</person><person>Willem</person></persons>";
+        template.sendBody("direct:e", xml);
+
+        assertMockEndpointsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -68,6 +87,14 @@ public class SplitTokenizerTest extends 
                 from("direct:c")
                     .split().tokenize("(\\W+)\\s*", null, true)
                         .to("mock:split");
+
+                from("direct:d")
+                    .split().tokenizePair("[", "]")
+                        .to("mock:split");
+
+                from("direct:e")
+                    .split().tokenizePair("<person>", "</person>")
+                        .to("mock:split");
             }
         };
     }



Mime
View raw message