Class AlternatorTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.AlternatorTool
-
@DefaultKey("alternator") public class AlternatorTool extends SafeConfig
Simple tool to provide easy in-template instantiation ofAlternators from varying "list" types or individual arguments.Example Use:
tools.xml... <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.AlternatorTool"/> </toolbox> </tools> 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$ $Date$
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTO_ALTERNATE_DEFAULT_KEYstatic StringOLD_AUTO_ALTERNATE_DEFAULT_KEYDeprecated.-
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY
-
-
Constructor Summary
Constructors Constructor Description AlternatorTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Alternatorauto(Object... list)Make an automaticAlternatorfrom the specified objects.Alternatorauto(Object o1, Object o2)Deprecated.Will be unnecessary with Velocity 1.6Alternatorauto(Collection list)Deprecated.Will be unnecessary with Velocity 1.6protected voidconfigure(ValueParser parser)Looks for a default auto-alternate value in the given params, if not, set the default to true.booleangetAutoAlternateDefault()Returns true if the default for auto-alternating is true.Alternatormake(boolean auto, Object... list)Returns a new Alternator for the specified list with the specified automatic shifting preference.Alternatormake(boolean auto, Object o1, Object o2)Deprecated.Will be unnecessary with Velocity 1.6Alternatormake(boolean auto, Collection list)Deprecated.Will be unnecessary with Velocity 1.6Alternatormake(Object... list)Make an automaticAlternatorfrom the specifed objects.Alternatormake(Object o1, Object o2)Deprecated.Will be unnecessary with Velocity 1.6Alternatormake(Collection list)Deprecated.Will be unnecessary with Velocity 1.6Alternatormanual(Object... list)Make a manualAlternatorfrom the specified objects.Alternatormanual(Object o1, Object o2)Deprecated.Will be unnecessary with Velocity 1.6Alternatormanual(Collection list)Deprecated.Will be unnecessary with Velocity 1.6protected voidsetAutoAlternateDefault(boolean bool)Sets the default for auto-alternating.-
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
-
-
-
Field Detail
-
OLD_AUTO_ALTERNATE_DEFAULT_KEY
@Deprecated public static final String OLD_AUTO_ALTERNATE_DEFAULT_KEY
Deprecated.- See Also:
- Constant Field Values
-
AUTO_ALTERNATE_DEFAULT_KEY
public static final String AUTO_ALTERNATE_DEFAULT_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
protected void configure(ValueParser parser)
Looks for a default auto-alternate value in the given params, if not, set the default to true.- Overrides:
configurein classSafeConfig
-
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(Object... list)
Make an automaticAlternatorfrom the specifed objects.
-
make
@Deprecated public Alternator make(Collection list)
Deprecated.Will be unnecessary with Velocity 1.6
-
make
public Alternator make(boolean auto, Object... list)
Returns a new Alternator for the specified list with the specified automatic shifting preference.- Parameters:
auto- SeeAlternator.setAuto(boolean auto).list- The list of elements to alternate.
-
make
@Deprecated public Alternator make(boolean auto, Collection list)
Deprecated.Will be unnecessary with Velocity 1.6
-
make
@Deprecated public Alternator make(Object o1, Object o2)
Deprecated.Will be unnecessary with Velocity 1.6
-
make
@Deprecated public Alternator make(boolean auto, Object o1, Object o2)
Deprecated.Will be unnecessary with Velocity 1.6
-
auto
public Alternator auto(Object... list)
Make an automaticAlternatorfrom the specified objects.- Returns:
- a new, automatic Alternator with the specified values or
nullif there are none specified. - Since:
- VelocityTools 1.3
-
auto
@Deprecated public Alternator auto(Collection list)
Deprecated.Will be unnecessary with Velocity 1.6
-
auto
@Deprecated public Alternator auto(Object o1, Object o2)
Deprecated.Will be unnecessary with Velocity 1.6
-
manual
public Alternator manual(Object... list)
Make a manualAlternatorfrom the specified objects.- Returns:
- a new, manual Alternator with the values in the array or
nullif the array isnull. - Since:
- VelocityTools 1.3
-
manual
@Deprecated public Alternator manual(Collection list)
Deprecated.Will be unnecessary with Velocity 1.6
-
manual
@Deprecated public Alternator manual(Object o1, Object o2)
Deprecated.Will be unnecessary with Velocity 1.6
-
-