cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r568847 - /cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java
Date Thu, 23 Aug 2007 06:47:23 GMT
Author: cziegeler
Date: Wed Aug 22 23:47:22 2007
New Revision: 568847

URL: http://svn.apache.org/viewvc?rev=568847&view=rev
Log:
Fixing ForEach by going back to NULL_ITER.

Modified:
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java?rev=568847&r1=568846&r2=568847&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ForEach.java
Wed Aug 22 23:47:22 2007
@@ -40,6 +40,20 @@
  */
 public class ForEach extends Instruction {
 
+    protected static final Iterator NULL_ITER = new Iterator() {
+        public boolean hasNext() {
+            return true;
+        }
+
+        public Object next() {
+            return null;
+        }
+
+        public void remove() {
+            // EMPTY
+        }
+    };
+
     private final Subst items;
     private final Subst var;
     private final Subst varStatus;
@@ -88,7 +102,7 @@
         try {
             iter = (this.items != null )
                     ? this.items.getIterator(objectModel)
-                    : null;
+                    : NULL_ITER;
             begin = this.begin == null
                 ? 0
                 : this.begin.getIntValue(objectModel);
@@ -114,13 +128,9 @@
         objectModel.markLocalContext();
         int i = 0;
         // Move to the begin row
-        if ( iter == null ) {
+        while (i < begin && iter.hasNext()) {
+            iter.next();
             i++;
-        } else {
-            while (i < begin && iter.hasNext()) {
-                iter.next();
-                i++;
-            }
         }
         LoopTagStatus status = null;
         if (varStatus != null) {
@@ -132,7 +142,7 @@
             objectModel.put(varStatus, status);
         }
         int skipCounter, count = 1;
-        while (i <= end && iter != null && iter.hasNext()) {
+        while (i <= end && iter.hasNext()) {
             objectModel.markLocalContext();
             Object value = iter.next();
             objectModel.put(ObjectModel.CONTEXTBEAN, value);



Mime
View raw message