org.apache.velocity.runtime.directive

Class Foreach

Implemented Interfaces:
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.42.4.1 2004/03/03 23:22:55 geirm Exp $
Authors:
Jason van Zyl
Geir Magnusson Jr.

Field Summary

private int
counterInitialValue
What value to start the loop counter at.
private String
counterName
The name of the variable to use when placing the counter value into the context.
private String
elementKey
The reference name used to access each of the elements in the list object.
protected Info
uberInfo
immutable, so create in init

Fields inherited from class org.apache.velocity.runtime.directive.Directive

column, line, rsvc

Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants

BLOCK, LINE

Method Summary

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, Writer writer, Node node)
renders the #foreach() block

Methods inherited from class org.apache.velocity.runtime.directive.Directive

getColumn, getLine, getName, getType, init, render, setLocation

Field Details

counterInitialValue

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

counterName

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

elementKey

private 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.

uberInfo

protected Info uberInfo
immutable, so create in init

Method Details

getName

public String getName()
Return name of this directive.
Overrides:
getName in interface Directive

getType

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

init

public void init(RuntimeServices rs,
                 InternalContextAdapter context,
                 Node node)
            throws Exception
simple init - init the tree and get the elementKey from the AST
Overrides:
init in interface Directive

render

public boolean render(InternalContextAdapter context,
                      Writer writer,
                      Node node)
            throws IOException,
                   MethodInvocationException,
                   ResourceNotFoundException,
                   ParseErrorException
renders the #foreach() block
Overrides:
render in interface Directive

Copyright B) 2002 Apache Software Foundation. All Rights Reserved.