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.35 2001/03/20 01:11:22 jon Exp $
Author:
Jason van Zyl, Geir Magnusson Jr.

Field Summary
private static int COUNTER_INITIAL_VALUE
          What value to start the loop counter at.
private static java.lang.String COUNTER_NAME
          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_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
column, line
 
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(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, registerNatives, toString, wait, wait, wait
 

Field Detail

UNKNOWN

private static final int UNKNOWN

INFO_ARRAY

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

INFO_ITERATOR

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

INFO_MAP

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

INFO_COLLECTION

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

COUNTER_NAME

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

COUNTER_INITIAL_VALUE

private static final int COUNTER_INITIAL_VALUE
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.
Overrides:
getName in class Directive

getType

public int getType()
Return type of this directive.
Overrides:
getType in class Directive

init

public void init(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

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

render

public boolean render(InternalContextAdapter context,
                      java.io.Writer writer,
                      Node node)
               throws java.io.IOException,
                      MethodInvocationException
renders the #foreach() block
Overrides:
render in class Directive


Copyright © 2001 Apache Software Foundation. All Rights Reserved.