org.apache.velocity.tools.generic
Class AlternatorTool

java.lang.Object
  extended by org.apache.velocity.tools.generic.AlternatorTool

public class AlternatorTool
extends java.lang.Object

Simple tool to provide easy in-template instantiation of Alternators 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. I dig $style.next numbers.
 #end *

 output...
   Number 1 is red and hip. I dig hip numbers.
   Number 2 is blue and fly. I dig fly numbers.
   Number 3 is red and groovy. I dig groovy numbers.
   Number 4 is blue and hip. I dig hip numbers.
   Number 5 is red and fly. I dig fly numbers.
 

Since:
Velocity Tools 1.2
Version:
$Revision: 484710 $ $Date: 2006-12-08 11:40:42 -0800 (Fri, 08 Dec 2006) $

Field Summary
static java.lang.String AUTO_ALTERNATE_DEFAULT_KEY
           
private  boolean autoAlternateDefault
           
 
Constructor Summary
AlternatorTool()
           
 
Method Summary
 Alternator auto(java.util.List list)
          Make an automatic Alternator from values in the specified List.
 Alternator auto(java.lang.Object[] array)
          Make an automatic Alternator from the specified object array.
 Alternator auto(java.lang.Object o1, java.lang.Object o2)
          Make an automatic Alternator from a list containing the two specified objects.
 void configure(java.util.Map params)
          Looks for a default auto-alternate value in the given params, if not, set the default to true.
 boolean getAutoAlternateDefault()
          Returns true if the default for auto-alternating is true.
 Alternator make(boolean auto, java.util.List list)
          Deprecated. Use auto(List list) or manual(List list) instead.
 Alternator make(boolean auto, java.lang.Object[] array)
          Deprecated. Use auto(Object[] array) or manual(Object[] array) instead.
 Alternator make(boolean auto, java.lang.Object o1, java.lang.Object o2)
          Deprecated. Use auto(Object o1, Object o2) or manual(Object o1, Object o2) instead.
 Alternator make(java.util.List list)
          Make an automatic Alternator from a List.
 Alternator make(java.lang.Object[] array)
          Make an automatic Alternator from an object array.
 Alternator make(java.lang.Object o1, java.lang.Object o2)
          Make an automatic Alternator from a list containing the two specified objects.
 Alternator manual(java.util.List list)
          Make a manual Alternator from values in the specified List.
 Alternator manual(java.lang.Object[] array)
          Make a manual Alternator from the specified object array.
 Alternator manual(java.lang.Object o1, java.lang.Object o2)
          Make a manual Alternator from a list containing the two specified objects.
protected  void setAutoAlternateDefault(boolean bool)
          Sets the default for auto-alternating.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO_ALTERNATE_DEFAULT_KEY

public static final java.lang.String AUTO_ALTERNATE_DEFAULT_KEY
Since:
VelocityTools 1.3
See Also:
Constant Field Values

autoAlternateDefault

private boolean autoAlternateDefault
Constructor Detail

AlternatorTool

public AlternatorTool()
Method Detail

configure

public void configure(java.util.Map params)
Looks for a default auto-alternate value in the given params, if not, set the default to true.

Since:
VelocityTools 1.3

getAutoAlternateDefault

public boolean getAutoAlternateDefault()
Returns true if the default for auto-alternating is true.

Since:
VelocityTools 1.3

setAutoAlternateDefault

protected void setAutoAlternateDefault(boolean bool)
Sets the default for auto-alternating.

Since:
VelocityTools 1.3

make

public Alternator make(java.util.List list)
Make an automatic Alternator from a List.


make

public Alternator make(boolean auto,
                       java.util.List list)
Deprecated. Use auto(List list) or manual(List list) instead.


make

public Alternator make(java.lang.Object[] array)
Make an automatic Alternator from an object array.


make

public Alternator make(boolean auto,
                       java.lang.Object[] array)
Deprecated. Use auto(Object[] array) or manual(Object[] array) instead.


make

public Alternator make(java.lang.Object o1,
                       java.lang.Object o2)
Make an automatic Alternator from a list containing the two specified objects.

Returns:
The new Alternator, or null if arguments were illegal.

make

public Alternator make(boolean auto,
                       java.lang.Object o1,
                       java.lang.Object o2)
Deprecated. Use auto(Object o1, Object o2) or manual(Object o1, Object o2) instead.


auto

public Alternator auto(java.util.List list)
Make an automatic Alternator from values in the specified List.

Returns:
a new, automatic Alternator with the values in the List or null if the List is null.
Since:
VelocityTools 1.3

auto

public Alternator auto(java.lang.Object[] array)
Make an automatic Alternator from the specified object array.

Returns:
a new, automatic Alternator with the values in the array or null if the array is null.
Since:
VelocityTools 1.3

auto

public Alternator auto(java.lang.Object o1,
                       java.lang.Object o2)
Make an automatic Alternator from a list containing the two specified objects.

Parameters:
o1 - The first of two objects for alternation between. Must be non-null.
o2 - The second of two objects for alternation between. Must be non-null.
Returns:
The new Alternator, or null if an argument was null.
Since:
VelocityTools 1.3

manual

public Alternator manual(java.util.List list)
Make a manual Alternator from values in the specified List.

Returns:
a new, manual Alternator with the values in the List or null if the List is null.
Since:
VelocityTools 1.3

manual

public Alternator manual(java.lang.Object[] array)
Make a manual Alternator from the specified object array.

Returns:
a new, manual Alternator with the values in the array or null if the array is null.
Since:
VelocityTools 1.3

manual

public Alternator manual(java.lang.Object o1,
                         java.lang.Object o2)
Make a manual Alternator from a list containing the two specified objects.

Parameters:
o1 - The first of two objects for alternation between. Must be non-null.
o2 - The second of two objects for alternation between. Must be non-null.
Returns:
The new Alternator, or null if an argument was null.
Since:
VelocityTools 1.3


Copyright (c) 2003-2007 Apache Software Foundation