org.apache.velocity.tools.generic |
Contains a collection of reusable, general-purpose "tools" for Velocity.
These tools are independent of the VelocityView classes and may be used
in any context.
Package Specification
Related Documentation
|
Java Source File Name | Type | Comment |
Alternator.java | Class | Utility class for easily alternating over values in a list. |
AlternatorTool.java | Class | Simple tool to provide easy in-template instantiation of
Alternator s from varying "list" types.
Example Use:
toolbox.xml...
<tool>
<key>alternator</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.AlternatorTool</class>
<parameter name="auto-alternate" value="true"/>
</tool>
template...
#set( $color = $alternator.auto('red', 'blue') )
## use manual alternation for this one
#set( $style = $alternator.manual(['hip','fly','groovy']) )
#foreach( $i in [1..5] )
Number $i is $color and $style. |
DateTool.java | Class | Tool for working with
Date and
Calendar in Velocity templates. |
EscapeTool.java | Class | Tool for working with escaping in Velocity templates. |
IteratorTool.java | Class |
A convenience tool to use with #foreach loops. |
ListTool.java | Class | Tool for working with Lists and arrays in Velocity templates. |
MathTool.java | Class | Tool for performing math in Velocity.
Some things should be noted here:
- This class does not have methods that take
primitives.
|
NumberTool.java | Class | Tool for working with
Number in Velocity templates.
It is useful for accessing and
formatting arbitrary
Number objects. |
RenderTool.java | Class | This tool exposes methods to evaluate the given
strings as VTL (Velocity Template Language)
using the given context.
NOTE: These examples assume you have placed an
instance of the current context within itself
as 'ctx'. |
ResourceTool.java | Class | Tool for accessing ResourceBundles and formatting messages therein.
Template example(s):
$text.foo -> bar
$text.hello.world -> Hello World!
#set( $otherText = $text.bundle('otherBundle') )
$otherText.foo -> woogie
$otherText.bar -> The args are {0} and {1}.
$otherText.bar.insert(4) -> The args are 4 and {1}.
$otherText.bar.insert(4,true) -> The args are 4 and true.
Toolbox configuration example:
<tool>
<key>text</key>
<class>org.apache.velocity.tools.generic.ResourceTool</class>
<parameter name="bundles" value="resources,com.foo.moreResources"/>
<parameter name="locale" value="en_US"/>
</tool>
This comes in very handy when internationalizing templates.
Note that the default resource bundle baseName is "resources", and
the default locale is the system locale. |
SortTool.java | Class | SortTool allows a user to sort a collection (or array, iterator, etc)
on any arbitary set of properties exposed by the objects contained
within the collection.
The sort tool is specifically designed to use within a #foreach
but you may find other uses for it.
The sort tool can handle all of the collection types supported by
#foreach and the same constraints apply as well as the following.
Every object in the collection must support the set of properties
selected to sort on. |
ValueParser.java | Class | |