public class Template extends Resource
// set up and initialize Velocity before this code block Template template = Velocity.getTemplate("test.wm"); Context context = new VelocityContext(); context.put("foo", "bar"); context.put("customer", new Customer()); template.merge(context, writer);
Modifier and Type | Field and Description |
---|---|
private VelocityException |
errorCondition |
private java.util.Map<java.lang.String,java.lang.Object> |
macros |
private boolean |
provideScope |
private java.lang.String |
scopeName |
data, encoding, lastModified, log, MILLIS_PER_SECOND, modificationCheckInterval, name, nextCheck, resourceLoader, rsvc, type
Constructor and Description |
---|
Template()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
getMacros()
get the map of all macros defined by this template
|
void |
initDocument()
initializes the document.
|
void |
merge(Context context,
java.io.Writer writer)
The AST node structure is merged with the
context to produce the final output.
|
void |
merge(Context context,
java.io.Writer writer,
java.util.List<java.lang.String> macroLibraries)
The AST node structure is merged with the
context to produce the final output.
|
boolean |
process()
gets the named resource as a stream, parses and inits
|
getData, getEncoding, getLastModified, getName, getResourceLoader, getType, isSourceModified, requiresChecking, setData, setEncoding, setLastModified, setModificationCheckInterval, setName, setResourceLoader, setRuntimeServices, setType, touch
private java.lang.String scopeName
private boolean provideScope
private java.util.Map<java.lang.String,java.lang.Object> macros
private VelocityException errorCondition
public java.util.Map<java.lang.String,java.lang.Object> getMacros()
public boolean process() throws ResourceNotFoundException, ParseErrorException
process
in class Resource
ResourceNotFoundException
- if template not found
from any available source.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.public void initDocument() throws TemplateInitException
TemplateInitException
- When a problem occurs during the document initialization.public void merge(Context context, java.io.Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException
context
- Context with data elements accessed by templatewriter
- output writer for rendered templateResourceNotFoundException
- if template not found
from any available source.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.MethodInvocationException
- When a method on a referenced object in the context could not invoked.public void merge(Context context, java.io.Writer writer, java.util.List<java.lang.String> macroLibraries) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException
context
- Context with data elements accessed by templatewriter
- output writer for rendered templatemacroLibraries
- a list of template files containing macros to be used when mergingResourceNotFoundException
- if template not found
from any available source.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.MethodInvocationException
- When a method on a referenced object in the context could not invoked.