Package org.apache.velocity
Class Template
- java.lang.Object
-
- org.apache.velocity.runtime.resource.Resource
-
- org.apache.velocity.Template
-
public class Template extends Resource
This class is used for controlling all template operations. This class uses a parser created by JavaCC to create an AST that is subsequently traversed by a Visitor.// 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);
- Version:
- $Id: Template.java 778045 2009-05-23 22:17:46Z nbubna $
-
-
Field Summary
Fields Modifier and Type Field Description private VelocityException
errorCondition
private boolean
provideScope
private java.lang.String
scopeName
-
Fields inherited from class org.apache.velocity.runtime.resource.Resource
data, encoding, lastModified, MILLIS_PER_SECOND, modificationCheckInterval, name, nextCheck, resourceLoader, rsvc, type
-
-
Constructor Summary
Constructors Constructor Description Template()
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 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-
Methods inherited from class org.apache.velocity.runtime.resource.Resource
getData, getEncoding, getLastModified, getName, getResourceLoader, getType, isSourceModified, requiresChecking, setData, setEncoding, setLastModified, setModificationCheckInterval, setName, setResourceLoader, setRuntimeServices, setType, touch
-
-
-
-
Field Detail
-
scopeName
private java.lang.String scopeName
-
provideScope
private boolean provideScope
-
errorCondition
private VelocityException errorCondition
-
-
Method Detail
-
process
public boolean process() throws ResourceNotFoundException, ParseErrorException
gets the named resource as a stream, parses and inits- Specified by:
process
in classResource
- Returns:
- true if successful
- Throws:
ResourceNotFoundException
- if template not found from any available source.ParseErrorException
- if template cannot be parsed due to syntax (or other) error.java.io.IOException
- problem reading input stream
-
initDocument
public void initDocument() throws TemplateInitException
initializes the document. init() is not longer dependant upon context, but we need to let the init() carry the template name down throught for VM namespace features- Throws:
TemplateInitException
- When a problem occurs during the document initialization.
-
merge
public void merge(Context context, java.io.Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException
The AST node structure is merged with the context to produce the final output.- Parameters:
context
- Conext with data elements accessed by templatewriter
- output writer for rendered template- Throws:
ResourceNotFoundException
- 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.
-
merge
public void merge(Context context, java.io.Writer writer, java.util.List macroLibraries) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException
The AST node structure is merged with the context to produce the final output.- Parameters:
context
- Conext with data elements accessed by templatewriter
- output writer for rendered templatemacroLibraries
- a list of template files containing macros to be used when merging- Throws:
ResourceNotFoundException
- 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.- Since:
- 1.6
-
-