freemarker.template.instruction
Class ElseInstruction

java.lang.Object
  extended by freemarker.template.instruction.ElseInstruction
All Implemented Interfaces:
Instruction, TemplateProcessor, java.io.Serializable
Direct Known Subclasses:
IfInstruction

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

An instruction representing an if-else structure. The "else" part of the structure will be executed if the condition expression evaluates to true value.

As a special case, any "else" structures are performed the same way as "if" structures, but with the test always returning true.

Unexpectedly, this is a superclass of the regular IfInstruction class.

Version:
$Id: ElseInstruction.java 1162 2013-04-20 12:04:32Z run2000 $
See Also:
IfElseInstruction, IfInstruction, 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
 
Field Summary
protected  TemplateProcessor body
          The template body to process if the else clause is reached.
 
Constructor Summary
ElseInstruction()
          Constructor to be used when evaluating the "else" part of the instruction.
 
Method Summary
 TemplateProcessor callBuilder(TemplateBuilder builder)
          A TemplateBuilder can call this method to have an Instruction call it back to be built.
 boolean conditionMatches(TemplateWriteableHashModel modelRoot)
          Tests the condition for which this "else" statement should match.
 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 <else> instruction.
 void setBody(TemplateProcessor body)
          Sets the body to be executed if the "if" expression is true.
 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
 

Field Detail

body

protected TemplateProcessor body
The template body to process if the else clause is reached.

Constructor Detail

ElseInstruction

public ElseInstruction()
Constructor to be used when evaluating the "else" part of the instruction.

Method Detail

conditionMatches

public boolean conditionMatches(TemplateWriteableHashModel modelRoot)
                         throws TemplateException
Tests the condition for which this "else" statement should match.

Returns:
the condition to be tested
Throws:
TemplateException

setBody

public final void setBody(TemplateProcessor body)
Sets the body to be executed if the "if" expression is true.

Parameters:
body - a TemplateProcessor to be processed if the condition is true.

isEndInstruction

public final boolean isEndInstruction()
Is this an end instruction?

Specified by:
isEndInstruction in interface Instruction
Returns:
true, 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:
ELSE, indicating that this is an else instruction

callBuilder

public final TemplateProcessor callBuilder(TemplateBuilder builder)
A TemplateBuilder can call this method to have an Instruction call it back to be built. For end instructions, there is nothing more to be build, so return immediately.

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

process

public final TemplateProcessor.ExitStatus process(TemplateProcessorParameters p)
                                           throws java.io.IOException
Evaluate the <else> 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