| com.uwyn.rife.template.Template
All known Subclasses: com.uwyn.rife.template.AbstractTemplate,
Template | public interface Template extends Cloneable(Code) | | A template is used to construct, manipulate and produce text content.
Templates can be used for a variety of text types, including XHTML,
plain text, XML, SQL and even Java source. Each template type has similar
features, the biggest difference is the syntax of the invisible tag which
takes the form of a comment in the corresponding language (<!--
--> for XHTML and XML, /* -* / for Java and SQL,
...).
Using templates
Templates are most commonly used to produce web pages, which is why a
method like
com.uwyn.rife.engine.Element.getXhtmlTemplate(String) is used. By obtaining
a template instance from the active
com.uwyn.rife.engine.Element , features that are
related to the web engine are added. To print a template for page output,
com.uwyn.rife.engine.Element.print(Template) is usually used. However, the content of
any template instance can be retrieved with the
Template.getContent method
which produces a regular String that is usable anywhere.
Components of a template
Templates are controlled by external code (usually a
), but communication is bidirectional between a
template and the logic that controls it. A template can provide content to
the controller through blocks, and the controller can insert or
replace text in the template through template values. The
controller can also provide the template with expression variables
and resource bundles.
Values
A value is the simplest concept in a template. It is the placeholder for
text somewhere in a block or in the page itself. In a HTML template, a
value called "name " is created using a declaration like:
<!--!V 'name'/-->
The controller can then fill this value with any of the
Template.setValue(String,String) setValue and
Template.appendValue(String,String)appendValue methods.
Values are mainly a one-way communication channel from the logic to the
template. However, values may contain a default value which can be
by the controller:
<!--V 'name'-->Some default<!--/V-->
Values are automatically filled in many ways aside from calling
Template.setValue and
Template.appendValue directly. We will discuss this later.
Blocks
Blocks represent the other direction of communication between a
controller and a template. A HTML template can define a block called "greeting "
like this:
<!--B 'greeting'-->Welcome, <!--V 'name'/--><!--/B-->
The literal text in the block is not accessible by the controller. It is
evaluated when the block is used. For example by
,
or
in the template
itself. The evaluation is based on the values that are currently present in
the template. If a block contains a value that hasn't been set yet, the
value placeholder will be remembered, unpopulated. It will be evaluated
against another value context the next time the content of the block is
used.
As soon as value placeholders exist when a block is used, they are
captured from the template and replaced with their available content. They
will become immutable in the result of the operation that used the block.
This means that repeated calls to
Template.appendBlock can append a block
to a value multiple times with different values each time. This feature
allows blocks to be used for producing repeating constructs such as tables,
using a pattern like this:
template.removeValue("people", "");
Iterator it = people.iterator();
while (it.hasNext()) {
Person person = (Person)it.next();
template.setValue("name", person.getName());
template.setValue("age", person.getAge());
template.appendBlock("people", "person");
}
Nested loops and corresponding nested blocks may be used to produce more
complex constructs.
Expressions
Templates may contain small boolean expressions that are written in JVM
scripting languages like OGNL, Groovy, or Janino. These expressions will be
automatically evaluated and allow certain blocks to be assigned
automatically to a value according to the scripted conditions. The
controller does not execute the scripts itself, but it may provide
variables to which the scripts have access, using the
Template.setExpressionVar setExpressionVar method. For example, if a template
contains:
<!--V 'GROOVY:welcome'--><!--/V-->
<!--V 'GROOVY:welcome:[[ showWelcome ]]'-->Welcome,
<!--V 'name'/--><!--/V-->
A controller could decide whether the welcome block should be shown
using:
template.setExpressionVar("showWelcome", person != null);
Apart from the expression variables, each expression is evaluated
against a current root object whose methods and properties you can access
using the regular scripting language syntax. This root object is by default
the template instance that you are processing.
To make it easy to write expressions against commonly used contexts,
RIFE also provides specialized scripted tags that set different root
objects. Currently the language:ROLEUSER and
language:CONFIG tags are provided.
Localization
It's possible to easily localize templates through the standard
ResourceBundle mechanism that is available in Java. The strings that are
localized are automatically filtered and replace values tags. The format
for localized values is:
<!--V 'L10N:key'-->default value<!--/V-->
Of course, before replacement, the template instance has to know where
to look for the key. Therefore, the
Template.addResourceBundle(ResourceBundle) method needs to be called to make the
template aware of it.
For example, consider the following resource bundles:
text_nl.properties
hello = Hallo
text_fr.properties
hello = Bonjour
and the following template:
Hey mister, I said: <!--V 'L10N:hello'/-->!"
The following Java code:
Template template_html = TemplateFactory.HTML.get("text");
ResourceBundle bundle = Localization.getResourceBundle("text", "fr");
template_html.addResourceBundle(bundle);
System.out.println(template.getContent());
will output:
Hey mister, I said: "Bonjour!"
Just replacing the second line with the following:
...
ResourceBundle bundle = Localization.getResourceBundle("text", "nl");
...
will output:
Hey mister, I said: "Hallo!"
Very often, resourcebundle are used for the whole application.
Therefore, application-wide default resource bundles can be specified for
each template type through the
com.uwyn.rife.config RIFEconfiguration , for example:
<list name="TEMPLATE_DEFAULT_RESOURCEBUNDLES_ENGINEHTML">
<item>l10n/graphics</item>
<item>l10n/text</item>
<item>l10n/descriptions</item>
</list>
This will automatically add these resourcebundles to any template
instance of the corresponding type, calling
Template.addResourceBundle(ResourceBundle) is thus not needed anymore and
localization will happen without any intervention from the controller.
While resource bundles offer a good method to isolate localized text
snippets, it's sometimes interesting to be able to conditionally display
parts of templates with lots of markup. For this purpose, resource bundles
are actually awkward to use. Templates are therefore able to set blocks
automatically to values, according to the default localization language (L10N_DEFAULT_LANGUAGE
configuration parameter). This can be done with the <!--B
'LANG:id:language'--> block syntax.
For example:
<!--V 'LANG:value1'-->default<!--/V--> [!V 'LANG:value2'/]
<!--B 'LANG:value1:nl'-->ja ja<!--/B-->
[!B 'LANG:value2:fr']oui oui[!/B]
[!B 'LANG:value2:en ']yes yes[!/B]
will display this when the default language is 'en ':
default yes yes
or this when the default language is 'fr ':
default oui oui
or this when the default language is 'nl ':
ja ja [!V 'LANG:value2'/]
Value renderers
Besides the main manipulation logic of a template, value content needs
to be sometimes created that is solely presentation related. This doesn't
actually have its place in elements and sometimes even creates a burden.
For these purposes, we created the
ValueRenderer interface. Classes
that implement this interface can be specified in any template like this:
<!--V 'RENDER:pakkage.classname'/-->
An instance of the class will be created and the
ValueRenderer.render method will be called if the value hasn't been set
yet. This has as side-effect that if you have several occurances of this
value ID, they will all have the same renderer value and the renderer will
only be called once.
If you need to have different results of the same renderer, you need to
use a differentiator, like this:
<!--V 'RENDER:pakkage.classname:differentiator'/-->
Encoding
Templates automatically encode values to the appropriate format (HTML,
XHTML, etc.) when using forms,
, localization tags, and when
.
However, in many cases it is necessary to encode values manually, to
prevent malicious content from being inserted into your site, or simply to
display text correctly if it may contain illegal characters (like
< in HTML). You can encode text using the template's
encoder after calling the
Template.getEncoder method.
Other features
Templates are powerful and some features are not described here. The Templates wiki
page describes several other features, including filtered values,
alternative means of localization, and other forms of templates.
author: Keith Lea <keith[remove] at cs dot oswego dot edu> author: Geert Bevin (gbevin[remove] at uwyn dot com) version: $Revision: 3643 $ since: 1.0 |
Method Summary | |
public void | addResourceBundle(ResourceBundle resourceBundle) Adds a resource bundle to this template. | public void | appendBlock(String valueId, String blockId) Appends the content of a block to a value. | public void | appendValue(String id, Object value) Appends the result of calling
String.valueOf(Object)String.valueOf on the given value to the specified value
in this template. | public void | appendValue(String id, boolean value) Appends "true" or "false" to the specified
value in this template, depending on the given value . | public void | appendValue(String id, char value) Appends the single specified character to the specified value in this
template. | public void | appendValue(String id, char[] value) Appends the given characters to the specified value in this template. | public void | appendValue(String id, char[] value, int offset, int count) Appends the specified range of the given character string to the
specified value in this template. | public void | appendValue(String id, double value) Appends the given double precision floating point value to the
specified value in this template. | public void | appendValue(String id, float value) Appends the given floating point value to the specified value in this
template. | public void | appendValue(String id, int value) Appends the given integer to the specified value in this template. | public void | appendValue(String id, long value) Appends the given long to the specified value in this template. | public void | appendValue(String id, String value) Appends the given string, or an empty string if value is
null , to the specified value in this template. | public void | blankValue(String id) Set the content of the specified value to an empte string. | public void | cacheObject(String key, Object value) Stores the given value in a cache, associated with the given key. | public void | clear() Resets all values in this template and removes any resource bundles. | public Object | clone() Returns a shallow copy of this template, with the same values,
expression variables, and so on. | public int | countValues() Returns the number of values in this template which
. | public InternalValue | createInternalValue() Returns an anonymous value that can be used to construct complex
content for use within this template. | public List<String> | evaluateConfigTags() Fills all values in this template which match "CONFIG:key ",
where "key " is a configuration value name in the
Config instance returned by
Config.getRepInstance . | public List<String> | evaluateExpressionConfigTags(String id) Evaluates the specified OGNL, Groovy, or Janino configuration
expression tag. | public List<String> | evaluateExpressionTags(String id) Evaluates the specified OGNL, Groovy, or Janino expression tag. | public List<String> | evaluateL10nTags() Fills all values in this template which match "L10N:key ",
where "key " is a
in a
registered for this
template. | public List<String> | evaluateLangTags(String id) Fills the value "LANG:id " with the value of the
block "LANG:id:langid ", where "id "
is the given ID, and "langid " is this template's
.
If no matching block for the current language is found, the content
of the specified value will not be modified.
This method is called automatically when the output is generated
(such as when calling
Template.getContent() ). | public List<String> | evaluateRenderTags() Evalutes all values in this template with ID's of the form "RENDER:class "
or "RENDER:class:differentiato r",
where "class " is the fully-qualified name of a class which
extends
ValueRenderer , the result of calling
ValueRenderer.render(TemplateStringString) ValueRenderer.render on
a new instance of the class. | public String[] | getAvailableValueIds() Returns a list of the ID's of all values present in this template,
including set and unset values. | public BeanHandler | getBeanHandler() Returns this template's
. | public String | getBlock(String id) Returns the evaluated content of the specified block as a text. | public Object | getCacheObject(String key) Returns the value corresponding to the given key in this template's
cache, or null if no such cached object exists. | public String | getContent() Returns the entire content of the template and finalize all non
evaluated values. | public String | getDefaultContentType() Returns this template's default content type, for example text/html . | public String | getDefaultValue(String id) Returns the original text of the specified value, before any
modification that may have been made using
Template.setValue or similar
methods. | public List<CharSequence> | getDeferredBlock(String id) Returns the content of the specified block as a list with all the
individual parts.
This list is the internal representation of all content with
placeholders for the values that aren't filled in yet. | public List<CharSequence> | getDeferredContent() Returns the content of this template as a list with all the individual
parts.
This list is the internal representation of all content with
placeholders for the values that aren't filled in yet. | public Map<URL, Long> | getDependencies() Returns a list of URL's that this template depends on, and their last
modification dates (in milliseconds since the Unix epoch). | public TemplateEncoder | getEncoder() Returns the encoder that this template uses to convert strings to
values in the template's generated text output. | public Map<String, Object> | getExpressionVars() Returns the name and value of all of the expression variables which
have been
in this template. | public List<String[]> | getFilteredBlocks(String filter) Each template type supports a set of special block tags that are used
for adding automated features like localization, block value scripting,
config value setting, ... | public List<String[]> | getFilteredValues(String filter) Each template type supports a set of special value tags that are used
for adding automated features like embedded elements, localization,
block value scripting, config value setting, ... | public String | getFullName() Returns this template's full name, as it was used to instantiate it
by a template factory. | public String | getLanguage() Returns this template's current 2-letter language code. | public long | getModificationTime() Returns when the file corresponding to this template was modified, in
milliseconds since the Unix epoch. | public String | getName() Returns this template's name, without path information or file
extension. | public Collection<ResourceBundle> | getResourceBundles() Returns a list of the resource bundles used by this template. | public Collection<String> | getUnsetValueIds() Returns a list of the ID's of all values in this template which
. | public String | getValue(String id) Returns the current content of the specified value as a string. | public boolean | hasBlock(String id) Returns whether this template contains a block with the given ID. | public boolean | hasDefaultValue(String id) Returns whether a
was
specified in this template for the specified value. | public boolean | hasFilteredBlocks(String filter) Returns whether any block matched a particular filter at template
compilation. | public boolean | hasFilteredValues(String filter) Returns whether any value matched a particular filter at template
compilation. | public boolean | hasResourceBundles() Returns whether this template has any resource bundles
. | public boolean | hasValueId(String id) Returns whether this template contains a value with the given ID. | public boolean | isValueSet(String id) Returns whether the specified value has been set. | public void | removeBean(Object bean) Reverts all values to their defaults when the identifiers match
properties of the given bean, whether or not those values were set with
a previous call to
Template.setBean(Object) setBean . | public void | removeBean(Object bean, String prefix) Reverts all values to their defaults when the identifiers match
properties of the given bean preceded by the given prefix, whether or
not those values were set with a previous call to
Template.setBean(Object) setBean . | public void | removeValue(String id) Reverts the specified value back to its default value. | public void | removeValues(List<String> ids) Reverts the specified values back to their default value. | public void | setBean(Object bean) Sets all values in this template whose identifiers match names of
properties in the given bean.
For example, given a class:
class Person {
private String first;
private String last;
public String getFirstName() { return first; }
public void setFirstName(String name) { this.first = name; }
public String getLastName() { return last; }
public void setLastName(String name) { this.last = name; }
And given a template:
Hello <!--V 'firstName'/--> <!--V 'lastName'/-->.
Calling this method with an instance of Person where
first was "Jim" and last was "James", would
produce:
Hello Jim James.
Calling this method is equivalent to calling
Template.setValue(String,String) setValue individually for each property of
the bean.
This method uses this template's
to
encode the bean properties before setting the values. | public void | setBean(Object bean, String prefix) Sets all values in this template whose names match names of properties
in the given bean, preceded by the given prefix.
For example, given a class:
class Person {
private String first;
private String last;
public String getFirstName() { return first; }
public void setFirstName(String name) { this.first = name; }
public String getLastName() { return last; }
public void setLastName(String name) { this.last = name; }
And given a template:
Hello <!--V 'NAME:firstName'/--> <!--V 'NAME:lastName'/-->.
Calling this method with an instance of Person where
first was "Jim" and last was "James", and the
prefix "NAME:", would produce:
Hello Jim James.
Calling this method is equivalent to calling
Template.setValue(String,String) setValue individually for each property of
the bean prefixed with the given prefix.
This method uses this template's
to
encode the bean properties before setting the values. | public void | setBean(Object bean, String prefix, boolean encode) Sets all values in this template whose names match names of properties
in the given bean, preceded by the given prefix, if present. | public void | setBlock(String valueId, String blockId) Replaces the specified value with the content of the specified block. | public void | setExpressionVar(String name, Object value) Sets a variable which can be accessed by
in OGNL, Groovy, or Janino. | public void | setExpressionVars(Map<String, Object> map) Sets the given variables to the given corresponding values, for use in
. | public void | setLanguage(String lang) Sets this template's current language code, such as "en". | public void | setValue(String id, List<CharSequence> deferredContent) Sets the specified value in this template to content that's structured
in the internal format. | public void | setValue(String id, InternalValue internalValue) Sets the specified value in this template to the value of the given
. | public void | setValue(String id, Object value) Sets the specified value in this template to the result of calling
String.valueOf(Object) String.valueOf on the given
value . | public void | setValue(String id, boolean value) Sets the specified value in this template to true or
false depending on the given value . | public void | setValue(String id, char value) Sets the specified value in this template to the single specified
character. | public void | setValue(String id, char[] value) Sets the specified value in this template to the given characters. | public void | setValue(String id, char[] value, int offset, int count) Sets the specified value in this template to the specified range of the
given character string. | public void | setValue(String id, double value) Sets the specified value in this template to the given double precision
floating point value. | public void | setValue(String id, float value) Sets the specified value in this template to the given floating point
value. | public void | setValue(String id, int value) Sets the specified value in this template to the given integer. | public void | setValue(String id, long value) Sets the specified value in this template to the given long. | public void | setValue(String id, String value) Sets the specified value in this template to the given string, or an
empty string if value is null . | public void | setValue(String id, CharSequence value) Sets the specified value in this template to the given character sequence,
or an empty character sequence if value is null . | public void | setValue(String id, Template template) Sets the specified value in this template to the current
of the given template. | public void | write(OutputStream out) This method is a shorthand for
Template.writeContent(OutputStream) . | public void | writeBlock(String id, OutputStream out) Writes the
of the
specified block to the given output stream, using UTF-8
encoding. | public void | writeContent(OutputStream out) Writes the
to the given stream, using UTF-8 encoding. | public void | writeContent(OutputStream out, String charsetName) Writes the
to the given stream, using the specified charset for encoding. |
addResourceBundle | public void addResourceBundle(ResourceBundle resourceBundle)(Code) | | Adds a resource bundle to this template. Resource bundles are used in
many places, including when generating labels for forms, generating
options for <select> tags, and
.
Parameters: resourceBundle - a resource bundle See Also: Template.getResourceBundles See Also: Template.hasResourceBundles since: 1.0 |
cacheObject | public void cacheObject(String key, Object value)(Code) | | Stores the given value in a cache, associated with the given key. This
is mainly used by OGNL, Groovy, and Janino expression evaluation system
to store caches to classes. You should probably not use the template
caching system to avoid conflicting with the expression evaluation
system.
Parameters: key - a name under which the given value should be stored Parameters: value - an object since: 1.0 |
clear | public void clear()(Code) | | Resets all values in this template and removes any resource bundles.
Configuration and localization tags are re-evaluated.
since: 1.0 |
clone | public Object clone()(Code) | | Returns a shallow copy of this template, with the same values,
expression variables, and so on.
a shallow copy of this template since: 1.0 |
countValues | public int countValues()(Code) | | Returns the number of values in this template which
.
the number of values in this template which have been set since: 1.0 |
createInternalValue | public InternalValue createInternalValue()(Code) | | Returns an anonymous value that can be used to construct complex
content for use within this template. See
InternalValue for
details.
The returned internal value is tied closely to the template it was
obtained from, methods like
InternalValue.appendBlock(String)InternalValue.appendBlock reference blocks within this template.
a new internal value instance for constructing more complexparts of this template See Also: InternalValue since: 1.0 |
evaluateConfigTags | public List<String> evaluateConfigTags()(Code) | | Fills all values in this template which match "CONFIG:key ",
where "key " is a configuration value name in the
Config instance returned by
Config.getRepInstance . Each
valuev will be filled with the value of the configuration option with
the corresponding key.
This method is normally called automatically during template
initialization. You should call it if you wish to re-evaluate the tags
at any time during the template's life.
the list of names of the template values that were generated since: 1.0 |
evaluateExpressionConfigTags | public List<String> evaluateExpressionConfigTags(String id)(Code) | | Evaluates the specified OGNL, Groovy, or Janino configuration
expression tag. For example, if a value exists with ID "OGNL:CONFIG:id:[[script]]",
where "id" is the given ID and "script" is some OGNL expression, this
method will replace this value with the value of the evaluated OGNL
expression, using the current set of
.
The prefix for OGNL is "OGNL: ", the prefix for Groovy
is "GROOVY: " and the prefix for Janino is "JANINO: ".
The context for the expressions will be the
Config object
returned by
Config.getRepInstance .
Expression config tags are evaluated automatically when the output
is generated (such as when calling
Template.getContent() ). You can
manually call this method to force evaluation of the tags earlier than
that.
Parameters: id - the ID whose expression tag will be replaced with the valueof the evaluated expression in the tag ID the list of names of the template values that were generated since: 1.0 |
evaluateExpressionTags | public List<String> evaluateExpressionTags(String id)(Code) | | Evaluates the specified OGNL, Groovy, or Janino expression tag. For
example, if a value exists with ID "OGNL:id:[[script]] ",
where "id " is the given ID and "script " is
some OGNL expression, this method will replace this value with the
value of the evaluated OGNL expression, using the current set of
.
The prefix for OGNL is "OGNL:", the prefix for Groovy is "GROOVY:"
and the prefix for Janino is "JANINO:".
This method is called automatically when the output is generated
(such as when calling
Template.getContent() ). You can manually call
this method to force evaluation of the tags earlier than that.
Parameters: id - the ID whose expression tag will be replaced with the valueof the evaluated expression in the tag ID the list of names of the template values that were generated since: 1.0 |
evaluateL10nTags | public List<String> evaluateL10nTags()(Code) | | Fills all values in this template which match "L10N:key ",
where "key " is a
in a
registered for this
template. Each value will be filled with the value in the resource
bundle with the corresponding key.
This method is normally called automatically during template
initialization. You should call it if you wish to re-evaluate the tags
at any time during the template's life.
the list of names of the template values that were generated since: 1.0 |
evaluateLangTags | public List<String> evaluateLangTags(String id)(Code) | | Fills the value "LANG:id " with the value of the
block "LANG:id:langid ", where "id "
is the given ID, and "langid " is this template's
.
If no matching block for the current language is found, the content
of the specified value will not be modified.
This method is called automatically when the output is generated
(such as when calling
Template.getContent() ). You can manually call
this method to force evaluation of the tags earlier than that.
Parameters: id - the ID whose language tag should be filled with theappropriate block the list of names of the template values that were generated since: 1.0 |
evaluateRenderTags | public List<String> evaluateRenderTags() throws TemplateException(Code) | | Evalutes all values in this template with ID's of the form "RENDER:class "
or "RENDER:class:differentiato r",
where "class " is the fully-qualified name of a class which
extends
ValueRenderer , the result of calling
ValueRenderer.render(TemplateStringString) ValueRenderer.render on
a new instance of the class. The class must contain a zero-argument
("no-arg") constructor.
For example, given a class MyRenderer in the package "org.rifers.something ",
which extends
ValueRenderer , a value "RENDER:org.rifers.something.MyRenderer:test "
would create a new instance of MyRenderer (using its
no-arg constructor), call render(this,
"RENDER:org.rifers.something.MyRenderer:test", "test") , and set
the value in this template to whatever value the call returns.
Value renderer tags are evaluated automatically when the output is
generated (such as when calling
Template.getContent() ). You can
manually call this method to force evaluation of the tags earlier than
that.
exception: TemplateException - if a class in a render tag cannot beinstantiated the list of names of the template values that were generated since: 1.0 |
getAvailableValueIds | public String[] getAvailableValueIds()(Code) | | Returns a list of the ID's of all values present in this template,
including set and unset values.
a list of ID's of all set and unset value since: 1.0 |
getBeanHandler | public BeanHandler getBeanHandler()(Code) | | Returns this template's
. The bean
handler is used for filling bean values into template values, and for
building forms.
this template's bean handler since: 1.0 |
getCacheObject | public Object getCacheObject(String key)(Code) | | Returns the value corresponding to the given key in this template's
cache, or null if no such cached object exists. As noted
in
Template.cacheObject , you should probably not use this method to
avoid conflicting with RIFE's internal use of the cache.
Parameters: key - a key whose associated cached object should be returned the value associated with the given key, or null if none exists since: 1.0 |
getContent | public String getContent() throws TemplateException(Code) | | Returns the entire content of the template and finalize all non
evaluated values. The content is the root block with has an empty
string as identifier.
Values without content will either use their default value if it has
been provided, or the tag that was used to declare the value will be
output as-is.
All specialized tags will also be evaluated (resourcebundle
localization, block localization, value renderers, expressions, ...).
the entire textual content of the template exception: TemplateException - when an error occurred during theprocessing of the specialized tags See Also: Template.appendBlock See Also: Template.setBlock See Also: Template.getBlock See Also: Template.hasBlock since: 1.0 |
getDefaultContentType | public String getDefaultContentType()(Code) | | Returns this template's default content type, for example text/html .
this template's default content type; ornull if no default content type is known for this template instance since: 1.3
|
getDefaultValue | public String getDefaultValue(String id)(Code) | | Returns the original text of the specified value, before any
modification that may have been made using
Template.setValue or similar
methods.
If no default value was specified for the given value, this method
will return null .
Parameters: id - the ID of a value in this template, or null the original text value of the specified value See Also: Template.hasDefaultValue since: 1.0 |
getDeferredBlock | public List<CharSequence> getDeferredBlock(String id) throws TemplateException(Code) | | Returns the content of the specified block as a list with all the
individual parts.
This list is the internal representation of all content with
placeholders for the values that aren't filled in yet. This structure
is mainly used internally by the framework. The list structure also
makes it possible to optimize performance and memory usage.
Parameters: id - the ID of a block in this template a list of the contents of the specified block exception: TemplateException - if no such block exists; or if an error occurred during the retrieval See Also: Template.getDeferredContent since: 1.0 |
getDeferredContent | public List<CharSequence> getDeferredContent() throws TemplateException(Code) | | Returns the content of this template as a list with all the individual
parts.
This list is the internal representation of all content with
placeholders for the values that aren't filled in yet. This structure
is mainly used internally by the framework. The list structure also
makes it possible to optimize performance and memory usage.
a list of the contents of this template exception: TemplateException - if an error occurred during the retrieval See Also: Template.getDeferredBlock since: 1.0 |
getDependencies | public Map<URL, Long> getDependencies()(Code) | | Returns a list of URL's that this template depends on, and their last
modification dates (in milliseconds since the Unix epoch). This method
should return templates which are included by this template, and any
other resources which are required to fully render the template.
a list of URL's and last modification dates of resources onwhich this template depends since: 1.0 |
getEncoder | public TemplateEncoder getEncoder()(Code) | | Returns the encoder that this template uses to convert strings to
values in the template's generated text output. In an HTML template,
for example, this encoder may be used to convert text which may contain
HTML special characters like <> to corresponding
escaped strings.
this template's encoder since: 1.0 |
getFilteredBlocks | public List<String[]> getFilteredBlocks(String filter)(Code) | | Each template type supports a set of special block tags that are used
for adding automated features like localization, block value scripting,
config value setting, ... Instead of having to parse all template block
identifiers each time these features are used, RIFE filters them out at
template compilation and keeps them available in a separate collection.
This method is mainly used by the framework itself, the supported
filter regular expressions are available from
TemplateFactory and
TemplateFactoryEngineTypes .
Parameters: filter - a template factory regular expression a list of captured groups for matching block ID's See Also: Template.hasFilteredBlocks since: 1.0 |
getFilteredValues | public List<String[]> getFilteredValues(String filter)(Code) | | Each template type supports a set of special value tags that are used
for adding automated features like embedded elements, localization,
block value scripting, config value setting, ... Instead of having to
parse all template value identifiers each time these features are used,
RIFE filters them out at template compilation and keeps them available
in a separate collection.
This method is mainly used by the framework itself, the supported
filter regular expressions are available from
TemplateFactory and
TemplateFactoryEngineTypes .
Parameters: filter - a template factory regular expression a list of captured groups for matching value ID's See Also: Template.hasFilteredValues since: 1.0 |
getFullName | public String getFullName()(Code) | | Returns this template's full name, as it was used to instantiate it
by a template factory.
this template's full name since: 1.6 |
getLanguage | public String getLanguage()(Code) | | Returns this template's current 2-letter language code. This code is
used when
Template.evaluateL10nTags filling localized text values . If
the language has not been
, it defaults to
the language set by the RIFE configuration parameter "L10N_DEFAULT_LANGUAGE ".
the 2-letter language code currently used by this template See Also: Template.setLanguage since: 1.0 |
getModificationTime | public long getModificationTime()(Code) | | Returns when the file corresponding to this template was modified, in
milliseconds since the Unix epoch.
the time at which the underlying template file was modified since: 1.0 |
getName | public String getName()(Code) | | Returns this template's name, without path information or file
extension. For example, for /Users/me/Something/templates/xyz.html,
this method will return "xyz".
this template's name, without path or file extension since: 1.0 |
getUnsetValueIds | public Collection<String> getUnsetValueIds()(Code) | | Returns a list of the ID's of all values in this template which
.
a list of ID's of values in this template which have not beenset since: 1.0 |
hasDefaultValue | public boolean hasDefaultValue(String id)(Code) | | Returns whether a
was
specified in this template for the specified value.
Parameters: id - the ID of a value in this template whether the specified value has a default value See Also: Template.getDefaultValue since: 1.0 |
hasFilteredBlocks | public boolean hasFilteredBlocks(String filter)(Code) | | Returns whether any block matched a particular filter at template
compilation.
Parameters: filter - a template factory regular expression whether any matching blocks exist in this template See Also: Template.getFilteredBlocks since: 1.0 |
hasFilteredValues | public boolean hasFilteredValues(String filter)(Code) | | Returns whether any value matched a particular filter at template
compilation.
Parameters: filter - a template factory regular expression whether any matching values exist in this template See Also: Template.getFilteredValues since: 1.0 |
removeBean | public void removeBean(Object bean) throws TemplateException(Code) | | Reverts all values to their defaults when the identifiers match
properties of the given bean, whether or not those values were set with
a previous call to
Template.setBean(Object) setBean . The values of the
bean's properties are ignored.
Calling this method is equivalent to calling
Template.removeValueremoveValue once for the name of each property of the given bean.
Parameters: bean - a bean exception: TemplateException - if this template has no bean handlingcapability; or an error occurred during the introspection of the bean See Also: Template.setBean since: 1.0 |
removeBean | public void removeBean(Object bean, String prefix) throws TemplateException(Code) | | Reverts all values to their defaults when the identifiers match
properties of the given bean preceded by the given prefix, whether or
not those values were set with a previous call to
Template.setBean(Object) setBean . The values of the bean's properties are
ignored.
Calling this method is equivalent to calling
Template.removeValueremoveValue once for the name of each property of the given bean,
prefixed with the given prefix.
Parameters: bean - a bean whose properties will be used to determine whichvalues to remove from the template Parameters: prefix - a prefix exception: TemplateException - if this template has no bean handlingcapability; or an error occurred during the introspection of the bean See Also: Template.setBean since: 1.0 |
setBean | public void setBean(Object bean) throws TemplateException(Code) | | Sets all values in this template whose identifiers match names of
properties in the given bean.
For example, given a class:
class Person {
private String first;
private String last;
public String getFirstName() { return first; }
public void setFirstName(String name) { this.first = name; }
public String getLastName() { return last; }
public void setLastName(String name) { this.last = name; }
And given a template:
Hello <!--V 'firstName'/--> <!--V 'lastName'/-->.
Calling this method with an instance of Person where
first was "Jim" and last was "James", would
produce:
Hello Jim James.
Calling this method is equivalent to calling
Template.setValue(String,String) setValue individually for each property of
the bean.
This method uses this template's
to
encode the bean properties before setting the values. To prevent this,
use
.
Only bean properties will be considered for insertion in
the template. This means only properties with a getter and a setter
will be considered.
Parameters: bean - a bean whose properties will be used to fill in values inthe template exception: TemplateException - if this template has no bean handlingcapability; or an error occurred during the introspection of the bean See Also: Template.removeBean since: 1.0 |
setBean | public void setBean(Object bean, String prefix) throws TemplateException(Code) | | Sets all values in this template whose names match names of properties
in the given bean, preceded by the given prefix.
For example, given a class:
class Person {
private String first;
private String last;
public String getFirstName() { return first; }
public void setFirstName(String name) { this.first = name; }
public String getLastName() { return last; }
public void setLastName(String name) { this.last = name; }
And given a template:
Hello <!--V 'NAME:firstName'/--> <!--V 'NAME:lastName'/-->.
Calling this method with an instance of Person where
first was "Jim" and last was "James", and the
prefix "NAME:", would produce:
Hello Jim James.
Calling this method is equivalent to calling
Template.setValue(String,String) setValue individually for each property of
the bean prefixed with the given prefix.
This method uses this template's
to
encode the bean properties before setting the values. To prevent this,
use
.
Only bean properties will be considered for insertion in
the template. This means only properties with a getter and a setter
will be considered.
Parameters: bean - a bean whose properties will be used to fill in values inthe template Parameters: prefix - the prefix of values which will be filled with the givenbean's property values exception: TemplateException - if this template has no bean handlingcapability; or an error occurred during the introspection of the bean See Also: Template.removeBean since: 1.0 |
setBean | public void setBean(Object bean, String prefix, boolean encode) throws TemplateException(Code) | | Sets all values in this template whose names match names of properties
in the given bean, preceded by the given prefix, if present. If the
given prefix is null , it is ignored.
For example, given a class:
class Person {
private String first;
private String last;
public String getFirstName() { return first; }
public void setFirstName(String name) { this.first = name; }
public String getLastName() { return last; }
public void setLastName(String name) { this.last = name; }
And given a template:
Hello <!--V 'NAME:firstName'/--> <!--V 'NAME:lastName'/-->.
Calling this method with an instance of Person where
first was "Jim" and last was "James", and the
prefix "NAME:", would produce:
Hello Jim James.
Calling this method is equivalent to calling
Template.setValue(String,String) setValue individually for each property of
the bean prefixed with the given prefix.
If encode is true , this method will use
this template's
to encode the bean
properties before setting the values.
Only bean properties will be considered for insertion in
the template. This means only properties with a getter and a setter
will be considered.
Parameters: bean - a bean whose properties will be used to fill in values inthe template Parameters: prefix - the prefix of values which will be filled with the givenbean's property values Parameters: encode - true if the bean poroperty values have to beencoded; or false otherwise exception: TemplateException - if this template has no bean handlingcapability; or
an error occurred during the introspection of the bean See Also: Template.removeBean since: 1.0 |
setLanguage | public void setLanguage(String lang)(Code) | | Sets this template's current language code, such as "en".
This is used when
Template.evaluateL10nTags filling localized textvalues .
Parameters: lang - a 2-letter language code for the language to be used bythis template See Also: Template.getLanguage since: 1.0 |
|
|