|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--freemarker.template.Template
An application or servlet can instantiate a subclass of Template to compile and process an HTML template.
You can pass the filename of the template to the constructor, in which case it is compiled immediately. Once compiled, the template is stored in an an efficient data structure for later use.
To process the template and produce HTML, call the process() method, which takes a tree of TemplateModel objects as its data model. The root node of the tree must be a TemplateModelRoot.
Any error messages from exceptions thrown by the data model, or generated by the Template during compilation or processing, will be thrown up to the caller to deal with.
Field Summary | |
static boolean |
CLASSIC_COMPATIBILITY
|
protected TemplateElement |
rootElement
|
Constructor Summary | |
Template()
Constructs an empty template. |
|
Template(java.io.File file)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
|
Template(java.io.InputStream stream)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
|
Template(java.io.Reader stream)
Constructs a template by compiling it from an Reader. |
|
Template(java.lang.String filePath)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
|
Template(TemplateCache cache,
java.io.InputStream is)
|
|
Template(TemplateCache cache,
java.io.InputStream is,
java.util.Locale locale)
|
|
Template(TemplateCache cache,
java.io.InputStream is,
java.lang.String encoding)
|
|
Template(TemplateCache cache,
java.io.Reader r,
java.util.Locale locale)
|
Method Summary | |
void |
addFunction(Function function)
Adds a function to the template. |
void |
compileFromFile(java.io.File file)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
void |
compileFromFile(java.lang.String filePath)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
void |
compileFromStream(java.io.InputStream stream)
Deprecated. Expect this to be removed later. You should either pass in a Reader, or an explicit encoding. |
void |
compileFromStream(java.io.InputStream stream,
java.lang.String encoding)
Compiles the template from an InputStream, using the specified character encoding. |
void |
compileFromStream(java.io.Reader stream)
Compiles the template from a Reader. |
void |
dump(java.io.PrintStream ps)
Dump the raw template in canonical form. |
void |
dump(java.io.PrintWriter pw)
Dump the raw template in canonical form. |
TemplateCache |
getCache()
Retrieve the cache that this object is stored in. |
static boolean |
getDebugMode()
|
java.lang.String |
getEncoding()
|
Function |
getFunction(java.lang.String name)
Retrieves a function from the template. |
java.util.Set |
getFunctionNames()
|
java.util.Locale |
getLocale()
|
java.lang.String |
getName()
|
void |
process(TemplateModelRoot modelRoot,
java.io.OutputStream out)
Processes the template, using data from a template model, and outputs the resulting HTML to an output stream using the encoding for the template. |
void |
process(TemplateModelRoot modelRoot,
java.io.Writer out)
Processes the template, using data from a template model, and outputs the resulting HTML to a Writer. |
void |
process(TemplateModelRoot modelRoot,
java.io.Writer out,
java.lang.Object dummy)
Processes the contents of this TemplateElement and outputs the resulting text to a Writer. |
void |
process(java.io.Writer out)
Processes the template, using an empty data model, and outputs the resulting HTML to a Writer. |
void |
setCache(TemplateCache cache)
Sets the cache that this object is stored in. |
static void |
setClassicCompatibility(boolean b)
Sets a flag to indicate that we should run in "classic compatibility mode". |
static void |
setDebugMode(boolean b)
If the debug mode is set to true (the default currently) all stack traces thrown by the process() method are simply output to the output stream (the web client in the case of a servlet-based app.) If it is false, the exception is simply rethrown and it is up to the application programmer to catch the exception and deal with it gracefully. |
void |
setEncoding(java.lang.String encoding)
|
void |
setLocale(java.util.Locale locale)
|
void |
setName(java.lang.String name)
|
java.lang.String |
toString(TemplateModelRoot root)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected TemplateElement rootElement
public static boolean CLASSIC_COMPATIBILITY
Constructor Detail |
public Template()
public Template(java.lang.String filePath) throws java.io.IOException
filePath
- the absolute path of the template file
to be compiled.public Template(java.io.File file) throws java.io.IOException
file
- a File representing the
template file to be compiled.public Template(java.io.InputStream stream) throws java.io.IOException
stream
- an InputStream from which the
template can be read.public Template(java.io.Reader stream) throws java.io.IOException
stream
- a Reader from which the
template can be read.public Template(TemplateCache cache, java.io.InputStream is) throws java.io.IOException
public Template(TemplateCache cache, java.io.InputStream is, java.lang.String encoding) throws java.io.IOException
public Template(TemplateCache cache, java.io.InputStream is, java.util.Locale locale) throws java.io.IOException
public Template(TemplateCache cache, java.io.Reader r, java.util.Locale locale) throws java.io.IOException
Method Detail |
public static void setDebugMode(boolean b)
public static boolean getDebugMode()
public static void setClassicCompatibility(boolean b)
public java.util.Locale getLocale()
public void setCache(TemplateCache cache)
public TemplateCache getCache()
public void compileFromStream(java.io.Reader stream) throws java.io.IOException
stream
- an Reader from which the
template can be read.public void compileFromFile(java.io.File file) throws java.io.IOException
file
- a File representing the
template file to be compiled.public void compileFromStream(java.io.InputStream stream) throws java.io.IOException
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
stream
- an InputStream from which the
template can be read.encoding
- the character encoding of the input streampublic void compileFromFile(java.lang.String filePath) throws java.io.IOException
filePath
- the absolute path of the template file
to be compiled.public void addFunction(Function function)
public Function getFunction(java.lang.String name)
public java.util.Set getFunctionNames()
public void process(TemplateModelRoot modelRoot, java.io.Writer out, java.lang.Object dummy) throws TemplateException, java.io.IOException
modelRoot
- the root node of the data model.out
- a Writer to send the output to.dummy
- A dummy argument that is not used. It is
there as a convenience to keep legacy code compilable.public void process(TemplateModelRoot modelRoot, java.io.Writer out) throws TemplateException, java.io.IOException
modelRoot
- the root node of the data model. If null, an
empty data model is used.out
- a Writer to output the HTML to.public java.lang.String toString(TemplateModelRoot root) throws TemplateException, java.io.IOException
public void process(java.io.Writer out) throws TemplateException, java.io.IOException
out
- a Writer to output the HTML to.public void process(TemplateModelRoot modelRoot, java.io.OutputStream out) throws TemplateException, java.io.IOException
modelRoot
- the root node of the data model. If null, an
empty data model is used.out
- an OutputStream to output the HTML to.public void dump(java.io.PrintWriter pw)
public void dump(java.io.PrintStream ps)
public java.lang.String getEncoding()
public void setEncoding(java.lang.String encoding)
public void setLocale(java.util.Locale locale)
public void setName(java.lang.String name)
public java.lang.String getName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |