|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | 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. 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);
Nested Class Summary |
Nested classes inherited from class org.apache.velocity.app.event.MethodExceptionEventHandler |
org.apache.velocity.app.event.MethodExceptionEventHandler.MethodExceptionExecutor |
Field Summary |
Fields inherited from class org.apache.turbine.services.BaseService |
name, serviceBroker |
Fields inherited from class org.apache.turbine.services.BaseInitable |
initableBroker, isInitialized |
Fields inherited from interface org.apache.turbine.services.velocity.VelocityService |
CATCH_ERRORS_DEFAULT, CATCH_ERRORS_KEY, CONTEXT, RUNDATA_KEY, SERVICE_NAME, VELOCITY_EXTENSION |
Fields inherited from interface org.apache.turbine.services.template.TemplateEngineService |
DEFAULT_ERROR_SCREEN, DEFAULT_LAYOUT, DEFAULT_LAYOUT_TEMPLATE, DEFAULT_NAVIGATION, DEFAULT_NAVIGATION_TEMPLATE, DEFAULT_PAGE, DEFAULT_SCREEN, DEFAULT_SCREEN_TEMPLATE, DEFAULT_TEMPLATE_EXTENSION, TEMPLATE_EXTENSIONS |
Constructor Summary | |
TurbineVelocityService()
|
Method Summary | |
org.apache.commons.collections.ExtendedProperties |
createVelocityProperties(org.apache.commons.configuration.Configuration conf)
This method generates the Extended Properties object necessary for the initialization of Velocity. |
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. |
org.apache.velocity.context.Context |
getNewContext()
This method returns a new, empty Context 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()
Load all configured components and initialize them. |
void |
init(javax.servlet.ServletConfig config)
Deprecated. use init() instead. |
java.lang.Object |
methodException(java.lang.Class clazz,
java.lang.String method,
java.lang.Exception e)
MethodException Event Cartridge handler for Velocity. |
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, 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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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, setInitableBroker, shutdown |
Constructor Detail |
public TurbineVelocityService()
Method Detail |
public void init() throws InitializationException
init
in interface Initable
init
in class TurbineBaseService
InitializationException
- Something went wrong in the init
stagepublic void init(javax.servlet.ServletConfig config) throws InitializationException
init
in class TurbineBaseService
config
- The ServletConfiguration from Turbine
InitializationException
- Something went wrong when starting up.public org.apache.velocity.context.Context getContext()
getContext
in interface VelocityService
public org.apache.velocity.context.Context getNewContext()
getNewContext
in interface VelocityService
public java.lang.Object methodException(java.lang.Class clazz, java.lang.String method, java.lang.Exception e) throws java.lang.Exception
methodException
in interface org.apache.velocity.app.event.MethodExceptionEventHandler
clazz
- The class that threw the exceptionmethod
- The Method name that threw the exceptione
- The exception that would've been thrown
java.lang.Exception
- We threw the exception further uppublic 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.output
- 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.public org.apache.commons.collections.ExtendedProperties createVelocityProperties(org.apache.commons.configuration.Configuration conf) throws java.lang.Exception
conf
- The Velocity Service configuration
java.lang.Exception
- If a problem occured while converting the properties.public boolean templateExists(java.lang.String template)
templateExists
in interface TemplateEngineService
templateExists
in class BaseTemplateEngineService
template
- String template to search for
TemplateEngineService.templateExists(java.lang.String)
public void requestFinished(org.apache.velocity.context.Context context)
requestFinished
in interface VelocityService
context
- a Velocity Context
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |