freemarker.template.instruction
Class IfElseInstruction

java.lang.Object
  extended by freemarker.template.instruction.IfElseInstruction
All Implemented Interfaces:
Instruction, TemplateProcessor, java.io.Serializable

public final class IfElseInstruction
extends java.lang.Object
implements Instruction, TemplateProcessor, java.io.Serializable

A instruction that handles if-elseif-else functionality. The initial "if" clause is held in a single variable. If any else or elseif clauses are encountered, they are stored in a List of IfInstructions. The List is not constructed until the first else or elseif is encountered.

Version:
$Id: IfElseInstruction.java 1162 2013-04-20 12:04:32Z run2000 $
Author:
Jonathan Revusky
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface freemarker.template.instruction.Instruction
Instruction.EndType
 
Nested classes/interfaces inherited from interface freemarker.template.TemplateProcessor
TemplateProcessor.ExitStatus
 
Constructor Summary
IfElseInstruction(Expression condition)
          Constructs a new if/else instruction without the first block.
 
Method Summary
 void addTest(ElseInstruction instruction)
          Adds a new test to the if/else instruction.
 TemplateProcessor callBuilder(TemplateBuilder builder)
          A TemplateBuilder can call this method to have an Instruction call it back to be built.
 Instruction.EndType getEndType()
          Determine what type of end instruction this is, if any.
 boolean isEndInstruction()
          Is this an end instruction?
 TemplateProcessor.ExitStatus process(TemplateProcessorParameters p)
          Evaluate the <if ...
 void setIfBlock(TemplateProcessor block)
          Adds the main block to the first "if" statement.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfElseInstruction

public IfElseInstruction(Expression condition)
Constructs a new if/else instruction without the first block.

Parameters:
condition - the condition for the first if
Throws:
java.lang.NullPointerException - condition is null
Method Detail

setIfBlock

public void setIfBlock(TemplateProcessor block)
Adds the main block to the first "if" statement. For if/else, this is a special case.

Parameters:
block - the block to be processed if the first "if" statement is true

addTest

public void addTest(ElseInstruction instruction)
Adds a new test to the if/else instruction. Each test is evaluated in the order they are added using this method.

Parameters:
instruction - the "if" instruction to be evaluated and executed
Throws:
java.lang.NullPointerException - instruction is null

isEndInstruction

public boolean isEndInstruction()
Is this an end instruction?

Specified by:
isEndInstruction in interface Instruction
Returns:
false, indicating that this is not an end instruction

getEndType

public Instruction.EndType getEndType()
Determine what type of end instruction this is, if any.

Specified by:
getEndType in interface Instruction
Returns:
NONE, indicating that this is not an end instruction

callBuilder

public TemplateProcessor callBuilder(TemplateBuilder builder)
                              throws ParseException
A TemplateBuilder can call this method to have an Instruction call it back to be built. This implementation throws an UnsupportedOperationException indicating that this is not yet production code.

Specified by:
callBuilder in interface Instruction
Parameters:
builder - the builder to be called back by this method
Throws:
ParseException

process

public TemplateProcessor.ExitStatus process(TemplateProcessorParameters p)
                                     throws java.io.IOException
Evaluate the <if ... > instruction.

Specified by:
process in interface TemplateProcessor
Parameters:
p - template processing parameters
Returns:
an exit code indicating how the process terminated, typically used for short-circuiting template processing
Throws:
java.io.IOException - an IO error occurred during processing

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a String representing this instruction subtree