org.brains2b.typewriter
Class IfTemplate

java.lang.Object
  extended byorg.brains2b.typewriter.ContentTemplate
      extended byorg.brains2b.typewriter.IfTemplate
All Implemented Interfaces:
Template

public class IfTemplate
extends ContentTemplate

Template for creating conditions and else statements in another ContentTemplate

Version:
0.12.1 11-06-2006
Author:
dennis@brains2b.nl
See Also:
ContentTemplate.createIf(String)

Field Summary
 
Fields inherited from class org.brains2b.typewriter.ContentTemplate
m_content
 
Constructor Summary
IfTemplate(java.lang.String condition)
          Constructor for IfTemplate.
 
Method Summary
 BlockTemplate createElse()
          create an else statement for this condition
 java.lang.String getCondition()
          get the condition.
 void setCondition(java.lang.String condition)
          set the expression to evaluate for this condition
 void write(java.io.PrintWriter writer, int indent)
          this implementation of write follows the rule that if this statement has an else statement which only contains another if statement the statement should read } else if ( instead of closing the else and starting with a new condition.
 void write(java.io.PrintWriter writer, int indent, boolean firstLine)
          write the if statement to the PrintWriter
 
Methods inherited from class org.brains2b.typewriter.ContentTemplate
addImport, addText, createFor, createIf, createTry, createWhile, getContent, getParent, makeInstance, makeInstance, makeInstance, setContent, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IfTemplate

public IfTemplate(java.lang.String condition)
Constructor for IfTemplate.

Parameters:
condition - String, an expression defining the condition for this statement
Method Detail

write

public void write(java.io.PrintWriter writer,
                  int indent)

this implementation of write follows the rule that if this statement has an else statement which only contains another if statement the statement should read } else if ( instead of closing the else and starting with a new condition.

Specified by:
write in interface Template
Overrides:
write in class ContentTemplate
See Also:
Template.write(java.io.PrintWriter, int)

write

public void write(java.io.PrintWriter writer,
                  int indent,
                  boolean firstLine)
write the if statement to the PrintWriter

Parameters:
writer - PrintWriter
indent - int, current indent
firstLine - boolean, false if this is a condition which is the only content of an else branch, true if it is a regular condition
Throws:
TypeWriterException, - if the condition is not set or if it is empty
See Also:
Template.write(java.io.PrintWriter, int)

createElse

public BlockTemplate createElse()
create an else statement for this condition

Returns:
IfTemplate, a new instance of this IfTemplate used for it's else statement

setCondition

public void setCondition(java.lang.String condition)
set the expression to evaluate for this condition

Parameters:
condition - String, the expression

getCondition

public java.lang.String getCondition()
get the condition.

Returns:
String