|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.webmacro.engine.WMTemplate
Template objects represent the user defined layout into which the webmacro package will substitute values. It is a very simple kind of interpreted language containing text, blocks, and directives. Text is to be passed through verbatim. LList group text and directives into linear lists and sublists. Directives determine how subsequent blocks are to be processed and constitute the commands of the language.
The Template is lazily evaluated: it does not parse or open the supplied filename until it is used. Once it has parsed the file, it never alters its data. The intent is to allow a Template to be parsed once (somewhat expensive) and then used many times; and also not to incur any parsing costs at all if the Template is never actually used.
CONCURRENCY: You must parse() the template before making it available to other threads. After a template has been parsed it is immutable and can be shared between threads without synchronization. This class performs no synchronization itself but instead relies on the TemplateProvider/Broker to synchronize access.
Field Summary | |
protected Broker |
_broker
The resource broker used to resolve things in this template |
protected Block |
_content
What this template contains is a top level block |
protected Log |
_log
Where we log our errors |
Constructor Summary | |
protected |
WMTemplate(Broker broker)
Create a new Template. |
protected |
WMTemplate(java.lang.String parserName,
Broker broker)
Create a new Template specifying both the broker and the parsing language. |
Method Summary | |
void |
accept(TemplateVisitor v)
|
java.lang.Object |
evaluate(Context data)
Parse the Template against the supplied context data and return it as a string. |
protected java.lang.String |
getDefaultEncoding()
return the default encoding either from the WebMacro config or the JVM settings Note for Unix users: you may need to set the environmental variable LC_ALL=[locale] to get the default one set up. |
java.util.Map |
getMacros()
Get the #macros' defined for this template. |
java.lang.String |
getName()
Return a name for this template. |
java.lang.Object |
getParam(java.lang.String key)
Template API |
java.util.Map |
getParameters()
|
protected Parser |
getParser()
Subclasses can override this if they wish to invoke a parser other than the WM parser, or choose the parser on some more complicated condition. |
protected abstract java.io.Reader |
getReader()
Get the stream the template should be read from. |
void |
parse()
Template API |
void |
setName(java.lang.String name)
Set the name for this template. |
void |
setParam(java.lang.String key,
java.lang.Object value)
set a parameter. |
abstract java.lang.String |
toString()
Return a name for this template. |
void |
write(FastWriter out,
Context data)
A macro has a write method which takes a context and applies it to the macro to create a resulting String value, which is then written to the supplied stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected final Broker _broker
protected final Log _log
protected Block _content
Constructor Detail |
protected WMTemplate(Broker broker)
protected WMTemplate(java.lang.String parserName, Broker broker)
Method Detail |
protected abstract java.io.Reader getReader() throws java.io.IOException
java.io.IOException
- if unable to read templatepublic abstract java.lang.String toString()
public java.lang.String getName()
getName
in interface Template
public void setName(java.lang.String name)
setName
in interface Template
protected Parser getParser() throws TemplateException
TemplateException
public void parse() throws java.io.IOException, TemplateException
parse
in interface Template
TemplateException
- if the sytax was invalid and we could not recover
java.io.IOException
- if we could not successfullly read the parseToolpublic java.util.Map getMacros()
getMacros
in interface Template
parse()'d
.public final java.lang.Object evaluate(Context data) throws PropertyException
evaluate
in interface Macro
PropertyException
- if required data was missing from contextpublic final void write(FastWriter out, Context data) throws java.io.IOException, PropertyException
write
in interface Macro
java.io.IOException
- if there is a problem writing to the Writer
PropertyException
- if required data was missing from contextpublic void accept(TemplateVisitor v)
accept
in interface Visitable
protected final java.lang.String getDefaultEncoding()
public java.lang.Object getParam(java.lang.String key) throws java.io.IOException, TemplateException
getParam
in interface Template
TemplateException
- if an error occurred parsing the template
java.io.IOException
- if an error occurred reading the templatepublic java.util.Map getParameters()
getParameters
in interface Template
public void setParam(java.lang.String key, java.lang.Object value)
Template
setParam
in interface Template
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |