org.apache.turbine.services.velocity
Class TurbineVelocity

java.lang.Object
  extended byorg.apache.turbine.services.velocity.TurbineVelocity

public abstract class TurbineVelocity
extends java.lang.Object

This is a simple static accessor to common Velocity tasks such as getting an instance of a context as well as handling a request for processing a template.

 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: TurbineVelocity.java 534527 2007-05-02 16:10:59Z tv $
Author:
John D. McNally, Jon S. Stevens, Jason van Zyl

Constructor Summary
TurbineVelocity()
           
 
Method Summary
static org.apache.velocity.context.Context getContext()
          This method returns a blank Context object, which also contains the global context object.
static org.apache.velocity.context.Context getContext(RunData data)
          This returns a Context that you can pass into handleRequest once you have populated it with information that the template will know about.
static org.apache.velocity.context.Context getNewContext()
          This method returns a new, empty Context object.
static VelocityService getService()
          Utility method for accessing the service implementation
static java.lang.String handleRequest(org.apache.velocity.context.Context context, java.lang.String template)
          This allows you to pass in a context and a path to a template file and then grabs an instance of the velocity service and processes the template and returns the results as a String object.
static void handleRequest(org.apache.velocity.context.Context context, java.lang.String template, java.io.OutputStream out)
          Process the request and fill in the template with the values you set in the Context.
static void handleRequest(org.apache.velocity.context.Context context, java.lang.String template, java.io.Writer writer)
          Process the request and fill in the template with the values you set in the Context.
static void requestFinished(org.apache.velocity.context.Context context)
          Performs post-request actions (releases context tools back to the object pool).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurbineVelocity

public TurbineVelocity()
Method Detail

getService

public static VelocityService getService()
Utility method for accessing the service implementation

Returns:
a VelocityService implementation instance

handleRequest

public static java.lang.String handleRequest(org.apache.velocity.context.Context context,
                                             java.lang.String template)
                                      throws java.lang.Exception
This allows you to pass in a context and a path to a template file and then grabs an instance of the velocity service and processes the template and returns the results as a String object.

Parameters:
context - A Context.
template - The path for the template files.
Returns:
A String.
Throws:
java.lang.Exception - a generic exception.

handleRequest

public static void handleRequest(org.apache.velocity.context.Context context,
                                 java.lang.String template,
                                 java.io.OutputStream out)
                          throws java.lang.Exception
Process the request and fill in the template with the values you set in the Context.

Parameters:
context - A Context.
template - A String with the filename of the template.
out - A OutputStream where we will write the process template as a String.
Throws:
java.lang.Exception - a generic exception.

handleRequest

public static void handleRequest(org.apache.velocity.context.Context context,
                                 java.lang.String template,
                                 java.io.Writer writer)
                          throws java.lang.Exception
Process the request and fill in the template with the values you set in the Context.

Parameters:
context - A Context.
template - A String with the filename of the template.
writer - A Writer where we will write the process template as a String.
Throws:
java.lang.Exception - a generic exception.

getContext

public static org.apache.velocity.context.Context getContext(RunData data)
This returns a Context that you can pass into handleRequest once you have populated it with information that the template will know about.

Parameters:
data - A Turbine RunData.
Returns:
A Context.

getContext

public static org.apache.velocity.context.Context getContext()
This method returns a blank Context object, which also contains the global context object. Do not use this method if you need an empty context object! Use getNewContext for this.

Returns:
A WebContext.

getNewContext

public static org.apache.velocity.context.Context getNewContext()
This method returns a new, empty Context object.

Returns:
A WebContext.

requestFinished

public static void requestFinished(org.apache.velocity.context.Context context)
Performs post-request actions (releases context tools back to the object pool).

Parameters:
context - a Velocity Context


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.