org.apache.velocity.runtime.directive
Class Foreach

java.lang.Object
  |
  +--org.apache.velocity.runtime.directive.Directive
        |
        +--org.apache.velocity.runtime.directive.Foreach
All Implemented Interfaces:
java.lang.Cloneable, DirectiveConstants

public class Foreach
extends Directive

Foreach directive used for moving through arrays, or objects that provide an Iterator.

Version:
$Id: Foreach.java,v 1.40 2001/10/24 03:06:17 geirm Exp $
Author:
Jason van Zyl, Geir Magnusson Jr.

Field Summary
private  int counterInitialValue
          What value to start the loop counter at.
private  java.lang.String counterName
          The name of the variable to use when placing the counter value into the context.
private  java.lang.String elementKey
          The reference name used to access each of the elements in the list object.
private static int INFO_ARRAY
          Flag to indicate that the list object being used in an array.
private static int INFO_COLLECTION
          Flag to indicate that the list object being used is a Collection.
private static int INFO_ENUMERATION
          Flag to indicate that the list object being used is an Enumeration
private static int INFO_ITERATOR
          Flag to indicate that the list object being used provides an Iterator.
private static int INFO_MAP
          Flag to indicate that the list object being used is a Map.
private static int UNKNOWN
           
 
Fields inherited from class org.apache.velocity.runtime.directive.Directive
rsvc
 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
 
Constructor Summary
Foreach()
           
 
Method Summary
private  java.util.Iterator getIterator(InternalContextAdapter context, Node node)
          returns an Iterator to the collection in the #foreach()
 java.lang.String getName()
          Return name of this directive.
 int getType()
          Return type of this directive.
 void init(RuntimeServices rs, InternalContextAdapter context, Node node)
          simple init - init the tree and get the elementKey from the AST
 boolean render(InternalContextAdapter context, java.io.Writer writer, Node node)
          renders the #foreach() block
 
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

private static final int UNKNOWN
See Also:
Constant Field Values

INFO_ARRAY

private static final int INFO_ARRAY
Flag to indicate that the list object being used in an array.

See Also:
Constant Field Values

INFO_ITERATOR

private static final int INFO_ITERATOR
Flag to indicate that the list object being used provides an Iterator.

See Also:
Constant Field Values

INFO_MAP

private static final int INFO_MAP
Flag to indicate that the list object being used is a Map.

See Also:
Constant Field Values

INFO_COLLECTION

private static final int INFO_COLLECTION
Flag to indicate that the list object being used is a Collection.

See Also:
Constant Field Values

INFO_ENUMERATION

private static final int INFO_ENUMERATION
Flag to indicate that the list object being used is an Enumeration

See Also:
Constant Field Values

counterName

private java.lang.String counterName
The name of the variable to use when placing the counter value into the context. Right now the default is $velocityCount.


counterInitialValue

private int counterInitialValue
What value to start the loop counter at.


elementKey

private java.lang.String elementKey
The reference name used to access each of the elements in the list object. It is the $item in the following: #foreach ($item in $list) This can be used class wide because it is immutable.

Constructor Detail

Foreach

public Foreach()
Method Detail

getName

public java.lang.String getName()
Return name of this directive.

Specified by:
getName in class Directive

getType

public int getType()
Return type of this directive.

Specified by:
getType in class Directive

init

public void init(RuntimeServices rs,
                 InternalContextAdapter context,
                 Node node)
          throws java.lang.Exception
simple init - init the tree and get the elementKey from the AST

Overrides:
init in class Directive
java.lang.Exception

getIterator

private java.util.Iterator getIterator(InternalContextAdapter context,
                                       Node node)
                                throws MethodInvocationException
returns an Iterator to the collection in the #foreach()

Parameters:
context - current context
node - AST node
Returns:
Iterator to do the dataset
MethodInvocationException

render

public boolean render(InternalContextAdapter context,
                      java.io.Writer writer,
                      Node node)
               throws java.io.IOException,
                      MethodInvocationException,
                      ResourceNotFoundException,
                      ParseErrorException
renders the #foreach() block

Specified by:
render in class Directive
java.io.IOException
MethodInvocationException
ResourceNotFoundException
ParseErrorException


Copyright ? 2003 Apache Software Foundation. All Rights Reserved.