org.webmacro.resource
Class ServletContextTemplateLoader
java.lang.Object
org.webmacro.resource.AbstractTemplateLoader
org.webmacro.resource.ServletContextTemplateLoader
- All Implemented Interfaces:
- TemplateLoader
- public class ServletContextTemplateLoader
- extends AbstractTemplateLoader
Implementation of TemplateLoader that loads template from web-apps.
This will require a broker that is an instance of org.webmacro.servlet.ServletBroker
to have access to the ServletContext.
Templates will be loaded by ServletContext.getResource().
The "path" setting is used as a prefix for all request, so it should
end with a slash.
Example: If you have
webapp:/WEB-INF/templates/
as a
TemplateLoaderPath and request the template "foo/bar.wm", it will search for
"WEB-INF/templates/foo/bar.wm" in your web-app directory.
This TemplateLoader will automatically add trailing and starting slashed, if they
are missing. The starting slash is required by the servlet specification.
- Author:
- Sebastian Kanthak (sebastian.kanthak@muehlheim.de)
Method Summary |
void |
init(Broker broker,
Settings config)
Sets up broker, reloadDelayDecorator and log. |
Template |
load(java.lang.String query,
CacheElement ce)
Try to load a template. |
void |
setConfig(java.lang.String config)
Set the config options for this template loader. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ServletContextTemplateLoader
public ServletContextTemplateLoader()
init
public void init(Broker broker,
Settings config)
throws InitException
- Description copied from class:
AbstractTemplateLoader
- Sets up broker, reloadDelayDecorator and log.
Don't forget to call super.init() if you override this
method.
- Specified by:
init
in interface TemplateLoader
- Overrides:
init
in class AbstractTemplateLoader
- Throws:
InitException
setConfig
public void setConfig(java.lang.String config)
- Description copied from interface:
TemplateLoader
- Set the config options for this template loader.
The config option is the path after the colon (":") in
the TemplatePath setting for this loader.
This can be an path as well as JDBC settings or something
completely different.
- Parameters:
config
- config options for this template loader
load
public Template load(java.lang.String query,
CacheElement ce)
throws ResourceException
- Description copied from interface:
TemplateLoader
- Try to load a template.
This method will create and return a template found in the location
described by query or return null, if no such template exists. If
a resource is found at the location, but no template could be created
for some reason, a ResourceException is thrown.
If the cache element ce is not null, this method should set a reload
context on the cache element to enable
reload-on-demand for this template. If ce is null, caching is disabled.
- Parameters:
query
- location to load template fromce
- cache element that will be used for this template or null
if no cache is used.
- Throws:
ResourceException
- if an error occured while loading the template