|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--freemarker.template.AbstractTemplate
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
.
Template
,
UnparsedTemplate
Field Summary | |
protected Cache |
cache
The Cache to which this template belongs (if any). |
Constructor Summary | |
AbstractTemplate()
Constructs an empty unparsed template. |
|
AbstractTemplate(java.io.File file)
Constructs an unparsed template by compiling it from a file. |
|
AbstractTemplate(java.io.InputStream stream)
Constructs an unparsed template by compiling it from an InputStream . |
|
AbstractTemplate(java.io.Reader stream)
Constructs an unparsed template by compiling it from a Reader . |
|
AbstractTemplate(java.lang.String filePath)
Constructs an unparsed template by compiling it from a file. |
Method Summary | |
java.lang.Object |
clone()
Clones the current template. |
void |
compileFromFile(java.io.File file)
Reads an unparsed template from a file, by getting the file's FileInputStream and using it to call
compileFromStream(java.io.InputStream) ,
using the platform's default character encoding. |
void |
compileFromFile(java.lang.String filePath)
Reads an unparsed template from a file, by getting the file's FileInputStream and using it to call
compileFromStream(java.io.InputStream) ,
using the platform's default character encoding. |
void |
compileFromStream(java.io.InputStream stream)
Reads the unparsed template from an InputStream , using the
platform's default character encoding. |
void |
compileFromStream(java.io.InputStream stream,
java.lang.String encoding)
Compiles the template from an InputStream , using the
specified character encoding. |
abstract void |
compileFromStream(java.io.Reader stream)
Compiles the template from a Reader . |
Cache |
getCache()
Retrieve the Cache that this object is stored in. |
abstract void |
process(TemplateModelRoot modelRoot,
java.io.Writer out)
Processes the template, using data from a template model, and outputs the resulting text to a Writer . |
abstract void |
process(TemplateModelRoot 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 |
protected Cache cache
Cache
to which this template belongs (if any).Constructor Detail |
public AbstractTemplate()
public AbstractTemplate(java.lang.String filePath) throws java.io.IOException
compileFromFile(String)
.filePath
- the absolute path of the template file
to be compiled.public AbstractTemplate(java.io.File file) throws java.io.IOException
compileFromFile(java.io.File)
.file
- a File
representing the
template file to be compiled.public AbstractTemplate(java.io.InputStream stream) throws java.io.IOException
InputStream
. Calls
compileFromStream(java.io.InputStream)
.stream
- an InputStream
from which the
template can be read.public AbstractTemplate(java.io.Reader stream) throws java.io.IOException
Reader
. Calls
compileFromStream(java.io.InputStream)
.stream
- a Reader
from which the
template can be read.Method Detail |
public void compileFromFile(java.lang.String filePath) throws java.io.IOException
FileInputStream
and using it to call
compileFromStream(java.io.InputStream)
,
using the platform's default character encoding.filePath
- the absolute path of the template file
to be compiled.public void compileFromFile(java.io.File file) throws java.io.IOException
FileInputStream
and using it to call
compileFromStream(java.io.InputStream)
,
using the platform's default character encoding.file
- a File
representing the
template file to be compiled.public void compileFromStream(java.io.InputStream stream) throws java.io.IOException
InputStream
, using the
platform's default character encoding. If the template has
already been compiled, this method does nothing. Calls
compileFromStream(java.io.Reader)
to perform parsing.compileFromStream
in interface Compileable
stream
- an InputStream
from which the
template can be read.public void compileFromStream(java.io.InputStream stream, java.lang.String encoding) throws java.io.IOException
InputStream
, using the
specified character encoding. If the template has
already been compiled, this method does nothing. Calls
compileFromStream(java.io.Reader)
to perform parsing.compileFromStream
in interface Compileable
stream
- an InputStream
from which the
template can be read.encoding
- the character encoding of the input streampublic abstract void compileFromStream(java.io.Reader stream) throws java.io.IOException
Reader
. If the template
has already been compiled, this method does nothing.stream
- an Reader
from which the
template can be read.public void setCache(Cache cache)
Cache
that this object is stored in.setCache
in interface Cacheable
cache
- the Cache
that this template belongs to.public Cache getCache()
Cache
that this object is stored in.getCache
in interface Cacheable
Cache
that this template belongs to.public java.lang.Object clone()
Clones the current template.
Cloning is used in Cache
s,
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.
clone
in interface Cacheable
clone
in class java.lang.Object
public abstract void process(TemplateModelRoot modelRoot, java.io.Writer out, TemplateRuntimeHandler eventHandler) throws java.io.IOException
TemplateEventAdapter
, and outputs
the resulting text to a Writer
.process
in interface TemplateProcessor
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.public abstract void process(TemplateModelRoot modelRoot, java.io.Writer out) throws java.io.IOException
Writer
.modelRoot
- the root node of the data model. If null
,
an empty data model is used.out
- a Writer
to output the text to.public abstract void process(java.io.Writer out) throws java.io.IOException
Writer
.out
- a Writer
to output the text to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |