Class TurbineVelocityService
- java.lang.Object
- 
- org.apache.turbine.services.BaseInitable
- 
- org.apache.turbine.services.BaseService
- 
- org.apache.turbine.services.TurbineBaseService
- 
- org.apache.turbine.services.template.BaseTemplateEngineService
- 
- org.apache.turbine.services.velocity.TurbineVelocityService
 
 
 
 
 
- 
- All Implemented Interfaces:
- Initable,- Service,- TemplateEngineService,- VelocityService,- org.apache.velocity.app.event.EventHandler,- org.apache.velocity.app.event.MethodExceptionEventHandler
 
 public class TurbineVelocityService extends BaseTemplateEngineService implements VelocityService, org.apache.velocity.app.event.MethodExceptionEventHandler This is a Service that can process Velocity templates from within a Turbine Screen. It is used in conjunction with the templating service as a Templating Engine for templates ending in "vm". It registers itself as translation engine with the template service and gets accessed from there. After configuring it in your properties, it should never be necessary to call methods from this service directly. Here's an example of how you might use it from a screen:
 Context context = TurbineVelocity.getContext(data);
 context.put("message", "Hello from Turbine!");
 String results = TurbineVelocity.handleRequest(context,"helloWorld.vm");
 data.getPage().getBody().addElement(results);
 - Version:
- $Id$
- Author:
- Dave Bryson, Rafal Krzewski, Jason van Zyl, Sean Legassick, Daniel Rall, Henning P. Schmiedehausen, Eric Pugh, Peter Courcoux
 
- 
- 
Field Summary- 
Fields inherited from class org.apache.turbine.services.BaseServicename, serviceBroker
 - 
Fields inherited from class org.apache.turbine.services.BaseInitableinitableBroker, isInitialized
 - 
Fields inherited from interface org.apache.turbine.services.ServiceSERVICE_NAME
 - 
Fields inherited from interface org.apache.turbine.services.template.TemplateEngineServiceDEFAULT_ERROR_SCREEN, DEFAULT_LAYOUT, DEFAULT_LAYOUT_TEMPLATE, DEFAULT_NAVIGATION, DEFAULT_NAVIGATION_TEMPLATE, DEFAULT_PAGE, DEFAULT_SCREEN, DEFAULT_SCREEN_TEMPLATE, DEFAULT_TEMPLATE_EXTENSION, TEMPLATE_EXTENSIONS
 - 
Fields inherited from interface org.apache.turbine.services.velocity.VelocityServiceCATCH_ERRORS_DEFAULT, CATCH_ERRORS_KEY, CONTEXT, PIPELINEDATA_KEY, RUNDATA_KEY, SERVICE_NAME, VELOCITY_EXTENSION
 
- 
 - 
