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/06/10 20:37:10 UTC
svn commit: r666267 - in
/velocity/engine/trunk/src/java/org/apache/velocity/runtime:
RuntimeConstants.java defaults/velocity.properties directive/Foreach.java
Author: nbubna
Date: Tue Jun 10 11:37:10 2008
New Revision: 666267
URL: http://svn.apache.org/viewvc?rev=666267&view=rev
Log:
VELOCITY-600 - add $velocityHasNext during foreach loops (patch by Adrian Tarau)
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=666267&r1=666266&r2=666267&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java Tue Jun 10 11:37:10 2008
@@ -114,6 +114,9 @@
/** Counter reference name in #foreach directives. */
String COUNTER_NAME = "directive.foreach.counter.name";
+ /** Iterator.hasNext() reference name in #foreach directives. */
+ String HAS_NEXT_NAME = "directive.foreach.iterator.name";
+
/** Initial counter value in #foreach directives. */
String COUNTER_INITIAL_VALUE = "directive.foreach.counter.initial.value";
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties?rev=666267&r1=666266&r2=666267&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties Tue Jun 10 11:37:10 2008
@@ -48,15 +48,17 @@
# F O R E A C H P R O P E R T I E S
# ----------------------------------------------------------------------------
# These properties control how the counter is accessed in the #foreach
-# directive. By default the reference $velocityCount will be available
-# in the body of the #foreach directive. The default starting value
-# for this reference is 1.
+# directive. By default the reference $velocityCount and $velocityHasNext
+# will be available in the body of the #foreach directive.
+# The default starting value for $velocityCount is 1.
# ----------------------------------------------------------------------------
directive.foreach.counter.name = velocityCount
directive.foreach.counter.initial.value = 1
directive.foreach.maxloops = -1
+directive.foreach.iterator.name = velocityHasNext
+
# ----------------------------------------------------------------------------
# S E T P R O P E R T I E S
# ----------------------------------------------------------------------------
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=666267&r1=666266&r2=666267&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 Tue Jun 10 11:37:10 2008
@@ -301,6 +301,13 @@
private String counterName;
/**
+ * The name of the variable to use when placing
+ * iterator hasNext() value into the context.Right
+ * now the defailt is $velocityHasNext
+ */
+ private String hasNextName;
+
+ /**
* What value to start the loop counter at.
*/
private int counterInitialValue;
@@ -341,6 +348,7 @@
super.init(rs, context, node);
counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
+ hasNextName = rsvc.getString(RuntimeConstants.HAS_NEXT_NAME);
counterInitialValue = rsvc.getInt(RuntimeConstants.COUNTER_INITIAL_VALUE);
maxNbrLoops = rsvc.getInt(RuntimeConstants.MAX_NUMBER_LOOPS,
Integer.MAX_VALUE);
@@ -445,6 +453,7 @@
{
// TODO: JDK 1.4+ -> valueOf()
context.localPut(counterName , new Integer(counter));
+ context.localPut(hasNextName, Boolean.valueOf(i.hasNext()));
Object value = i.next();
context.localPut(elementKey, value);