public class TurbineVelocityService extends BaseTemplateEngineService implements VelocityService, org.apache.velocity.app.event.MethodExceptionEventHandler
Context context = TurbineVelocity.getContext(data);
context.put("message", "Hello from Turbine!");
String results = TurbineVelocity.handleRequest(context,"helloWorld.vm");
data.getPage().getBody().addElement(results);
name, serviceBroker
initableBroker, isInitialized
CATCH_ERRORS_DEFAULT, CATCH_ERRORS_KEY, CONTEXT, PIPELINEDATA_KEY, RUNDATA_KEY, SERVICE_NAME, VELOCITY_EXTENSION
DEFAULT_ERROR_SCREEN, DEFAULT_LAYOUT, DEFAULT_LAYOUT_TEMPLATE, DEFAULT_NAVIGATION, DEFAULT_NAVIGATION_TEMPLATE, DEFAULT_PAGE, DEFAULT_SCREEN, DEFAULT_SCREEN_TEMPLATE, DEFAULT_TEMPLATE_EXTENSION, TEMPLATE_EXTENSIONS
Constructor and Description |
---|
TurbineVelocityService() |
Modifier and Type | Method and Description |
---|---|
org.apache.commons.collections.ExtendedProperties |
createVelocityProperties(org.apache.commons.configuration.Configuration conf)
This method generates the Extended Properties object necessary
for the initialization of Velocity.
|
org.apache.velocity.context.Context |
getContext()
Create a Context object that also contains the globalContext.
|
org.apache.velocity.context.Context |
getContext(PipelineData pipelineData)
Create a Context from the PipelineData object.
|
org.apache.velocity.context.Context |
getNewContext()
This method returns a new, empty Context object.
|
String |
handleRequest(org.apache.velocity.context.Context context,
String filename)
Process the request and fill in the template with the values
you set in the Context.
|
void |
handleRequest(org.apache.velocity.context.Context context,
String filename,
OutputStream output)
Process the request and fill in the template with the values
you set in the Context.
|
void |
handleRequest(org.apache.velocity.context.Context context,
String filename,
Writer writer)
Process the request and fill in the template with the values
you set in the Context.
|
void |
init()
Load all configured components and initialize them.
|
Object |
methodException(Class clazz,
String method,
Exception e)
MethodException Event Cartridge handler
for Velocity.
|
void |
requestFinished(org.apache.velocity.context.Context context)
Performs post-request actions (releases context
tools back to the object pool).
|
boolean |
templateExists(String template)
Find out if a given template exists.
|
getAssociatedFileExtensions, getTemplateEngineServiceConfiguration, initConfiguration, registerConfiguration
init, init, shutdown
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
getInit, getInitableBroker, setInit, setInitableBroker
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfiguration, getName, getProperties, setName, setServiceBroker
getInit, init, setInitableBroker, shutdown
public TurbineVelocityService()
public void init() throws InitializationException
init
in interface Initable
init
in class TurbineBaseService
InitializationException
- Something went wrong in the init
stagepublic org.apache.velocity.context.Context getContext()
getContext
in interface VelocityService
public org.apache.velocity.context.Context getNewContext()
getNewContext
in interface VelocityService
public Object methodException(Class clazz, String method, Exception e) throws Exception
methodException
in interface org.apache.velocity.app.event.MethodExceptionEventHandler
clazz
- The class that threw the exceptionmethod
- The Method name that threw the exceptione
- The exception that would've been thrownException
- We threw the exception further uppublic org.apache.velocity.context.Context getContext(PipelineData pipelineData)
getContext
in interface VelocityService
pipelineData
- The Turbine PipelineData object.public String handleRequest(org.apache.velocity.context.Context context, String filename) throws TurbineException
handleRequest
in interface VelocityService
context
- The populated context.filename
- The file name of the template.TurbineException
- Any exception thrown while processing will be
wrapped into a TurbineException and rethrown.public void handleRequest(org.apache.velocity.context.Context context, String filename, OutputStream output) throws TurbineException
handleRequest
in interface VelocityService
context
- A Context.filename
- A String with the filename of the template.output
- A OutputStream where we will write the process template as
a String.TurbineException
- Any exception thrown while processing will be
wrapped into a TurbineException and rethrown.public void handleRequest(org.apache.velocity.context.Context context, String filename, Writer writer) throws TurbineException
handleRequest
in interface VelocityService
context
- A Context.filename
- A String with the filename of the template.writer
- A Writer where we will write the process template as
a String.TurbineException
- Any exception thrown while processing will be
wrapped into a TurbineException and rethrown.public org.apache.commons.collections.ExtendedProperties createVelocityProperties(org.apache.commons.configuration.Configuration conf) throws Exception
conf
- The Velocity Service configurationException
- If a problem occurred while converting the properties.public boolean templateExists(String template)
templateExists
in interface TemplateEngineService
templateExists
in class BaseTemplateEngineService
template
- String template to search forTemplateEngineService.templateExists(java.lang.String)
public void requestFinished(org.apache.velocity.context.Context context)
requestFinished
in interface VelocityService
context
- a Velocity ContextCopyright © 2000-2015 The Apache Software Foundation. All Rights Reserved.