Constructor SummaryConstructors Constructor Description TurbineVelocityService()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.velocity.context.ContextgetContext()Create a Context object that also contains the globalContext.org.apache.velocity.context.ContextgetContext(PipelineData pipelineData)Create a Context from the PipelineData object.org.apache.velocity.context.ContextgetNewContext()This method returns a new, empty Context object.StringhandleRequest(org.apache.velocity.context.Context context, String filename)Process the request and fill in the template with the values you set in the Context.voidhandleRequest(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.voidhandleRequest(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.voidinit()Load all configured components and initialize them.ObjectmethodException(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.voidrequestFinished(org.apache.velocity.context.Context context)Performs post-request actions (releases context tools back to the object pool).protected voidsetVelocityProperties(org.apache.velocity.app.VelocityEngine velocity, org.apache.commons.configuration2.Configuration conf)This method generates the Properties object necessary for the initialization of Velocity.booleantemplateExists(String template)Find out if a given template exists.- 
Methods inherited from class org.apache.turbine.services.template.BaseTemplateEngineServicegetAssociatedFileExtensions, getTemplateEngineServiceConfiguration, initConfiguration, registerConfiguration
 - 
Methods inherited from class org.apache.turbine.services.TurbineBaseServiceinit, init, shutdown
 - 
Methods inherited from class org.apache.turbine.services.BaseServicegetConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 - 
Methods inherited from class org.apache.turbine.services.BaseInitablegetInit, getInitableBroker, setInit, setInitableBroker
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.turbine.services.InitablegetInit, init, setInitableBroker, shutdown
 - 
Methods inherited from interface org.apache.turbine.services.ServicegetConfiguration, getName, getProperties, setName, setServiceBroker
 
- 
 
- 
- 
- 
Constructor Detail- 
TurbineVelocityServicepublic TurbineVelocityService() 
 
- 
 - 
Method Detail- 
initpublic void init() throws InitializationException Load all configured components and initialize them. This is a zero parameter variant which queries the Turbine Servlet for its config.- Specified by:
- initin interface- Initable
- Overrides:
- initin class- TurbineBaseService
- Throws:
- InitializationException- Something went wrong in the init stage
 
 - 
getContextpublic org.apache.velocity.context.Context getContext() Create a Context object that also contains the globalContext.- Specified by:
- getContextin interface- VelocityService
- Returns:
- A Context object.
 
 - 
getNewContextpublic org.apache.velocity.context.Context getNewContext() This method returns a new, empty Context object.- Specified by:
- getNewContextin interface- VelocityService
- Returns:
- A Context Object.
 
 - 
methodExceptionpublic 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. It logs an exception thrown by the velocity processing on error level into the log file- Specified by:
- methodExceptionin interface- org.apache.velocity.app.event.MethodExceptionEventHandler
- Parameters:
- context- The current context
- clazz- The class that threw the exception
- method- The Method name that threw the exception
- e- The exception that would've been thrown
- info- Information about the template, line and column the exception occurred
- Returns:
- A valid value to be used as Return value
 
 - 
getContextpublic org.apache.velocity.context.Context getContext(PipelineData pipelineData) Create a Context from the PipelineData object. Adds a pointer to the PipelineData object to the VelocityContext so that PipelineData is available in the templates.- Specified by:
- getContextin interface- VelocityService
- Parameters:
- pipelineData- The Turbine PipelineData object.
- Returns:
- A clone of the WebContext needed by Velocity.
 
 - 
handleRequestpublic String handleRequest(org.apache.velocity.context.Context context, String filename) throws TurbineException Process the request and fill in the template with the values you set in the Context.- Specified by:
- handleRequestin interface- VelocityService
- Parameters:
- context- The populated context.
- filename- The file name of the template.
- Returns:
- The process template as a String.
- Throws:
- TurbineException- Any exception thrown while processing will be wrapped into a TurbineException and rethrown.
 
 - 
handleRequestpublic void handleRequest(org.apache.velocity.context.Context context, String filename, OutputStream output) throws TurbineException Process the request and fill in the template with the values you set in the Context.- Specified by:
- handleRequestin interface- VelocityService
- Parameters:
- 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.
- Throws:
- TurbineException- Any exception thrown while processing will be wrapped into a TurbineException and rethrown.
 
 - 
handleRequestpublic void handleRequest(org.apache.velocity.context.Context context, String filename, Writer writer) throws TurbineException Process the request and fill in the template with the values you set in the Context.- Specified by:
- handleRequestin interface- VelocityService
- Parameters:
- 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.
- Throws:
- TurbineException- Any exception thrown while processing will be wrapped into a TurbineException and rethrown.
 
 - 
setVelocityPropertiesprotected void setVelocityProperties(org.apache.velocity.app.VelocityEngine velocity, org.apache.commons.configuration2.Configuration conf) throws Exception This method generates the Properties object necessary for the initialization of Velocity. It also converts the various resource loader pathes into webapp relative pathes. It also- Parameters:
- velocity- The Velocity engine
- conf- The Velocity Service configuration
- Throws:
- Exception- If a problem occurred while converting the properties.
 
 - 
templateExistspublic boolean templateExists(String template) Find out if a given template exists. Velocity will do its own searching to determine whether a template exists or not.- Specified by:
- templateExistsin interface- TemplateEngineService
- Specified by:
- templateExistsin class- BaseTemplateEngineService
- Parameters:
- template- String template to search for
- Returns:
- True if the template can be loaded by Velocity
- See Also:
- TemplateEngineService.templateExists(java.lang.String)
 
 - 
requestFinishedpublic void requestFinished(org.apache.velocity.context.Context context) Performs post-request actions (releases context tools back to the object pool).- Specified by:
- requestFinishedin interface- VelocityService
- Parameters:
- context- a Velocity Context
 
 
- 
 
-