Author: lgawron
Date: Fri May  6 14:52:29 2005
New Revision: 168667

URL: http://svn.apache.org/viewcvs?rev=168667&view=rev
Log:
fixed backward incompatibility with old JXTG
added another test case for jx:forEach

Modified:
    
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
    
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java
    
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach-output.xml
    
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach.xml

Modified: 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java?rev=168667&r1=168666&r2=168667&view=diff
==============================================================================
--- 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
 (original)
+++ 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
 Fri May  6 14:52:29 2005
@@ -58,7 +58,7 @@
     public static JXTExpression compileBoolean(String val, String msg,
                                                Locator location) throws 
SAXException {
         JXTExpression res = compileExpr(val, msg, location);
-        if (res.getCompiledExpression() == null && res.getRaw() != null) {
+        if (res != null && res.getCompiledExpression() == null && res.getRaw() 
!= null) {
             res.setCompiledExpression(Boolean.valueOf(res.getRaw()));
         }
         return res;
@@ -71,7 +71,7 @@
     public static JXTExpression compileInt(String val, String msg,
             Locator location) throws SAXException {
         JXTExpression res = compileExpr(val, msg, location);
-        if (res.getCompiledExpression() == null && res.getRaw() != null) {
+        if (res != null && res.getCompiledExpression() == null && res.getRaw() 
!= null) {
             res.setCompiledExpression(Integer.valueOf(res.getRaw()));
         }
         return res;
@@ -80,7 +80,7 @@
     public static JXTExpression compileExpr(String inStr) throws Exception {
         try {
             if (inStr == null) {
-                return new JXTExpression(null, null);
+                return null;
             }
             StringReader in = new StringReader(inStr.trim());
             int ch;
@@ -257,7 +257,7 @@
             
((Expression)this.compiledExpression).setProperty(JXPathExpression.LENIENT, 
lenient);
     }
 
-    private static final Iterator EMPTY_ITER = new Iterator() {
+    public static final Iterator EMPTY_ITER = new Iterator() {
         public boolean hasNext() {
             return false;
         }
@@ -271,7 +271,7 @@
         }
     };
 
-    private static final Iterator NULL_ITER = new Iterator() {
+    static public final Iterator NULL_ITER = new Iterator() {
         public boolean hasNext() {
             return true;
         }

Modified: 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java?rev=168667&r1=168666&r2=168667&view=diff
==============================================================================
--- 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java
 (original)
+++ 
cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java
 Fri May  6 14:52:29 2005
@@ -72,6 +72,7 @@
             throw new SAXParseException("forEach: only one of \"select\" or 
\"items\" may be specified",
                                         locator, null);
         }
+        
         this.items = JXTExpression.compileExpr(items == null ? select : items, 
null, locator);
     }
 
@@ -81,9 +82,11 @@
         throws SAXException {
         Iterator iter = null;
         int begin, end, step;
-        String var, varStatus;
+        String var = null, varStatus = null;
         try {
-            iter = this.items.getIterator(expressionContext);
+            iter = (this.items != null ) 
+                    ? this.items.getIterator(expressionContext)
+                    : JXTExpression.NULL_ITER;
             begin = this.begin == null
                 ? 0
                 : this.begin.getIntValue(expressionContext);
@@ -93,13 +96,12 @@
             step = this.step == null
                 ? 1
                 : this.step.getIntValue(expressionContext);
+
+            if ( this.var != null )
+                var = this.var.getStringValue(expressionContext);
             
-            // FIXME: why is this needed?
-            if ( step == 0 )
-                step = 1;
-            
-            var = this.var.getStringValue(expressionContext);
-            varStatus = this.varStatus.getStringValue(expressionContext);
+            if ( this.varStatus != null )
+                varStatus = this.varStatus.getStringValue(expressionContext);
         } catch (Exception exc) {
             throw new SAXParseException(exc.getMessage(),
                                         getLocation(), exc);

Modified: 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach-output.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach-output.xml?rev=168667&r1=168666&r2=168667&view=diff
==============================================================================
--- 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach-output.xml
 (original)
+++ 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach-output.xml
 Fri May  6 14:52:29 2005
@@ -4,4 +4,12 @@
   <forEach>one</forEach>
   <forEach>two</forEach>
   <forEach>three</forEach>
+
+  <loop>
+      <forEach>1</forEach>
+      <forEach>2</forEach>
+      <forEach>3</forEach>
+      <forEach>4</forEach>
+      <forEach>5</forEach>
+  </loop>
 </root>

Modified: 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach.xml?rev=168667&r1=168666&r2=168667&view=diff
==============================================================================
--- 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach.xml
 (original)
+++ 
cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/jxForEach.xml
 Fri May  6 14:52:29 2005
@@ -4,4 +4,10 @@
   <jx:forEach var="i" items="${test}">
     <forEach>${i}</forEach>
   </jx:forEach>
+  
+  <loop>
+    <jx:forEach varStatus="status" begin="1" end="5">
+      <forEach>${status.index}</forEach>
+    </jx:forEach>
+  </loop>
 </root>


Reply via email to