freemarker.template
Class AbstractTemplate

java.lang.Object
  extended by freemarker.template.AbstractTemplate
All Implemented Interfaces:
Cacheable, Compileable, TemplateProcessor, java.lang.Cloneable
Direct Known Subclasses:
Template, UnparsedTemplate

public abstract class AbstractTemplate
extends java.lang.Object
implements TemplateProcessor, Cacheable, Compileable, java.lang.Cloneable

A base class from which Template implementations are subclassed. This class implements all the interfaces required, and provides some of the basic machinery required to compile and cache a Template.

Version:
$Id: AbstractTemplate.java 1145 2005-10-09 06:32:16Z run2000 $
See Also:
Template, UnparsedTemplate

Nested Class Summary
 
Nested classes/interfaces inherited from interface freemarker.template.TemplateProcessor
TemplateProcessor.ExitStatus
 
Field Summary
protected  Cache cache
          The Cache to which this template belongs (if any).
 
Constructor Summary
AbstractTemplate()
          Constructs an empty template.
AbstractTemplate(java.io.File file)
          Deprecated. use the InputSource contructor to supply source streams to the template compiler
AbstractTemplate(InputSource source)
          Constructs a template by compiling it from an InputSource.
AbstractTemplate(java.io.InputStream stream)
          Deprecated. use the InputSource contructor to supply source streams to the template compiler
AbstractTemplate(java.io.Reader stream)
          Deprecated. use the InputSource contructor to supply source streams to the template compiler
AbstractTemplate(java.lang.String filePath)
          Deprecated. use the InputSource contructor to supply source streams to the template compiler
 
Method Summary
 java.lang.Object clone()
          Clones the current template.
abstract  void compile(InputSource source)
          Compiles the template from an InputSource.
 void compileFromFile(java.io.File file)
          Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler
 void compileFromFile(java.lang.String filePath)
          Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler
 void compileFromStream(java.io.InputStream stream)
          Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler
 void compileFromStream(java.io.InputStream stream, java.lang.String encoding)
          Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler
 void compileFromStream(java.io.Reader stream)
          Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler
 Cache getCache()
          Retrieve the Cache that this object is stored in.
abstract  void process(TemplateWriteableHashModel modelRoot, java.io.Writer out)
          Processes the template, using data from a template model, and outputs the resulting text to a Writer.
abstract  TemplateProcessor.ExitStatus process(TemplateWriteableHashModel modelRoot, java.io.Writer out, TemplateRuntimeHandler eventHandler)
          Processes the template, using data from the template model, writing any events to the TemplateEventAdapter, and outputs the resulting text to a Writer.
abstract  void process(java.io.Writer out)
          Processes the template, using an empty data model, and outputs the resulting text to a Writer.
 void setCache(Cache cache)
          Sets the Cache that this object is stored in.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected Cache cache
The Cache to which this template belongs (if any).

Constructor Detail

AbstractTemplate

public AbstractTemplate()
Constructs an empty template.


AbstractTemplate

public AbstractTemplate(InputSource source)
                 throws java.io.IOException,
                        java.lang.IllegalArgumentException
Constructs a template by compiling it from an InputSource. Calls compileFromStream(java.io.InputStream).

Parameters:
source - an InputSource from which the template can be read.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

AbstractTemplate

@Deprecated
public AbstractTemplate(java.lang.String filePath)
                 throws java.io.IOException
Deprecated. use the InputSource contructor to supply source streams to the template compiler

Constructs a template by compiling it from a file. Calls compile(InputSource).

Parameters:
filePath - the absolute path of the template file to be compiled.
Throws:
java.io.IOException

AbstractTemplate

@Deprecated
public AbstractTemplate(java.io.File file)
                 throws java.io.IOException
Deprecated. use the InputSource contructor to supply source streams to the template compiler

Constructs a template by compiling it from a file. Calls compile(InputSource).

Parameters:
file - a File representing the template file to be compiled.
Throws:
java.io.IOException

AbstractTemplate

@Deprecated
public AbstractTemplate(java.io.InputStream stream)
                 throws java.io.IOException
Deprecated. use the InputSource contructor to supply source streams to the template compiler

Constructs a template by compiling it from an InputStream. Calls compile(InputSource).

Parameters:
stream - an InputStream from which the template can be read.
Throws:
java.io.IOException

AbstractTemplate

@Deprecated
public AbstractTemplate(java.io.Reader stream)
                 throws java.io.IOException
