I did this yesterday :) Is there something wrong with it?
(Thatnks, though.)
geir
Tim Joyce wrote:
>
> Geir,
>
> > > I would like to be able to #foreach through an Enumeration. Is anyone
> > > receptive to this being added to Velocity?
> >
> > Yep. Should be straightforward. :)
>
> please find attached a new class
> org.apache.velocity.util.EnumerationIterator
>
> also, here is a diff for Foreach.java:
>
> diff Foreach.java Foreach.java.old
> 71d70
> < import org.apache.velocity.util.EnumerationIterator;
> 133,138d131
> <
> < /**
> < * Flag to indicate that the list object being used
> < * is an Enumeration.
> < */
> < private final static int INFO_ENUMERATION = 5;
> 240,241d232
> < else if ( listObject instanceof Enumeration )
> < type = INFO_ENUMERATION;
> 265c256
> < case INFO_ITERATOR :
> ---
> > case INFO_ITERATOR :
> 273d263
> < return ( (Iterator) listObject);
> 275,283c265
> < case INFO_ENUMERATION :
> < Runtime.warn ("Warning! The reference "
> < + node.jjtGetChild(2).getFirstToken().image
> < + " is an Enumeration in the #foreach() loop at
> ["
> < + getLine() + "," + getColumn() + "]"
> < + " in template " +
> context.getCurrentTemplateName()
>
> < + ". If used in more than once, this may lead to
> "
> < + "unexpected results.");
> < return ( new EnumerationIterator( (Enumeration) listObject));
>
> ---
> > return ( (Iterator) listObject);
>
> ------------------------------------------------------------------------
> Name: EnumerationIterator.java
> EnumerationIterator.java Type: unspecified type (application/octet-stream)
> Encoding: quoted-printable
--
Geir Magnusson Jr. [EMAIL PROTECTED]
Developing for the web? See http://jakarta.apache.org/velocity/