org.apache.turbine.services.freemarker
Class TurbineFreeMarkerService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.apache.turbine.services.freemarker.TurbineFreeMarkerService
All Implemented Interfaces:
freemarker.template.CacheListener, java.util.EventListener, FreeMarkerService, Initable, Service

public class TurbineFreeMarkerService
extends TurbineBaseService
implements FreeMarkerService, freemarker.template.CacheListener

This is a Service that can process FreeMarker templates from within a Turbine Screen. Here's an example of how you might use it from a screen:
FreeMarkerService fm = (FreeMarkerService)TurbineServices.getInstance() .getService(FreeMarkerService.SERVICE_NAME); SimpleHash context = fm.getContext(data); context.put("message", "Hello from Turbine!"); String results = fm.handleRequest(context,"helloWorld.wm"); data.getPage().getBody().addElement(results);

Version:
$Id: TurbineFreeMarkerService.java,v 1.6 2002/07/16 16:38:13 henning Exp $
Author:
John D. McNally, Jason van Zyl

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.freemarker.FreeMarkerService
CONTEXT, SERVICE_NAME
 
Constructor Summary
TurbineFreeMarkerService()
          Deprecated. Constructor.
 
Method Summary
 void cacheUnavailable(freemarker.template.CacheEvent e)
          Deprecated. Method called by templateCache.
 void elementRemoved(freemarker.template.CacheEvent e)
          Deprecated. Method called by templateCache.
 void elementUpdated(freemarker.template.CacheEvent e)
          Deprecated. Method called by templateCache.
 void elementUpdateFailed(freemarker.template.CacheEvent e)
          Deprecated. Method called by templateCache.
 java.lang.String getBasePath()
          Deprecated. Gets the base path for the FreeMarker templates.
 freemarker.template.Template getCachedTemplate(java.lang.String templateName)
          Deprecated. Return a FreeMarker template from the cache.
 freemarker.template.SimpleHash getContext()
          Deprecated. Create a context needed by the FreeMarker template.
 freemarker.template.SimpleHash getContext(RunData data)
          Deprecated. Create a context from the RunData object.
 freemarker.template.SimpleHash getContext(javax.servlet.ServletRequest req)
          Deprecated. Create a context needed by the FreeMarker template.
 freemarker.template.Template getNonCachedTemplate(java.lang.String templateName)
          Deprecated. Return a FreeMarker template.
 java.lang.String handleRequest(freemarker.template.SimpleHash context, java.lang.String filename, boolean cache)
          Deprecated. Process the request and fill in the template with the values you set in the WebContext.
 void init()
          Deprecated. Called during Turbine.init()
 
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
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

TurbineFreeMarkerService

public TurbineFreeMarkerService()
Deprecated. 
Constructor.
Method Detail

init

public void init()
          throws InitializationException
Deprecated. 
Called during Turbine.init()
Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Parameters:
config - A ServletConfig.

getContext

public freemarker.template.SimpleHash getContext()
Deprecated. 
Create a context needed by the FreeMarker template. This method just returns an SimpleHash with the request parameters copied into a model called request.
Specified by:
getContext in interface FreeMarkerService
Returns:
SimpleHash which can be used as the model for a template.

getContext

public freemarker.template.SimpleHash getContext(javax.servlet.ServletRequest req)
Deprecated. 
Create a context needed by the FreeMarker template. This method just returns an SimpleHash with the request parameters copied into a model called request.
Specified by:
getContext in interface FreeMarkerService
Parameters:
req - A ServletRequest.
Returns:
SimpleHash which can be used as the model for a template.

getContext

public freemarker.template.SimpleHash getContext(RunData data)
Deprecated. 
Create a context from the RunData object. Values found in RunData are copied into the modelRoot under similar names as they can be found in RunData. e.g. data.serverName, data.parameters.form_field_name data.acl.permissions.can_write_file. Some default links are also made available under links.
Specified by:
getContext in interface FreeMarkerService
Parameters:
data - The Turbine RunData object.
Returns:
a SimpleHash populated with RunData data.

handleRequest

public java.lang.String handleRequest(freemarker.template.SimpleHash context,
                                      java.lang.String filename,
                                      boolean cache)
                               throws TurbineException
Deprecated. 
Process the request and fill in the template with the values you set in the WebContext.
Specified by:
handleRequest in interface FreeMarkerService
Parameters:
context - A SimpleHash with the context.
templateName - A String with the filename of the template.
cache - True if the parsed template should be cached.
Returns:
The processed template as a String.
Throws:
TurbineException - Any exception trown while processing will be wrapped into a TurbineException and rethrown.

getBasePath

public java.lang.String getBasePath()
Deprecated. 
Gets the base path for the FreeMarker templates.
Specified by:
getBasePath in interface FreeMarkerService
Returns:
The base path for the FreeMarker templates.

getCachedTemplate

public freemarker.template.Template getCachedTemplate(java.lang.String templateName)
Deprecated. 
Return a FreeMarker template from the cache. If the template has not been cached yet, it will be added to the cache.
Specified by:
getCachedTemplate in interface FreeMarkerService
Parameters:
templateName - A String with the name of the template.
Returns:
A Template.

getNonCachedTemplate

public freemarker.template.Template getNonCachedTemplate(java.lang.String templateName)
                                                  throws java.io.IOException
Deprecated. 
Return a FreeMarker template. It will not be added to the cache.
Specified by:
getNonCachedTemplate in interface FreeMarkerService
Parameters:
templateName - A String with the name of the template.
Returns:
A Template.
Throws:
IOException, - if there was an I/O problem.

cacheUnavailable

public void cacheUnavailable(freemarker.template.CacheEvent e)
Deprecated. 
Method called by templateCache.
Specified by:
cacheUnavailable in interface freemarker.template.CacheListener
Parameters:
e - A CacheEvent.

elementUpdated

public void elementUpdated(freemarker.template.CacheEvent e)
Deprecated. 
Method called by templateCache.
Specified by:
elementUpdated in interface freemarker.template.CacheListener
Parameters:
e - A CacheEvent.

elementUpdateFailed

public void elementUpdateFailed(freemarker.template.CacheEvent e)
Deprecated. 
Method called by templateCache.
Specified by:
elementUpdateFailed in interface freemarker.template.CacheListener
Parameters:
e - A CacheEvent.

elementRemoved

public void elementRemoved(freemarker.template.CacheEvent e)
Deprecated. 
Method called by templateCache.
Specified by:
elementRemoved in interface freemarker.template.CacheListener
Parameters:
e - A CacheEvent.


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