org.apache.turbine.services.velocity
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
- public class TurbineVelocityService
- extends BaseTemplateEngineService
- implements VelocityService
This is a Service that can process Velocity templates from within a
Turbine Screen. 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: TurbineVelocityService.java,v 1.8 2002/07/11 16:53:23 mpoeschl Exp $
- Author:
- Dave Bryson, Rafal Krzewski, Jason van Zyl, Sean Legassick, Daniel Rall
Method Summary |
org.apache.velocity.context.Context |
getContext()
Create a Context object that also contains the globalContext. |
org.apache.velocity.context.Context |
getContext(RunData data)
Create a Context from the RunData object. |
java.lang.String |
handleRequest(org.apache.velocity.context.Context context,
java.lang.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,
java.lang.String filename,
java.io.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,
java.lang.String filename,
java.io.Writer writer)
Process the request and fill in the template with the values
you set in the Context. |
void |
init(javax.servlet.ServletConfig config)
Performs early initialization of this Turbine service. |
void |
requestFinished(org.apache.velocity.context.Context context)
Performs post-request actions (releases context
tools back to the object pool). |
boolean |
templateExists(java.lang.String template)
Find out if a given template exists. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TurbineVelocityService
public TurbineVelocityService()
init
public void init(javax.servlet.ServletConfig config)
throws InitializationException
- Performs early initialization of this Turbine service.
- Overrides:
init
in class TurbineBaseService
- Following copied from class:
org.apache.turbine.services.TurbineBaseService
- Parameters:
config
- A ServletConfing to use for initialization
activities.- Throws:
InitializationException,
- if initialization of this
class was not successful.
getContext
public org.apache.velocity.context.Context getContext()
- Create a Context object that also contains the globalContext.
- Specified by:
getContext
in interface VelocityService
- Returns:
- A Context object.
getContext
public org.apache.velocity.context.Context getContext(RunData data)
- Create a Context from the RunData object. Adds a pointer to
the RunData object to the WC so that RunData is available in
the templates.
- Specified by:
getContext
in interface VelocityService
- Parameters:
data
- The Turbine RunData object.- Returns:
- A clone of the WebContext needed by Velocity.
handleRequest
public java.lang.String handleRequest(org.apache.velocity.context.Context context,
java.lang.String filename)
throws TurbineException
- Process the request and fill in the template with the values
you set in the Context.
- Specified by:
handleRequest
in 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 trown while processing will be
wrapped into a TurbineException and rethrown.
handleRequest
public void handleRequest(org.apache.velocity.context.Context context,
java.lang.String filename,
java.io.OutputStream output)
throws TurbineException
- Process the request and fill in the template with the values
you set in the Context.
- Specified by:
handleRequest
in interface VelocityService
- Parameters:
context
- A Context.filename
- A String with the filename of the template.out
- A OutputStream where we will write the process template as
a String.- Throws:
TurbineException
- Any exception trown while processing will be
wrapped into a TurbineException and rethrown.
handleRequest
public void handleRequest(org.apache.velocity.context.Context context,
java.lang.String filename,
java.io.Writer writer)
throws TurbineException
- Process the request and fill in the template with the values
you set in the Context.
- Specified by:
handleRequest
in 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 trown while processing will be
wrapped into a TurbineException and rethrown.
templateExists
public boolean templateExists(java.lang.String template)
- Find out if a given template exists. Velocity
will do its own searching to determine whether
a template exists or not.
- Overrides:
templateExists
in class BaseTemplateEngineService
- Parameters:
String
- template to search for- Returns:
- boolean
requestFinished
public void requestFinished(org.apache.velocity.context.Context context)
- Performs post-request actions (releases context
tools back to the object pool).
- Specified by:
requestFinished
in interface VelocityService
- Parameters:
context
- a Velocity Context
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.