org.apache.turbine.services.webmacro
Class TurbineWebMacroService

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
All Implemented Interfaces:
Initable, Service, TemplateEngineService, WebMacroService

public class TurbineWebMacroService
extends BaseTemplateEngineService
implements WebMacroService

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.

Version:
$Id: TurbineWebMacroService.java,v 1.5 2002/08/14 16:44:09 henning Exp $
Author:
Dave Bryson, Rafal Krzewski, Daniel Rall, Jason van Zyl

Field Summary
protected static java.lang.String DEFAULT_ENCODING
          Deprecated. The default encoding used by the WebMacro FastWriter.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, 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()
          Deprecated.  
 
Method Summary
 org.webmacro.servlet.WebContext getContext()
          Deprecated. Create an empty WebContext object.
 org.webmacro.servlet.WebContext getContext(RunData data)
          Deprecated. Create a WebContext from the RunData object.
 org.webmacro.Template getTemplate(java.lang.String filename)
          Deprecated. Return a template from WebMacro.
 java.lang.String handleRequest(org.webmacro.servlet.WebContext wc, java.lang.String filename)
          Deprecated. 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)
          Deprecated. 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)
          Deprecated. Process the request and fill in the template with the values you set in the WebContext.
 void init()
          Deprecated. Load all configured components and initialize them.
 void init(javax.servlet.ServletConfig unused)
          Deprecated. Inits the service using servlet parameters to obtain path to the configuration file.
 void shutdown()
          Deprecated. Shuts down the service, including its WebMacro engine.
 boolean templateExists(java.lang.String template)
          Deprecated. 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
 
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
 

Field Detail

DEFAULT_ENCODING

protected static final java.lang.String DEFAULT_ENCODING
Deprecated. 
The default encoding used by the WebMacro 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.

Constructor Detail

TurbineWebMacroService

public TurbineWebMacroService()
Deprecated. 
Method Detail

init

public void init()
          throws InitializationException
Deprecated. 
Load all configured components and initialize them. This is a zero parameter variant which queries the Turbine Servlet for its config.
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Throws:
InitializationException - Something went wrong in the init stage

init

public void init(javax.servlet.ServletConfig unused)
          throws InitializationException
Deprecated. 
Inits the service using servlet parameters to obtain path to the configuration file.
Overrides:
init in class TurbineBaseService
Parameters:
config - The ServletConfiguration from Turbine
Throws:
InitializationException - Something went wrong when starting up.

shutdown

public void shutdown()
Deprecated. 
Shuts down the service, including its WebMacro engine.
Specified by:
shutdown in interface Initable
Overrides:
shutdown in class TurbineBaseService

getContext

public org.webmacro.servlet.WebContext getContext()
Deprecated. 
Create an empty WebContext object.
Specified by:
getContext in interface WebMacroService
Returns:
A new, empty context.

getContext

public org.webmacro.servlet.WebContext getContext(RunData data)
Deprecated. 
Create a WebContext 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 WebMacroService
Parameters:
data - The Turbine RunData object.
Returns:
A clone of the WebContext needed by WebMacro.

handleRequest

public java.lang.String handleRequest(org.webmacro.servlet.WebContext wc,
                                      java.lang.String filename)
                               throws TurbineException
Deprecated. 
Process the request and fill in the template with the values you set in the WebContext.
Specified by:
handleRequest in interface WebMacroService
Parameters:
wc - 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.webmacro.servlet.WebContext wc,
                          java.lang.String filename,
                          java.io.OutputStream out)
                   throws java.lang.Exception
Deprecated. 
Process the request and fill in the template with the values you set in the WebContext.
Specified by:
handleRequest in interface WebMacroService
Parameters:
wc - The populated context.
filename - The file name of the template.
out - A stream to write the processed template to.
Throws:
TurbineException - Any exception trown while processing will be wrapped into a TurbineException and rethrown.

handleRequest

public void handleRequest(org.webmacro.servlet.WebContext wc,
                          java.lang.String filename,
                          org.webmacro.FastWriter writer)
                   throws java.lang.Exception
Deprecated. 
Process the request and fill in the template with the values you set in the WebContext.
Specified by:
handleRequest in interface WebMacroService
Parameters:
wc - The populated context.
filename - The file name of the template.
writer - A writer to write the processed template with.
Throws:
TurbineException - Any exception trown while processing will be wrapped into a TurbineException and rethrown.

getTemplate

public org.webmacro.Template getTemplate(java.lang.String filename)
                                  throws org.webmacro.NotFoundException
Deprecated. 
Return a template from WebMacro.
Specified by:
getTemplate in interface WebMacroService
Parameters:
filename - A String with the name of the template.
Returns:
A Template.
Throws:
org.webmacro.NotFoundException - The template could not be found.

templateExists

public boolean templateExists(java.lang.String template)
Deprecated. 
Determine whether a given template exists. This service currently only supports file base template hierarchies so we will use the utility methods provided by the template service to do the searching.
Overrides:
templateExists in class BaseTemplateEngineService
Parameters:
String - template
Returns:
boolean


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