Deprecated. use the InputSource contructor to supply source streams to the template compiler

Constructs a template by compiling it from a Reader. Calls compile(InputSource).

Parameters:
stream - a Reader from which the template can be read.
Throws:
java.io.IOException
Method Detail

compileFromFile

@Deprecated
public void compileFromFile(java.lang.String filePath)
                     throws java.io.IOException
Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler

Reads a template from a file, by getting the file's FileInputStream and using it to call compile(InputSource), using the platform's default character encoding.

Parameters:
filePath - the absolute path of the template file to be compiled.
Throws:
java.io.IOException

compileFromFile

@Deprecated
public void compileFromFile(java.io.File file)
                     throws java.io.IOException
Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler

Reads a template from a file, by getting the file's FileInputStream and using it to call compile(InputSource), using the platform's default character encoding.

Parameters:
file - a File representing the template file to be compiled.
Throws:
java.io.IOException

compileFromStream

@Deprecated
public void compileFromStream(java.io.InputStream stream)
                       throws java.io.IOException
Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler

Reads the template from an InputStream, using the platform's default character encoding. If the template has already been compiled, this method does nothing. Calls compile(InputSource) to perform parsing.

Specified by:
compileFromStream in interface Compileable
Parameters:
stream - an InputStream from which the template can be read.
Throws:
java.io.IOException

compileFromStream

@Deprecated
public void compileFromStream(java.io.InputStream stream,
                                         java.lang.String encoding)
                       throws java.io.IOException
Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler

Compiles the template from an InputStream, using the specified character encoding. If the template has already been compiled, this method does nothing. Calls compile(InputSource) to perform parsing.

Specified by:
compileFromStream in interface Compileable
Parameters:
stream - an InputStream from which the template can be read.
encoding - the character encoding of the input stream
Throws:
java.io.IOException

compileFromStream

@Deprecated
public void compileFromStream(java.io.Reader stream)
                       throws java.io.IOException
Deprecated. use the compile(freemarker.template.InputSource) method to supply source streams to the template compiler

Compiles the template from a Reader. If the template has already been compiled, this method does nothing. Calls compile(InputSource) to perform parsing.

Parameters:
stream - an Reader from which the template can be read.
Throws:
java.io.IOException

compile

public abstract void compile(InputSource source)
                      throws java.io.IOException,
                             java.lang.IllegalArgumentException
Compiles the template from an InputSource. If the template has already been compiled, this method does nothing.

Specified by:
compile in interface Compileable
Parameters:
source - an InputSource from which the template can be read.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

setCache

public void setCache(Cache cache)
Sets the Cache that this object is stored in.

Specified by:
setCache in interface Cacheable
Parameters:
cache - the Cache that this template belongs to.

getCache

public Cache getCache()
Retrieve the Cache that this object is stored in.

Specified by:
getCache in interface Cacheable
Returns:
the Cache that this template belongs to.

clone

public java.lang.Object clone()

Clones the current template.

Cloning is used in Caches, whenever we need to create a new template: rather than simply creating a new Template, we ask a TemplateRegistry to create one for us. TemplateRegistry uses the clone function to take an existing template, copy it, and return the copy to the cache, where it is then populated.

Specified by:
clone in interface Cacheable
Overrides:
clone in class java.lang.Object
Returns:
a copy of the current template.

process

public abstract TemplateProcessor.ExitStatus process(TemplateWriteableHashModel modelRoot,
                                                     java.io.Writer out,
                                                     TemplateRuntimeHandler eventHandler)
                                              throws java.io.IOException
Processes the template, using data from the template model, writing any events to the TemplateEventAdapter, and outputs the resulting text to a Writer.

Specified by:
process in interface TemplateProcessor
Parameters:
modelRoot - the root node of the data model.
out - a Writer to send the output to.
eventHandler - a TemplateEventAdapter for handling any events that occur during processing.
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

process

public abstract void process(TemplateWriteableHashModel modelRoot,
                             java.io.Writer out)
                      throws java.io.IOException
Processes the template, using data from a template model, and outputs the resulting text to a Writer.

Parameters:
modelRoot - the root node of the data model. If null, an empty data model is used.
out - a Writer to output the text to.
Throws:
java.io.IOException

process

public abstract void process(java.io.Writer out)
                      throws java.io.IOException
Processes the template, using an empty data model, and outputs the resulting text to a Writer.

Parameters:
out - a Writer to output the text to.
Throws:
java.io.IOException