|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Template
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,
...).
Templates are most commonly used to produce web pages, which is why a
method like ElementSupport.getXhtmlTemplate(String) is used. By obtaining
a template instance from the active Element, features that are
related to the web engine are added. To print a template for page output,
ElementSupport.print(Template) is usually used. However, the content of
any template instance can be retrieved with the getContent() method
which produces a regular String that is usable anywhere.
Templates are controlled by external code (usually a RIFE element), 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.
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 setValue and 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 read by the controller:
<!--V 'name'-->Some default<!--/V-->
Values are automatically filled in many ways aside from calling setValue(java.lang.String, java.util.List and appendValue(java.lang.String, java.lang.Object) directly. We will discuss this later.
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 reading it from the controller, assigning it to a value or appending it to a value 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 appendBlock(java.lang.String, java.lang.String) 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.
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 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.
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 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 RIFE
configuration, 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 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'/]
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(com.uwyn.rife.template.Template, java.lang.String, java.lang.String) 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'/-->
Templates automatically encode values to the appropriate format (HTML,
XHTML, etc.) when using forms, configuration tags, localization tags, and when setting values from bean properties.
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 getEncoder() method.
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.
| Method Summary | |
|---|---|
void |
addResourceBundle(ResourceBundle resourceBundle)
Adds a resource bundle to this template. |
void |
appendBlock(String valueId,
String blockId)
Appends the content of a block to a value. |
void |
appendValue(String id,
boolean value)
Appends "true" or "false" to the specified
value in this template, depending on the given value. |
void |
appendValue(String id,
char value)
Appends the single specified character to the specified value in this template. |
void |
appendValue(String id,
char[] value)
Appends the given characters to the specified value in this template. |
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. |
void |
appendValue(String id,
double value)
Appends the given double precision floating point value to the specified value in this template. |
void |
appendValue(String id,
float value)
Appends the given floating point value to the specified value in this template. |
void |
appendValue(String id,
int value)
Appends the given integer to the specified value in this template. |
void |
appendValue(String id,
long value)
Appends the given long to the specified value in this template. |
void |
appendValue(String id,
Object value)
Appends the result of calling String.valueOf on the given value to the specified value
in this template. |
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. |
void |
blankValue(String id)
Set the content of the specified value to an empte string. |
void |
cacheObject(String key,
Object value)
Stores the given value in a cache, associated with the given key. |
void |
clear()
Resets all values in this template and removes any resource bundles. |
Object |
clone()
Returns a shallow copy of this template, with the same values, expression variables, and so on. |
int |
countValues()
Returns the number of values in this template which have been set. |
InternalValue |
createInternalValue()
Returns an anonymous value that can be used to construct complex content for use within this template. |
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(). |
List<String> |
evaluateExpressionConfigTags(String id)
Evaluates the specified OGNL, Groovy, or Janino configuration expression tag. |
List<String> |
evaluateExpressionTags(String id)
Evaluates the specified OGNL, Groovy, or Janino expression tag. |
List<String> |
evaluateL10nTags()
Fills all values in this template which match " L10N:key",
where "key" is a key in a resource bundle registered for this
template. |
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
current language ID. |
List<String> |
evaluateRenderTags()
Evalutes all values in this template with ID's of the form " RENDER:class"
or "RENDER:class:differentiator",
where "class" is the fully-qualified name of a class which
extends ValueRenderer, the result of calling ValueRenderer.render on
a new instance of the class. |
String[] |
getAvailableValueIds()
Returns a list of the ID's of all values present in this template, including set and unset values. |
BeanHandler |
getBeanHandler()
Returns this template's bean handler. |
String |
getBlock(String id)
Returns the evaluated content of the specified block as a text. |
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. |
String |
getContent()
Returns the entire content of the template and finalize all non evaluated values. |
String |
getDefaultContentType()
Returns this template's default content type, for example text/html. |
String |
getDefaultValue(String id)
Returns the original text of the specified value, before any modification that may have been made using setValue(java.lang.String, java.util.List or similar
methods. |
List<CharSequence> |
getDeferredBlock(String id)
Returns the content of the specified block as a list with all the individual parts. |
List<CharSequence> |
getDeferredContent()
Returns the content of this template as a list with all the individual parts. |
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). |
TemplateEncoder |
getEncoder()
Returns the encoder that this template uses to convert strings to values in the template's generated text output. |
Map<String,Object> |
getExpressionVars()
Returns the name and value of all of the expression variables which have been set in this template. |
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, ... |
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, ... |
String |
getFullName()
Returns this template's full name, as it was used to instantiate it by a template factory. |
String |
getLanguage()
Returns this template's current 2-letter language code. |
long |
getModificationTime()
Returns when the file corresponding to this template was modified, in milliseconds since the Unix epoch. |
String |
getName()
Returns this template's name, without path information or file extension. |
Collection<ResourceBundle> |
getResourceBundles()
Returns a list of the resource bundles used by this template. |
Collection<String> |
getUnsetValueIds()
Returns a list of the ID's of all values in this template which have not been set. |
String |
getValue(String id)
Returns the current content of the specified value as a string. |
boolean |
hasBlock(String id)
Returns whether this template contains a block with the given ID. |
boolean |
hasDefaultValue(String id)
Returns whether a default value was specified in this template for the specified value. |
boolean |
hasFilteredBlocks(String filter)
Returns whether any block matched a particular filter at template compilation. |
boolean |
hasFilteredValues(String filter)
Returns whether any value matched a particular filter at template compilation. |
boolean |
hasResourceBundles()
Returns whether this template has any resource bundles registered. |
boolean |
hasValueId(String id)
Returns whether this template contains a value with the given ID. |
boolean |
isValueSet(String id)
Returns whether the specified value has been set. |
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 setBean. |
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 setBean. |
void |
removeValue(String id)
Reverts the specified value back to its default value. |
void |
removeValues(List<String> ids)
Reverts the specified values back to their default value. |
void |
setBean(Object bean)
Sets all values in this template whose identifiers match names of properties in the given bean. |
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. |
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. |
void |
setBlock(String valueId,
String blockId)
Replaces the specified value with the content of the specified block. |
void |
setExpressionVar(String name,
Object value)
Sets a variable which can be accessed by expression tags in OGNL, Groovy, or Janino. |
void |
setExpressionVars(Map<String,Object> map)
Sets the given variables to the given corresponding values, for use in expression tags. |
void |
setLanguage(String lang)
Sets this template's current language code, such as "en". |
void |
setValue(String id,
boolean value)
Sets the specified value in this template to true or
false depending on the given value. |
void |
setValue(String id,
char value)
Sets the specified value in this template to the single specified character. |
void |
setValue(String id,
char[] value)
Sets the specified value in this template to the given characters. |
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. |
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. |
void |
setValue(String id,
double value)
Sets the specified value in this template to the given double precision floating point value. |
void |
setValue(String id,
float value)
Sets the specified value in this template to the given floating point value. |
void |
setValue(String id,
int value)
Sets the specified value in this template to the given integer. |
void |
setValue(String id,
InternalValue internalValue)
Sets the specified value in this template to the value of the given internal value. |
void |
setValue(String id,
List<CharSequence> deferredContent)
Sets the specified value in this template to content that's structured in the internal format. |
void |
setValue(String id,
long value)
Sets the specified value in this template to the given long. |
void |
setValue(String id,
Object value)
Sets the specified value in this template to the result of calling String.valueOf on the given
value. |
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. |
void |
setValue(String id,
Template template)
Sets the specified value in this template to the current content of the given template. |
void |
write(OutputStream out)
This method is a shorthand for writeContent(OutputStream). |
void |
writeBlock(String id,
OutputStream out)
Writes the evaluated contents of the specified block to the given output stream, using UTF-8
encoding. |
void |
writeContent(OutputStream out)
Writes the complete evaluated template content to the given stream, using UTF-8 encoding. |
void |
writeContent(OutputStream out,
String charsetName)
Writes the complete evaluated template content to the given stream, using the specified charset for encoding. |
| Method Detail |
|---|
void appendBlock(String valueId,
String blockId)
throws TemplateException
valueId - the ID of the valueblockId - the ID of the block
TemplateException - when the valueId or
blockId aren't knownsetBlock(java.lang.String, java.lang.String),
getBlock(java.lang.String),
getContent(),
hasBlock(java.lang.String)
void setBlock(String valueId,
String blockId)
throws TemplateException
valueId - the ID of the valueblockId - the ID of the block
TemplateException - when the valueId or
blockId aren't knownappendBlock(java.lang.String, java.lang.String),
getBlock(java.lang.String),
getContent(),
hasBlock(java.lang.String)
String getBlock(String id)
throws TemplateException
id - the ID of the block in the template
TemplateException - when the block ID isn't knownappendBlock(java.lang.String, java.lang.String),
setBlock(java.lang.String, java.lang.String),
getContent(),
hasBlock(java.lang.String)
String getContent()
throws TemplateException
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, ...).
TemplateException - when an error occurred during the
processing of the specialized tagsappendBlock(java.lang.String, java.lang.String),
setBlock(java.lang.String, java.lang.String),
getBlock(java.lang.String),
hasBlock(java.lang.String)
void writeBlock(String id,
OutputStream out)
throws IOException,
TemplateException
UTF-8
encoding.
id - the ID of the blockout - the stream to write to
IOException - when errors occur during the manipulation of the
output stream
TemplateException - when the block ID isn't knownwriteContent(OutputStream),
writeContent(OutputStream, String),
write(java.io.OutputStream)
void writeContent(OutputStream out)
throws IOException,
TemplateException
out - the stream to which the template contents should be written
IOException - when errors occur during the manipulation of the
output stream
TemplateException - when an error occurs during the template
content evaluationwriteBlock(java.lang.String, java.io.OutputStream),
writeContent(OutputStream, String),
write(java.io.OutputStream)
void writeContent(OutputStream out,
String charsetName)
throws IOException,
TemplateException
out - the stream to which the template contents should be writtencharsetName - the name of the charset to use
IOException - when errors occur during the manipulation of the
output stream; or
when the character set isn't valid
TemplateException - when an error occurs during the template
content evaluationwriteBlock(java.lang.String, java.io.OutputStream),
writeContent(OutputStream),
write(java.io.OutputStream)
void write(OutputStream out)
throws IOException,
TemplateException
writeContent(OutputStream).
out - the stream to which the template contents should be written
IOException - when errors occur during the manipulation of the
output stream; or
when the character set isn't valid
TemplateException - when an error occurs during the template
content evaluationwriteBlock(java.lang.String, java.io.OutputStream),
writeContent(OutputStream),
writeContent(OutputStream, String)
List<CharSequence> getDeferredBlock(String id)
throws TemplateException
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.
id - the ID of a block in this template
TemplateException - if no such block exists; or
if an error occurred during the retrieval
getDeferredContent()
List<CharSequence> getDeferredContent()
throws TemplateException
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.
TemplateException - if an error occurred during the retrievalgetDeferredBlock(java.lang.String)InternalValue createInternalValue()
InternalValue for
details.
The returned internal value is tied closely to the template it was
obtained from, methods like InternalValue.appendBlock reference blocks within this template.
InternalValue
void setValue(String id,
List<CharSequence> deferredContent)
throws TemplateException
id - the ID of the value in this templatedeferredContent - content in the internal format
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
InternalValue internalValue)
throws TemplateException
id - the ID of the value in this templateinternalValue - an internal value, null set the value
content to blank content
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
Object value)
throws TemplateException
String.valueOf on the given
value.
id - the ID of the value in this templatevalue - an object
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
boolean value)
throws TemplateException
true or
false depending on the given value.
id - the ID of the value in this templatevalue - a boolean value
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
char value)
throws TemplateException
id - the ID of the value in this templatevalue - a character
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
char[] value)
throws TemplateException
null.
id - the ID of the value in this templatevalue - a string of characters
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
char[] value,
int offset,
int count)
throws TemplateException
value will be used, starting at the character specified by
offset.
id - the ID of the value in this templatevalue - a character stringoffset - the index in value of the first character to
usecount - the number of characters to use
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
double value)
throws TemplateException
String.format or NumberFormat instead.
id - the ID of the value in this templatevalue - a floating point value
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
float value)
throws TemplateException
String.format or NumberFormat instead.
id - the ID of the value in this templatevalue - a floating point value
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
int value)
throws TemplateException
id - the ID of the value in this templatevalue - an integer
TemplateException - if the specified value does not exist in
this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
long value)
throws TemplateException
id - the ID of the value in this templatevalue - a long
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
String value)
throws TemplateException
value is null.
id - the ID of the value in this templatevalue - a string, or null
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
CharSequence value)
throws TemplateException
value is null.
id - the ID of the value in this templatevalue - a character sequence, or null
TemplateException - if the specified value ID does not exist
in this templateappendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setValue(String id,
Template template)
throws TemplateException
If the given template is null, the specified value will
be set to an empty string.
id - the ID of the value in this templatetemplate - a template
TemplateException - if the specified value ID does not exist
in this template; or
if an error occurred during the evaluation of the template parameter
appendValue(java.lang.String, java.lang.Object),
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void setBean(Object bean)
throws TemplateException
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 setValue individually for each property of
the bean.
This method uses this template's encoder to encode the bean properties before setting the values. To prevent this, use the other form of setBean.
Only bean properties will be considered for insertion in the template. This means only properties with a getter and a setter will be considered.
bean - a bean whose properties will be used to fill in values in
the template
TemplateException - if this template has no bean handling
capability; or
an error occurred during the introspection of the bean
removeBean(java.lang.Object)
void setBean(Object bean,
String prefix)
throws TemplateException
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 setValue individually for each property of
the bean prefixed with the given prefix.
This method uses this template's encoder to encode the bean properties before setting the values. To prevent this, use the other form of setBean.
Only bean properties will be considered for insertion in the template. This means only properties with a getter and a setter will be considered.
bean - a bean whose properties will be used to fill in values in
the templateprefix - the prefix of values which will be filled with the given
bean's property values
TemplateException - if this template has no bean handling
capability; or
an error occurred during the introspection of the bean
removeBean(java.lang.Object)
void setBean(Object bean,
String prefix,
boolean encode)
throws TemplateException
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 setValue individually for each property of
the bean prefixed with the given prefix.
If encode is true, this method will use
this template's encoder 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.
bean - a bean whose properties will be used to fill in values in
the templateprefix - the prefix of values which will be filled with the given
bean's property valuesencode - true if the bean poroperty values have to be
encoded; or
false otherwise
TemplateException - if this template has no bean handling
capability; or
an error occurred during the introspection of the bean
removeBean(java.lang.Object)
void removeBean(Object bean)
throws TemplateException
setBean. The values of the
bean's properties are ignored.
Calling this method is equivalent to calling removeValue once for the name of each property of the given bean.
bean - a bean
TemplateException - if this template has no bean handling
capability; or
an error occurred during the introspection of the bean
setBean(java.lang.Object)
void removeBean(Object bean,
String prefix)
throws TemplateException
setBean. The values of the bean's properties are
ignored.
Calling this method is equivalent to calling removeValue once for the name of each property of the given bean,
prefixed with the given prefix.
bean - a bean whose properties will be used to determine which
values to remove from the templateprefix - a prefix
TemplateException - if this template has no bean handling
capability; or
an error occurred during the introspection of the bean
setBean(java.lang.Object)
void appendValue(String id,
Object value)
throws TemplateException
String.valueOf on the given value to the specified value
in this template.
id - the ID of the value in this templatevalue - an object
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
boolean value)
throws TemplateException
"true" or "false" to the specified
value in this template, depending on the given value.
id - the ID of the value in this templatevalue - a boolean value
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
char value)
throws TemplateException
id - the ID of the value in this templatevalue - a character
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
char[] value)
throws TemplateException
null.
id - the ID of the value in this templatevalue - a string of characters
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
char[] value,
int offset,
int count)
throws TemplateException
value will be used, starting at the character specified by
offset.
id - the ID of the value in this templatevalue - a character stringoffset - the index in value of the first character to
usecount - the number of characters to use
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
double value)
throws TemplateException
String.format or NumberFormat instead.
id - the ID of the value in this templatevalue - a floating point value
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
float value)
throws TemplateException
String.format or NumberFormat instead.
id - the ID of the value in this templatevalue - a floating point value
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
int value)
throws TemplateException
id - the ID of the value in this templatevalue - an integer
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
long value)
throws TemplateException
id - the ID of the value in this templatevalue - a long
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
void appendValue(String id,
String value)
throws TemplateException
value is
null, to the specified value in this template.
id - the ID of the value in this templatevalue - a string, or null
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)
String getValue(String id)
throws TemplateException
id - the ID of a value in this template
TemplateException - if the specified value ID does not exist
in this templatesetValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)String getDefaultValue(String id)
setValue(java.lang.String, java.util.List) or similar
methods.
If no default value was specified for the given value, this method
will return null.
id - the ID of a value in this template, or null
hasDefaultValue(java.lang.String)boolean hasDefaultValue(String id)
id - the ID of a value in this template
getDefaultValue(java.lang.String)List<String[]> getFilteredBlocks(String filter)
This method is mainly used by the framework itself, the supported
filter regular expressions are available from TemplateFactory
and TemplateFactoryEngineTypes.
filter - a template factory regular expression
hasFilteredBlocks(java.lang.String)boolean hasFilteredBlocks(String filter)
filter - a template factory regular expression
getFilteredBlocks(java.lang.String)List<String[]> getFilteredValues(String filter)
This method is mainly used by the framework itself, the supported
filter regular expressions are available from TemplateFactory
and TemplateFactoryEngineTypes.
filter - a template factory regular expression
hasFilteredValues(java.lang.String)boolean hasFilteredValues(String filter)
filter - a template factory regular expression
getFilteredValues(java.lang.String)List<String> evaluateL10nTags()
L10N:key",
where "key" is a key in a resource bundle 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.
List<String> evaluateConfigTags()
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.
List<String> evaluateLangTags(String id)
LANG:id" with the value of the
block "LANG:id:langid", where "id"
is the given ID, and "langid" is this template's
current language ID.
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 getContent()). You can manually call
this method to force evaluation of the tags earlier than that.
id - the ID whose language tag should be filled with the
appropriate block
List<String> evaluateExpressionTags(String 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
expression variables.
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 getContent()). You can manually call
this method to force evaluation of the tags earlier than that.
id - the ID whose expression tag will be replaced with the value
of the evaluated expression in the tag ID
List<String> evaluateExpressionConfigTags(String id)
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 getContent()). You can
manually call this method to force evaluation of the tags earlier than
that.
id - the ID whose expression tag will be replaced with the value
of the evaluated expression in the tag ID
List<String> evaluateRenderTags()
throws TemplateException
RENDER:class"
or "RENDER:class:differentiator",
where "class" is the fully-qualified name of a class which
extends ValueRenderer, the result of calling 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 getContent()). You can
manually call this method to force evaluation of the tags earlier than
that.
TemplateException - if a class in a render tag cannot be
instantiatedboolean hasBlock(String id)
id - the prospective ID of a block
appendBlock(java.lang.String, java.lang.String),
setBlock(java.lang.String, java.lang.String),
getBlock(java.lang.String),
getContent()boolean isValueSet(String id)
false, the value has its original default value.
If no such value exists in this template, this method will not throw
an exception, it will return false.
id - the ID of a value in this template
appendValue(java.lang.String, java.lang.Object),
setValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)int countValues()
void removeValue(String id)
id - the ID of a value in this templateappendValue(java.lang.String, java.lang.Object),
setValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
hasValueId(java.lang.String)void removeValues(List<String> ids)
ids - the IDs of values in this templateappendValue(java.lang.String, java.lang.Object),
setValue(java.lang.String, java.util.List) ,
* @see #removeValue,
hasValueId(java.lang.String)void blankValue(String id)
id - the ID of a value in this templateappendValue(java.lang.String, java.lang.Object),
setValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
hasValueId(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) void clear()
String[] getAvailableValueIds()
Collection<String> getUnsetValueIds()
boolean hasValueId(String id)
id - the potential ID of a value in this template
appendValue(java.lang.String, java.lang.Object),
setValue(java.lang.String, java.util.List) ,
isValueSet(java.lang.String),
removeValue(java.lang.String),
removeValues(java.util.List) ,
blankValue(java.lang.String),
hasValueId(java.lang.String)long getModificationTime()
BeanHandler getBeanHandler()
TemplateEncoder getEncoder()
<> to corresponding
escaped strings.
void addResourceBundle(ResourceBundle resourceBundle)
<select> tags, and using localized text.
resourceBundle - a resource bundlegetResourceBundles(),
hasResourceBundles()Collection<ResourceBundle> getResourceBundles()
addResourceBundle as well as any default resource bundles.
addResourceBundle(java.util.ResourceBundle),
hasResourceBundles()boolean hasResourceBundles()
addResourceBundle(java.util.ResourceBundle),
getResourceBundles()void setLanguage(String lang)
This is used when filling localized text
values.
lang - a 2-letter language code for the language to be used by
this templategetLanguage()String getLanguage()
filling localized text values. If
the language has not been set, it defaults to
the language set by the RIFE configuration parameter "L10N_DEFAULT_LANGUAGE".
setLanguage(java.lang.String)
void setExpressionVar(String name,
Object value)
name - the name of the variablevalue - the value to associate with the given variable namesetExpressionVars(java.util.Map) ,
getExpressionVars()void setExpressionVars(Map<String,Object> map)
setExpressionVar for each entry in the given map.
map - a map from variable name to variable valuesetExpressionVar(java.lang.String, java.lang.Object),
getExpressionVars()Map<String,Object> getExpressionVars()
setExpressionVar(java.lang.String, java.lang.Object),
setExpressionVars(java.util.Map)
void cacheObject(String key,
Object value)
key - a name under which the given value should be storedvalue - an objectObject getCacheObject(String key)
null if no such cached object exists. As noted
in cacheObject(java.lang.String, java.lang.Object), you should probably not use this method to
avoid conflicting with RIFE's internal use of the cache.
key - a key whose associated cached object should be returned
null
if none existsMap<URL,Long> getDependencies()
String getName()
String getFullName()
String getDefaultContentType()
text/html.
null if no default content type is known for this template instance
Object clone()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||