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
Field Summary |
private java.lang.String |
path
The base path prepended to filenames given in arguments. |
private freemarker.template.FileTemplateCache |
templateCache
A cache to store parsed templates. |
Method Summary |
void |
cacheUnavailable(freemarker.template.CacheEvent e)
Method called by templateCache. |
void |
elementRemoved(freemarker.template.CacheEvent e)
Method called by templateCache. |
void |
elementUpdated(freemarker.template.CacheEvent e)
Method called by templateCache. |
void |
elementUpdateFailed(freemarker.template.CacheEvent e)
Method called by templateCache. |
java.lang.String |
getBasePath()
Gets the base path for the FreeMarker templates. |
freemarker.template.Template |
getCachedTemplate(java.lang.String templateName)
Return a FreeMarker template from the cache. |
freemarker.template.SimpleHash |
getContext()
Create a context needed by the FreeMarker template. |
freemarker.template.SimpleHash |
getContext(RunData data)
Create a context from the RunData object. |
freemarker.template.SimpleHash |
getContext(javax.servlet.ServletRequest req)
Create a context needed by the FreeMarker template. |
freemarker.template.Template |
getNonCachedTemplate(java.lang.String templateName)
Return a FreeMarker template. |
java.lang.String |
handleRequest(freemarker.template.SimpleHash context,
java.lang.String filename,
boolean cache)
Process the request and fill in the template with the values
you set in the WebContext. |
void |
init()
Called during Turbine.init() |
private void |
initFreeMarker()
This method sets up the FreeMarker template cache. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
templateCache
private freemarker.template.FileTemplateCache templateCache
- A cache to store parsed templates.
path
private java.lang.String path
- The base path prepended to filenames given in arguments.
TurbineFreeMarkerService
public TurbineFreeMarkerService()
- Constructor.
init
public void init()
throws InitializationException
- 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()
- 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)
- 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)
- 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
- 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()
- 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)
- 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
- 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.
initFreeMarker
private void initFreeMarker()
throws java.lang.Exception
- This method sets up the FreeMarker template cache.
- Parameters:
config
- A ServletConfig.- Throws:
Exception,
- a generic exception.
cacheUnavailable
public void cacheUnavailable(freemarker.template.CacheEvent e)
- Method called by templateCache.
- Specified by:
cacheUnavailable
in interface freemarker.template.CacheListener
- Parameters:
e
- A CacheEvent.
elementUpdated
public void elementUpdated(freemarker.template.CacheEvent e)
- Method called by templateCache.
- Specified by:
elementUpdated
in interface freemarker.template.CacheListener
- Parameters:
e
- A CacheEvent.
elementUpdateFailed
public void elementUpdateFailed(freemarker.template.CacheEvent e)
- Method called by templateCache.
- Specified by:
elementUpdateFailed
in interface freemarker.template.CacheListener
- Parameters:
e
- A CacheEvent.
elementRemoved
public void elementRemoved(freemarker.template.CacheEvent e)
- 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.