org.webmacro.directive
Class AlternateDirective

java.lang.Object
  extended byorg.webmacro.directive.Directive
      extended byorg.webmacro.directive.AlternateDirective
All Implemented Interfaces:
Macro, Visitable

public class AlternateDirective
extends Directive

#alternate

Use the #alternate directive to create an "alternating" variable, which is useful for creating tables that use a different background color for each line, etc.

 Syntax:
   #alternate var-reference through expression
 Example:
   #alternate $color through [ "red", "blue", "green" ]
   #foreach $row in $rows {
      ... blah blah ...
   }
 

expression can be any "list" type understood by WebMacro: Object[], java.util.List, java.util.Iterator, java.util.Enumeration, or any other object that has either of the following method signatures:

    public Iterator iterator ();
           or
    public Enumeration elements ();
 

The first time $color is evaluated, it will have the value "red". The next time it is evaluated, it will have the value "blue", and so on through the list. When it gets to the end of the list, it wraps back around to the beginning.


Nested Class Summary
 
Nested classes inherited from class org.webmacro.directive.Directive
Directive.ArgDescriptor, Directive.AssignmentArg, Directive.BlockArg, Directive.ConditionArg, Directive.ExactlyOneChoice, Directive.FormalArgListArg, Directive.KeywordArg, Directive.LiteralBlockArg, Directive.LValueArg, Directive.NameArg, Directive.NotSimpleVariableBuildException, Directive.NotVariableBuildException, Directive.OptionalGroup, Directive.OptionalRepeatingSubdirective, Directive.OptionalSubdirective, Directive.OptionChoice, Directive.QuotedStringArg, Directive.RValueArg, Directive.SingleOptionChoice, Directive.StringArg, Directive.Subdirective
 
Field Summary
 
Fields inherited from class org.webmacro.directive.Directive
ArgType_ARGLIST, ArgType_ASSIGN, ArgType_BLOCK, ArgType_CHOICE, ArgType_CONDITION, ArgType_GROUP, ArgType_KEYWORD, ArgType_LITBLOCK, ArgType_LVALUE, ArgType_NAME, ArgType_QUOTEDSTRING, ArgType_RVALUE, ArgType_STRING, ArgType_SUBDIRECTIVE
 
Constructor Summary
AlternateDirective()
           
 
Method Summary
 void accept(TemplateVisitor v)
           
 java.lang.Object build(DirectiveBuilder builder, BuildContext bc)
          Directives must implement a build() method.
static DirectiveDescriptor getDescriptor()
           
 void write(FastWriter out, Context context)
          Interpret the directive and write it out, using the values in the supplied context as appropriate.
 
Methods inherited from class org.webmacro.directive.Directive
evaluate, getWarningText, writeWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlternateDirective

public AlternateDirective()
Method Detail

getDescriptor

public static DirectiveDescriptor getDescriptor()

build

public java.lang.Object build(DirectiveBuilder builder,
                              BuildContext bc)
                       throws BuildException
Description copied from class: Directive
Directives must implement a build() method. The build method should examine the directive arguments (available through the DirectiveBuilder) and return a macro describing the built directive. In most cases, build() will just set up the directive's private fields and return 'this', but in some cases, no macro needs be returned (such as directives with only side effects on the build context) or some other macro may be returned (such as in the case of "#if (true) { }" -- no IfDirective object need be returned, just return the block.)

Specified by:
build in class Directive
Throws:
BuildException

write

public void write(FastWriter out,
                  Context context)
           throws PropertyException,
                  java.io.IOException
Description copied from interface: Macro
Interpret the directive and write it out, using the values in the supplied context as appropriate.

Throws:
java.io.IOException - if we could not successfully write to out
PropertyException - if required data was missing from context

accept

public void accept(TemplateVisitor v)
Specified by:
accept in interface Visitable
Overrides:
accept in class Directive