|
||||||||||
| 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.webmacro.TurbineWebMacroService
This is a Service that can process WebMacro templates from within a
Turbine Screen. Here's an example of how you might use it from a
screen:
WebContext context = WebMacro.getContext(data);
context.put("message", "Hello from Turbine!");
String results = WebMacro.handleRequest(context,"helloWorld.wm");
data.getPage().getBody().addElement(results);
Multiple template paths are specified via the
services.TurbineWebMacroService.templates property in the
TurbineResources.properties file, specified as a single string
delimited by the value of the System property path.separator
(this is : on UNIX and ; on Windows).
Turbine does not use the default ResourceProvider for WebMacro
ResourceEvents of type template. Instead, Turbine uses its own
TurbineTemplateProvider implementation.
| Field Summary | |
private org.webmacro.Broker |
broker
The broker used by WebMacro to retrieve resources. |
protected static java.lang.String |
DEFAULT_ENCODING
The default encoding used by the WebMacro FastWriter. |
private java.lang.String[] |
templatePaths
Paths where templates can be located. |
private org.webmacro.servlet.WebContext |
wcPrototype
The context used as a factory. |
private org.webmacro.WebMacro |
wm
The WebMacro engine. |
private java.lang.String |
WMProperties
Webmacro properties file. |
private java.lang.String |
WMTemplateProvider
WebMacro template provider. |
| 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.webmacro.WebMacroService |
SERVICE_NAME, WEBMACRO_CONTEXT |
| 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 | |
TurbineWebMacroService()
|
|
| Method Summary | |
org.webmacro.servlet.WebContext |
getContext()
Create an empty WebContext object. |
org.webmacro.servlet.WebContext |
getContext(RunData data)
Create a WebContext from the RunData
object. |
org.webmacro.Template |
getTemplate(java.lang.String filename)
Return a template from WebMacro. |
java.lang.String |
handleRequest(org.webmacro.servlet.WebContext wc,
java.lang.String filename)
Process the request and fill in the template with the values you set in the WebContext. |
void |
handleRequest(org.webmacro.servlet.WebContext wc,
java.lang.String filename,
org.webmacro.FastWriter writer)
Process the request and fill in the template with the values you set in the WebContext. |
void |
handleRequest(org.webmacro.servlet.WebContext wc,
java.lang.String filename,
java.io.OutputStream out)
Process the request and fill in the template with the values you set in the WebContext. |
void |
init(javax.servlet.ServletConfig unused)
Performs early initialization of this service. |
private void |
initWebContext()
This method must return a cloneable WebContext which can be cloned for use in responding to individual requests. |
private void |
initWebMacro()
This method returns the WebMacro object which will be used to load, access, and manage the Broker. |
void |
shutdown()
Shuts down the service, including its WebMacro engine. |
boolean |
templateExists(java.lang.String template)
Determine whether 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 |
| 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, getProperties, setName, setServiceBroker |
| Methods inherited from interface org.apache.turbine.services.Initable |
getInit, init, init, setInitableBroker |
| Field Detail |
protected static final java.lang.String DEFAULT_ENCODING
FastWriter.
We should encode the ouput byte stream as UTF-16 to
achieve the fastest conversion back to Java characters, but for some
reason this does not work (bug in FastWriter?). UTF-8
seems to work and is used as a fallback option.
private org.webmacro.WebMacro wm
private org.webmacro.servlet.WebContext wcPrototype
private org.webmacro.Broker broker
private java.lang.String[] templatePaths
private java.lang.String WMProperties
private java.lang.String WMTemplateProvider
| Constructor Detail |
public TurbineWebMacroService()
| Method Detail |
public void init(javax.servlet.ServletConfig unused)
throws InitializationException
init in class TurbineBaseServiceInitializationException - Caused by any initialization error.public void shutdown()
shutdown in interface Initableshutdown in class TurbineBaseServicepublic org.webmacro.servlet.WebContext getContext()
getContext in interface WebMacroServicepublic org.webmacro.servlet.WebContext getContext(RunData data)
WebContext from the RunData
object. Adds a pointer to the RunData object to
the WC so that RunData is available in the templates.getContext in interface WebMacroServicedata - The Turbine RunData object.
public java.lang.String handleRequest(org.webmacro.servlet.WebContext wc,
java.lang.String filename)
throws TurbineException
handleRequest in interface WebMacroServicewc - 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.webmacro.servlet.WebContext wc,
java.lang.String filename,
java.io.OutputStream out)
throws java.lang.Exception
handleRequest in interface WebMacroServicewc - The populated context.filename - The file name of the template.out - A stream to write the processed template to.TurbineException - Any exception trown while processing will be
wrapped into a TurbineException and rethrown.
public void handleRequest(org.webmacro.servlet.WebContext wc,
java.lang.String filename,
org.webmacro.FastWriter writer)
throws java.lang.Exception
handleRequest in interface WebMacroServicewc - The populated context.filename - The file name of the template.writer - A writer to write the processed template with.TurbineException - Any exception trown while processing will be
wrapped into a TurbineException and rethrown.
public org.webmacro.Template getTemplate(java.lang.String filename)
throws org.webmacro.NotFoundException
getTemplate in interface WebMacroServicefilename - A String with the name of the template.org.webmacro.NotFoundException - The template could not be found.
private void initWebMacro()
throws org.webmacro.InitException,
InitializationException
config - A ServletConfig.org.webmacro.InitException - Thrown by WebMacro.InitializationException - Thrown by Turbine.
private void initWebContext()
throws org.webmacro.InitException
InitException. - public boolean templateExists(java.lang.String template)
templateExists in class BaseTemplateEngineServiceString - template
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||