org.webmacro.resource
Class URLTemplateProvider
java.lang.Object
|
+--org.webmacro.resource.CachingProvider
|
+--org.webmacro.resource.URLTemplateProvider
- All Implemented Interfaces:
- Provider, ResourceLoader
- public final class URLTemplateProvider
- extends CachingProvider
This is a "drop-in" replacement for the standard TemplateProvider in the
WebMacro distribution. The primary benefit is to allow template to be loaded
by a variety of means, without requiring an absolute path. This should make
applications more portable.
TemplatePath
TemplatePath=path1[;path2;....]
Each path should be a full URL specification or one of the special cases
listed below. If the path cannot be interpreted, it will be tried as file:path
Special cases
- TemplatePath=classpath:/templates
Template will be loaded from the classpath. Each directory on the
classpath will be tried in turn to locate the template.
- TemplatePath=ignore:
Don't use the template path. All templates will be referenced
explicitly as full URL's. A common case would be to generate a base URL
at runtime (e.g., from ServletContext.getResource("/") in JSDK 2.2+) and to
prepend this to the template path.
- TemplatePath=context:
reserved for future use (specifically for finding templates with a
servlet context)
Locale support
There is a limited locale based implemention here. Template paths can contain
a string of the form {_aaa_bbb....} which will usually correspond to a
locale such as en_GB.
Thus load("template{_en_GB}.wm") will look for
- template_en_GB.wm
- template_en.wm
- template.wm
in that order, returning the first one that exists. This is implemented so that
requests for template_en_GB.wm & template_en_US.wm will both return the same template
template_en.wm assuming only the latter exists. In other words, the template is
only parsed once.
- See Also:
CachingProvider
,
TemplateProvider
Field Summary |
static java.lang.String |
RCS
CVS Revision tag |
Method Summary |
java.lang.String |
getType()
Supports the "template" type. |
void |
init(Broker b,
Settings config)
Create a new TemplateProvider that uses the specified directory
as the source for Template objects that it will return |
java.lang.Object |
load(java.lang.String name,
CacheElement ce)
Grab a template based on its name, setting the request event to
contain it if we found it. |
java.lang.Object |
load(java.lang.String name,
java.net.URL base)
Find the specified template in the directory managed by this
template store. |
boolean |
shouldReload(java.lang.String name)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
RCS
public static final java.lang.String RCS
- CVS Revision tag
URLTemplateProvider
public URLTemplateProvider()
getType
public final java.lang.String getType()
- Supports the "template" type. This is a straight replacement for the
default TemplateProvider
- Returns:
- the template type. Always the String "template"
init
public void init(Broker b,
Settings config)
throws InitException
- Create a new TemplateProvider that uses the specified directory
as the source for Template objects that it will return
- Overrides:
init
in class CachingProvider
- Parameters:
b
- A brokerconfig
- Settings from the webmacro initialization file- Throws:
InitException
- thrown when the provider fails to initialize
load
public final java.lang.Object load(java.lang.String name,
CacheElement ce)
throws ResourceException
- Grab a template based on its name, setting the request event to
contain it if we found it.
- Parameters:
name
- The name of the template to load- Returns:
- the requested resource
- Throws:
NotFoundException
- if no matching template can be foundResourceException
- if template cannot be loaded
load
public final java.lang.Object load(java.lang.String name,
java.net.URL base)
throws ResourceException
- Find the specified template in the directory managed by this
template store. Any path specified in the filename is relative
to the directory managed by the template store.
- Parameters:
path
- relative to the current directory fo the store- Returns:
- a template matching that name, or null if one cannot be found
shouldReload
public final boolean shouldReload(java.lang.String name)