Velocity Tools





Velocity News Feed


GenericTools is the set of classes that provide basic infrastructure for using tools in standard Java SE Velocity projects, as well as a set of tools for use in generic Velocity templates. These tools have no Java EE dependencies and are often safe to use as "singletons". Some of them are not thread-safe to allow both a no-arg constructor and configurability, but the state-changing methods are declared protected with the exception of configure(Map) which is--by default--rendered useless after being used just once. If you require strict thread-safety, be cautious in using any configurable tools and consider restricting the abilities of template authors to prevent circumvention of the lockdown placed on configuration methods.

Default Configuration

The default configuration provided for GenericTools is here. It includes all of the tools listed below.


The dependencies required for GenericTools vary somewhat depending on which tools you use, whether you will rely on core tool management infrastructure, and if so, how you choose to configure your toolbox. More details can be found on the dependencies chart.


  • AlternatorTool - For creating Alternators to easily alternate over a set of values.
  • ClassTool - For simplifying reflective lookup of information about Classes and their fields, methods and constructors.
  • ContextTool - For convenient access to Context data and meta-data.
  • ConversionTool - For converting String values to richer object types.
  • DateTool & ComparisonDateTool - For manipulating, formatting, and comparing dates.
  • DisplayTool - For controlling display of references (e.g. truncating values, "pretty printing" lists, and displaying alternates when a reference is null).
  • EscapeTool - For common escaping needs in Velocity templates (e.g. escaping html, xml, javascript etc.).
  • FieldTool - For (easy) access to static fields in a class, such as string constants.
  • LoopTool - A convenience tool to use with #foreach loops. It wraps a list with a custom iterator to provide greater control, allowing loops to end early, skip ahead and more.
  • LinkTool - For creating and manipulating URIs and URLs. The API for this tool is designed to closely resemble that of the VelocityView tool of the same name.
  • ListTool - For working with arrays and lists, treats both transparently the same.
  • MathTool - For performing math functions.
  • NumberTool - For formatting and converting numbers.
  • RenderTool - To evaluate and render arbitrary strings of VTL, including recursive rendering.
  • ResourceTool - For simplified access to ResourceBundles for internationalization or other dynamic content needs.
  • SortTool - Used to sort collections (or arrays, iterators, etc) on any arbitary set of properties exposed by the objects contained within the collection.
  • XmlTool - For reading/navigating XML files. This uses dom4j under the covers and provides complete XPath support.