org.webmacro.resource
Class DelegatingTemplateProvider
java.lang.Object
org.webmacro.resource.CachingProvider
org.webmacro.resource.DelegatingTemplateProvider
- All Implemented Interfaces:
- Provider, ResourceLoader
- public class DelegatingTemplateProvider
- extends CachingProvider
Alternative implementation of a TemplateProvider that uses TemplateLoaders to do the actual work.
This template provider controls a list of TemplateLoaders to do the actual work of loading
a template. It asks the template loaders one by one, until a template is found or the end of
the list is reached. It is configured by a list of "TemplateLoaderPath.n" settings in
WebMacro.properties.
Each template loader is described by an url like syntax with a TemplateLoaderPath.n setting,
where n should be a number starting from one.
Each template loader path is of the form "[protocol:][path]". If the protocol part in square brackets
is ommited, "default:" is assumed.
For each protocol, a "TemplateLoader.protocol" setting must give the fully qualified
classname of the template loader to be used for this protocol.
Example configuration:
TemplateLoaderPath.1=.
TemplateLoaderPath.2=classpath:
TemplateLoaderPath.3=webapp:/WEB-INF/templates/
TemplateLoader.default=org.webmacro.resource.FileTemplateLoader
TemplateLoader.classpath=org.webmacro.resource.ClassPathTemplateLoader
TemplateLoader.webapp=org.webmacro.resource.ServletContextTemplateLoader
This configuration will search for templates at three locations in this order:
- The current directory (".")
- The classpath (classpath:)
- The directory WEB-INF/templates/ in the web-app directory ("webapp:/WEB-INF/templates/")
Note, that this setup only makes sense in a web-app environment, because the webapp template loader
won't work otherwise.
- Author:
- Sebastian Kanthak (sebastian.kanthak@muehlheim.de)
Method Summary |
protected TemplateLoaderFactory |
createFactory(java.lang.String classname)
|
java.util.List |
getTemplateLoaders()
Returns an unmodifieable list of this provider's template loaders. |
java.lang.String |
getType()
Return an array representing the types this provider serves up |
void |
init(Broker broker,
Settings config)
If you override this method be sure and call super.init(...) |
java.lang.Object |
load(java.lang.String query,
CacheElement ce)
Ask all template loaders to load a template from query. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
DelegatingTemplateProvider
public DelegatingTemplateProvider()
init
public void init(Broker broker,
Settings config)
throws InitException
- Description copied from class:
CachingProvider
- If you override this method be sure and call super.init(...)
- Specified by:
init
in interface Provider
- Overrides:
init
in class CachingProvider
- Throws:
InitException
getType
public java.lang.String getType()
- Description copied from interface:
Provider
- Return an array representing the types this provider serves up
load
public java.lang.Object load(java.lang.String query,
CacheElement ce)
throws ResourceException
- Ask all template loaders to load a template from query.
Returns the template from the first provider, that returns a non-null value
or throws a NotFoundException, if all providers return null.
- Throws:
ResourceException
getTemplateLoaders
public java.util.List getTemplateLoaders()
- Returns an unmodifieable list of this provider's template loaders.
The list is has the same order used for searching templates. You may
use this method to access template loaders and change their settings
at runtime if they have an appropriate method.
- Returns:
- unmodifieable list of TemplateLoader objects
createFactory
protected TemplateLoaderFactory createFactory(java.lang.String classname)
throws InitException
- Throws:
InitException