org.apache.velocity.tools.generic
Class ExtendedListTool

java.lang.Object
  extended byorg.apache.velocity.tools.generic.ListTool
      extended byorg.apache.velocity.tools.generic.ExtendedListTool

public class ExtendedListTool
extends ListTool

Tool for working with Lists and arrays in Velocity templates. In addition to the features ListTool provides, it provides the function to retrieve the length, and create clones of a list or an array object. Also provides a method to convert arrays into Lists and Lists into arrays.

 Example uses:
  $primes                  -> new int[] {2, 3, 5, 7}
  $list.length($primes)    -> 4
  $list.get($primes, 2)    -> 5
  $list.clone($primes)     -> int[] {2, 3, 5, 7}, != $primes
  $list.set($primes, 2, 1) -> (primes[2] becomes 1)
  $list.get($primes, 2)    -> 1
  $list.get($clone, 2)     -> 5
 

Example toolbox.xml config (if you want to use this with VelocityView): <tool> <key>list</key> <scope>application</scope> <class>org.apache.velocity.tools.generic.ExtendedListTool</class> </tool>

This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application).

Version:
$Id: ExtendedListTool.java,v 1.1 2005/08/31 14:39:34 czarneckid Exp $
Author:
Shinobu Kawai

Constructor Summary
ExtendedListTool()
          Default constructor.
 
Method Summary
 java.lang.Object clone(java.lang.Object list)
          Gets the clone of a List/array.
 java.lang.Integer length(java.lang.Object array)
          Gets the length of an array/List.
 java.lang.Object toArray(java.lang.Object list)
          Converts a List object into an array.
 java.util.List toList(java.lang.Object array)
          Converts an array object into a List.
 
Methods inherited from class org.apache.velocity.tools.generic.ListTool
contains, get, isArray, isEmpty, isList, set, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendedListTool

public ExtendedListTool()
Default constructor.

Method Detail

toList

public java.util.List toList(java.lang.Object array)
Converts an array object into a List.

Parameters:
array - an array object.
Returns:
the converted java.util.List.

toArray

public java.lang.Object toArray(java.lang.Object list)
Converts a List object into an array.

Parameters:
list - a List object.
Returns:
the converted array.

length

public java.lang.Integer length(java.lang.Object array)
Gets the length of an array/List. It will return null under the following conditions: The result will be same as the ListTool.size(Object) method.

Parameters:
array - the array object.
Returns:
the length of the array.
See Also:
ListTool.size(Object)

clone

public java.lang.Object clone(java.lang.Object list)
Gets the clone of a List/array. It will return null under the following conditions:

Parameters:
list - the List/array object.
Returns:
the clone of the List/array.