public class VelocityTemplate extends AbstractTemplate
A Template implementation using the Apache Velocity templating engine. The engine itself is required as a separate module, VelocityEngineModule. The base functionality is defined in the AbstractTemplate base class and only the actual template processing is done here.
A few items are automatically added in the template context, in addition to the ones specified in initialisation parameters, as described in AbstractTemplate documentation. These are used to overcome some of the limitations in Velocity template language. The urlencoder parameter contains a URLEncoder object which can help with encoding values used in URLs. listmaker variable contains an InstanceMaker that can make ArrayLists, it is difficult to create new lists in Velocity without this. These helper classes are defined in org.wandora.modules.velocityhelpers along with other similar helpers, which you may want to add to the context manually.
Modifier and Type | Field and Description |
---|---|
protected VelocityEngineModule |
engineModule |
protected org.apache.velocity.Template |
vTemplate |
templateCaching, templateContext, templateEncoding, templateFile, templateKey, templateManager, templateMime, templateVersion
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
VelocityTemplate() |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
protected java.lang.String |
getFullTemplatePath() |
java.util.HashMap<java.lang.String,java.lang.Object> |
getTemplateContext()
Returns the default context for this template.
|
protected org.apache.velocity.app.VelocityEngine |
getVelocityEngine() |
void |
process(java.util.HashMap<java.lang.String,java.lang.Object> params,
java.io.OutputStream output)
Processes the template with the given context and writes the resulting
content in the output stream.
|
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
getEncoding, getKey, getMimeType, getVersion, init
isInitialized, isRunning, requireLogging, toString
protected org.apache.velocity.Template vTemplate
protected VelocityEngineModule engineModule
protected org.apache.velocity.app.VelocityEngine getVelocityEngine()
protected java.lang.String getFullTemplatePath()
getFullTemplatePath
in class AbstractTemplate
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractTemplate
manager
- The module manager handling this module.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractTemplate
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractTemplate
manager
- The module manager handling this module.public java.util.HashMap<java.lang.String,java.lang.Object> getTemplateContext()
Template
getTemplateContext
in interface Template
getTemplateContext
in class AbstractTemplate
public void process(java.util.HashMap<java.lang.String,java.lang.Object> params, java.io.OutputStream output)
Template
process
in interface Template
process
in class AbstractTemplate
params
- The template context used for processing of the template.output
- The output stream where the result is written.Copyright 2004-2015 Wandora Team