| org.apache.turbine.services.template.BaseTemplateEngineService org.apache.turbine.services.velocity.TurbineVelocityService
TurbineVelocityService | public class TurbineVelocityService extends BaseTemplateEngineService implements VelocityService,MethodExceptionEventHandler(Code) | | 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);
author: Dave Bryson author: Rafal Krzewski author: Jason van Zyl author: Sean Legassick author: Daniel Rall author: Henning P. Schmiedehausen version: $Id: TurbineVelocityService.java 552336 2007-07-01 16:33:47Z tv $ |
Method Summary | |
public ExtendedProperties | createVelocityProperties(Configuration conf) This method generates the Extended Properties object necessary
for the initialization of Velocity. | public Context | getContext() Create a Context object that also contains the globalContext. | public Context | getContext(RunData data) Create a Context from the RunData object. | public Context | getNewContext() This method returns a new, empty Context object. | public String | handleRequest(Context context, String filename) Process the request and fill in the template with the values
you set in the Context.
Parameters: context - The populated context. Parameters: filename - The file name of the template. | public void | handleRequest(Context context, String filename, OutputStream output) Process the request and fill in the template with the values
you set in the Context. | public void | handleRequest(Context context, String filename, Writer writer) Process the request and fill in the template with the values
you set in the Context. | public void | init() Load all configured components and initialize them. | public void | init(ServletConfig config) Inits the service using servlet parameters to obtain path to the
configuration file. | public Object | methodException(Class clazz, String method, Exception e) MethodException Event Cartridge handler
for Velocity. | public void | requestFinished(Context context) Performs post-request actions (releases context
tools back to the object pool). | public boolean | templateExists(String template) Find out if a given template exists. |
createVelocityProperties | public ExtendedProperties createVelocityProperties(Configuration conf) throws Exception(Code) | | This method generates the Extended Properties object necessary
for the initialization of Velocity. It also converts the various
resource loader pathes into webapp relative pathes. It also
Parameters: conf - The Velocity Service configuration An ExtendedProperties Object for Velocity throws: Exception - If a problem occured while converting the properties. |
getContext | public Context getContext()(Code) | | Create a Context object that also contains the globalContext.
A Context object. |
getContext | public Context getContext(RunData data)(Code) | | Create a Context from the RunData object. Adds a pointer to
the RunData object to the VelocityContext so that RunData
is available in the templates.
Parameters: data - The Turbine RunData object. A clone of the WebContext needed by Velocity. |
getNewContext | public Context getNewContext()(Code) | | This method returns a new, empty Context object.
A Context Object. |
handleRequest | public String handleRequest(Context context, String filename) throws TurbineException(Code) | | Process the request and fill in the template with the values
you set in the Context.
Parameters: context - The populated context. Parameters: filename - The file name of the template. The process template as a String. throws: TurbineException - Any exception trown while processing will bewrapped into a TurbineException and rethrown. |
handleRequest | public void handleRequest(Context context, String filename, OutputStream output) throws TurbineException(Code) | | Process the request and fill in the template with the values
you set in the Context.
Parameters: context - A Context. Parameters: filename - A String with the filename of the template. Parameters: output - A OutputStream where we will write the process template asa String. throws: TurbineException - Any exception trown while processing will bewrapped into a TurbineException and rethrown. |
handleRequest | public void handleRequest(Context context, String filename, Writer writer) throws TurbineException(Code) | | Process the request and fill in the template with the values
you set in the Context.
Parameters: context - A Context. Parameters: filename - A String with the filename of the template. Parameters: writer - A Writer where we will write the process template asa String. throws: TurbineException - Any exception trown while processing will bewrapped into a TurbineException and rethrown. |
init | public void init() throws InitializationException(Code) | | Load all configured components and initialize them. This is
a zero parameter variant which queries the Turbine Servlet
for its config.
throws: InitializationException - Something went wrong in the initstage |
methodException | public Object methodException(Class clazz, String method, Exception e) throws Exception(Code) | | MethodException Event Cartridge handler
for Velocity.
It logs an execption thrown by the velocity processing
on error level into the log file
Parameters: clazz - The class that threw the exception Parameters: method - The Method name that threw the exception Parameters: e - The exception that would've been thrown A valid value to be used as Return value throws: Exception - We threw the exception further up |
requestFinished | public void requestFinished(Context context)(Code) | | Performs post-request actions (releases context
tools back to the object pool).
Parameters: context - a Velocity Context |
templateExists | public boolean templateExists(String template)(Code) | | Find out if a given template exists. Velocity
will do its own searching to determine whether
a template exists or not.
Parameters: template - String template to search for True if the template can be loaded by Velocity |
|
|