You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/10/16 19:12:08 UTC

svn commit: r705288 - in /velocity/engine/trunk: src/java/org/apache/velocity/runtime/directive/ src/test/org/apache/velocity/test/issues/ test/issues/velocity-285/

Author: nbubna
Date: Thu Oct 16 10:12:07 2008
New Revision: 705288

URL: http://svn.apache.org/viewvc?rev=705288&view=rev
Log:
VELOCITY-630 revert errant change for VELOCITY-285 but make that behavior easy to replicate with a Foreach subclass

Added:
    velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java   (with props)
Removed:
    velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity285TestCase.java
    velocity/engine/trunk/test/issues/velocity-285/
Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=705288&r1=705287&r2=705288&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java Thu Oct 16 10:12:07 2008
@@ -247,6 +247,17 @@
     }
 
     /**
+     * Extension hook to allow subclasses to control whether loop vars
+     * are set locally or not. So, those in favor of VELOCITY-285, can
+     * make that happen easily by overriding this and having it use
+     * context.localPut(k,v). See VELOCITY-630 for more on this.
+     */
+    protected void put(InternalContextAdapter context, String key, Object value)
+    {
+        context.put(key, value);
+    }
+
+    /**
      *  renders the #foreach() block
      * @param context
      * @param writer
@@ -325,11 +336,11 @@
 
         while (!maxNbrLoopsExceeded && i.hasNext())
         {
-            // TODO: JDK 1.4+ -> Integer.valueOf()
-            context.localPut(counterName , new Integer(counter));
-            context.localPut(hasNextName, Boolean.valueOf(i.hasNext()));
+            // TODO: JDK 1.5+ -> Integer.valueOf()
+            put(context, counterName , new Integer(counter));
+            put(context, hasNextName, Boolean.valueOf(i.hasNext()));
             Object value = i.next();
-            context.localPut(elementKey, value);
+            put(context, elementKey, value);
 
             try
             {

Added: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java?rev=705288&view=auto
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java (added)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java Thu Oct 16 10:12:07 2008
@@ -0,0 +1,52 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * 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.    
+ */
+
+import org.apache.velocity.test.BaseEvalTestCase;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+/**
+ * This class tests VELOCITY-630.
+ */
+public class Velocity630TestCase extends BaseEvalTestCase
+{
+    public Velocity630TestCase(String name)
+    {
+        super(name);
+        DEBUG = false;
+    }
+
+    public void test630()
+    {
+        // this template is logically equivalent to the demo in VELOCITY-630
+        String template = "#macro( test $a )" +
+                            "#foreach( $i in [1..3] )" +
+                                "$a" +
+                            "#end" +
+                          "#end" +
+                          "#test( \"#if($i == 2)" +
+                                        " yes" +
+                                   "#else" +
+                                        " no" +
+                                   "#end\" )";
+        assertEvalEquals(" no yes no", template);
+    }
+
+}

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision

Propchange: velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity630TestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain