|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
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);
Field Summary | |
private static java.lang.String |
ABSOLUTE_PREFIX
The prefix used for URIs which are of type absolute . |
private static java.lang.String |
DEFAULT_CHAR_SET
Default character set to use if not specified in the RunData object. |
private org.apache.velocity.context.Context |
globalContext
The context used to the store the context containing the global application tools. |
private static java.lang.String |
JAR_PREFIX
The prefix used for URIs which are of type jar . |
private boolean |
pullModelActive
Is the pullModelActive. |
private boolean |
refreshToolsPerRequest
Should we refresh the tools on a per request basis. |
private static java.lang.String |
RESOURCE_LOADER_PATH
The generic resource loader path property in velocity. |
Fields inherited from class org.apache.turbine.services.template.BaseTemplateEngineService |
configuration |
Fields inherited from class org.apache.turbine.services.BaseService |
name, properties, serviceBroker |
Fields inherited from class org.apache.turbine.services.BaseInitable |
initableBroker, isInitialized |
Fields inherited from interface org.apache.turbine.services.velocity.VelocityService |
CONTEXT, SERVICE_NAME |
Fields inherited from interface org.apache.turbine.services.template.TemplateEngineService |
DEFAULT_ERROR_SCREEN, DEFAULT_LAYOUT, DEFAULT_LAYOUT_TEMPLATE, DEFAULT_NAVIGATION, DEFAULT_PAGE, DEFAULT_SCREEN, DEFAULT_TEMPLATE_EXTENSION, TEMPLATE_EXTENSIONS |
Constructor Summary | |
TurbineVelocityService()
|
Method Summary | |
private java.lang.String |
decodeRequest(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. |
private void |
decodeRequest(org.apache.velocity.context.Context context,
java.lang.String filename,
java.lang.String encoding,
java.io.Writer writer)
Process the request and fill in the template with the values you set in the Context. |
private java.lang.String |
getCharSet(org.apache.velocity.context.Context context)
Retrieve the required charset from the Turbine RunData in the context |
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. |
private java.lang.String |
getEncoding(org.apache.velocity.context.Context context)
Retrieve the required encoding from the Turbine RunData in the context |
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. |
private void |
initVelocity()
Setup the velocity runtime by using a subset of the Turbine configuration which relates to velocity. |
private static void |
renderingError(java.lang.String filename,
java.lang.Exception e)
Macro to handle rendering errors. |
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 org.apache.turbine.services.template.BaseTemplateEngineService |
getAssociatedFileExtensions, getTemplateEngineServiceConfiguration, initConfiguration, registerConfiguration |
Methods inherited from class org.apache.turbine.services.TurbineBaseService |
init, init, init, shutdown |
Methods inherited from class org.apache.turbine.services.BaseService |
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker |
Methods inherited from class org.apache.turbine.services.BaseInitable |
getInit, getInitableBroker, setInit, setInitableBroker |
Methods inherited from class java.lang.Object |
|
Methods inherited from interface org.apache.turbine.services.Service |
getConfiguration, getName, getProperties, setName, setServiceBroker |
Methods inherited from interface org.apache.turbine.services.Initable |
getInit, init, init, setInitableBroker, shutdown |
Field Detail |
private static final java.lang.String RESOURCE_LOADER_PATH
private static final java.lang.String DEFAULT_CHAR_SET
private static final java.lang.String JAR_PREFIX
jar
.private static final java.lang.String ABSOLUTE_PREFIX
absolute
.private org.apache.velocity.context.Context globalContext
private boolean pullModelActive
private boolean refreshToolsPerRequest
Constructor Detail |
public TurbineVelocityService()
Method Detail |
public void init(javax.servlet.ServletConfig config) throws InitializationException
init
in class TurbineBaseService
org.apache.turbine.services.TurbineBaseService
config
- A ServletConfing to use for initialization
activities.InitializationException,
- if initialization of this
class was not successful.public org.apache.velocity.context.Context getContext()
getContext
in interface VelocityService
public org.apache.velocity.context.Context getContext(RunData data)
getContext
in interface VelocityService
data
- The Turbine RunData object.public java.lang.String handleRequest(org.apache.velocity.context.Context context, java.lang.String filename) throws TurbineException
handleRequest
in interface VelocityService
context
- The populated context.filename
- The file name of the template.TurbineException
- Any exception trown while processing will be
wrapped into a TurbineException and rethrown.public void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.OutputStream output) throws TurbineException
handleRequest
in interface VelocityService
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.TurbineException
- Any exception trown while processing will be
wrapped into a TurbineException and rethrown.public void handleRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.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 trown while processing will be
wrapped into a TurbineException and rethrown.private java.lang.String decodeRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.io.OutputStream output) throws TurbineException
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.TurbineException
- Any exception trown while processing will be
wrapped into a TurbineException and rethrown.private java.lang.String getCharSet(org.apache.velocity.context.Context context)
context
- A Context.private java.lang.String getEncoding(org.apache.velocity.context.Context context)
context
- A Context.private void decodeRequest(org.apache.velocity.context.Context context, java.lang.String filename, java.lang.String encoding, java.io.Writer writer) throws TurbineException
context
- A Context.filename
- A String with the filename of the template.encoding
- The encoding to use with the templatewriter
- A Writer where we will write the process template as
a String. This writer charset should be compatible with the selected
encodingTurbineException
- Any exception trown while processing will be
wrapped into a TurbineException and rethrown.private static final void renderingError(java.lang.String filename, java.lang.Exception e) throws TurbineException
filename
- The file name of the unrenderable template.e
- The error.TurbineException
- Thrown every time. Adds additional
information to e
.private void initVelocity() throws InitializationException
InitializationException
- For any errors during initialization.public boolean templateExists(java.lang.String template)
templateExists
in class BaseTemplateEngineService
String
- template to search forpublic void requestFinished(org.apache.velocity.context.Context context)
requestFinished
in interface VelocityService
context
- a Velocity Context
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |