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.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(org.apache.velocity.context.Context context,
Class clazz,
String method,
Exception e,
org.apache.velocity.util.introspection.Info info)
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).
|
protected void |
setVelocityProperties(org.apache.velocity.app.VelocityEngine velocity,
org.apache.commons.configuration2.Configuration conf)
This method generates the Properties object necessary
for the initialization of Velocity.
|
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(org.apache.velocity.context.Context context, Class clazz, String method, Exception e, org.apache.velocity.util.introspection.Info info)
methodException
in interface org.apache.velocity.app.event.MethodExceptionEventHandler
context
- The current contextclazz
- The class that threw the exceptionmethod
- The Method name that threw the exceptione
- The exception that would've been throwninfo
- Information about the template, line and column the exception occurredpublic 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.protected void setVelocityProperties(org.apache.velocity.app.VelocityEngine velocity, org.apache.commons.configuration2.Configuration conf) throws Exception
velocity
- The Velocity engineconf
- 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–2019 The Apache Software Foundation. All rights reserved.