Interface Template
- All Superinterfaces:
Cloneable
- All Known Implementing Classes:
AbstractTemplate
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,
...).
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addGeneratedValue
(String valueId) Registers a value IDs as being generated by RIFE2.void
addGeneratedValues
(Collection<String> valueIds) Registers a collection of value IDs as being generated by RIFE2.void
addResourceBundle
(ResourceBundle resourceBundle) Adds a resource bundle to this template.void
addResourceBundles
(Collection<ResourceBundle> resourceBundles) Adds a list of resource bundles to this template.void
appendBlock
(String valueBlockId) Appends the content of a block to a value.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 givenvalue
.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 callingString.valueOf
on the givenvalue
to the specified value in this template.void
appendValue
(String id, String value) Appends the given string, or an empty string ifvalue
isnull
, to the specified value in this template.void
appendValueEncoded
(String id, Object value) Appends the result of callingString.valueOf
on the givenvalue
to the specified value in this template and encodes it with theTemplateEncoder
that's registered for this templatevoid
blankValue
(String id) Set the content of the specified value to an empty string.void
clear()
Resets all values in this template and removes any resource bundles.clone()
Returns a shallow copy of this template, with the same values.int
Returns the number of values in this template which have been set.Returns an anonymous value that can be used to construct complex content for use within this template.Creates a new template, using the same factory, name and encoding as those that were used to create this template instance.Fills all values in this template which match "l10n:key
", where "key
" is a key in a resource bundle registered for this template.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.Evaluates all values in this template with ID's of the form "render:class
" or "render:class:differentiator
r", where "class
" is the fully-qualified name of a class which extendsValueRenderer
, the result of callingValueRenderer.render
on a new instance of the class.getAttribute
(String name) Returns the data of an attribute that was set in this template instance.Returns the name and data of all attributes that have been set in this template instance.String[]
Returns a list of the ID's of all values present in this template, including set and unset values.Returns this template's bean handler.Returns the evaluated content of the specified block as a text.Returns the entire content of the template and finalize all non evaluated values.Returns this template's default content type, for exampletext/html
.Returns the original text of the specified value, before any modification that may have been made usingsetValue(java.lang.String, java.util.List<java.lang.CharSequence>)
or similar methods.Returns the content of the specified block as a list with all the individual parts.Returns the content of this template as a list with all the individual parts.Returns a list of URL's that this template depends on, and their last modification dates (in milliseconds since the Unix epoch).Returns the encoder that this template uses to convert strings to values in the template's generated text output.Returns the encoding of this the content of this template.Returns the unique identifier of the factory that was used to instantiate this template.String[]
getFilteredBlock
(String filter, String id) Returns the matched data of a block that matched a particular filter at template compilation.Collection<String[]>
getFilteredBlocks
(String filter) Each template type supports a set of special block tags that are used for adding automated features like localization, config value setting, ...String[]
getFilteredValue
(String filter, String id) Returns the matched data of a value that matched a particular filter at template compilation.Collection<String[]>
getFilteredValues
(String filter) Each template type supports a set of special value tags that are used for adding automated features like authentication, localization, value rendering, config value setting, ...Returns this template's form builder.Returns this template's full name, as it was used to instantiate it by a template factory.Returns this template's current 2-letter language code.long
Returns when the file corresponding to this template was modified, in milliseconds since the Unix epoch.getName()
Returns this template's name, without path information or file extension.Returns a list of the resource bundles used by this template.Returns a collection of the ID's of all values in this template which have not been set.Returns the current content of the specified value as a string.getValueOrAttribute
(String name) Returns the content of a value or the data of an attribute with a particular name.boolean
hasAttribute
(String name) Checks whether an attribute exists in this template instance.boolean
Returns whether this template contains a block with the given ID.boolean
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
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
Returns whether the specified value has been generated by RIFE2.boolean
isValueSet
(String id) Returns whether the specified value has been set.void
removeAttribute
(String name) Removes an attribute from this template instance.void
removeBean
(Object bean) Reverts all values to their defaults when the identifiers match properties of the given bean, whether those values were set with a previous call tosetBean
.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 tosetBean
.void
Reverts the generated values back to their default value.void
removeValue
(String id) Reverts the specified value back to its default value.void
removeValues
(Collection<String> ids) Reverts the specified values back to their default value.void
setAttribute
(String name, Object value) Sets an attribute that will be associated with this template instance.void
setAttributes
(Map<String, Object> map) Sets the given attributes to the corresponding data.void
Sets all values in this template whose identifiers match names of properties in the given bean.void
Sets all values in this template whose names match names of properties in the given bean, preceded by the given prefix.void
Sets all values in this template whose names match names of properties in the given bean, preceded by the given prefix, if present.void
Replaces the specified value with the content of the specified block.void
Replaces the specified value with the content of the specified block.void
setLanguage
(String lang) Sets this template's current language code, such as "en".void
Sets the specified value in this template totrue
orfalse
depending on the givenvalue
.void
Sets the specified value in this template to the single specified character.void
Sets the specified value in this template to the given characters.void
Sets the specified value in this template to the specified range of the given character string.void
Sets the specified value in this template to the given double precision floating point value.void
Sets the specified value in this template to the given floating point value.void
Sets the specified value in this template to the given integer.void
Sets the specified value in this template to the given long.void
setValue
(String id, CharSequence value) Sets the specified value in this template to the given character sequence, or an empty character sequence ifvalue
isnull
.void
Sets the specified value in this template to the result of callingString.valueOf
on the givenvalue
.void
Sets the specified value in this template to the given string, or an empty string ifvalue
isnull
.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, InternalValue internalValue) Sets the specified value in this template to the value of the given internal value.void
Sets the specified value in this template to the current content of the given template.void
setValueEncoded
(String id, Object value) Sets the specified value in this template to the result of callingString.valueOf
on the givenvalue
and encodes it with theTemplateEncoder
that's registered for this templatevoid
write
(OutputStream out) This method is a shorthand forwriteContent(OutputStream)
.void
writeBlock
(String id, OutputStream out) Writes the evaluated contents of the specified block to the given output stream, usingUTF-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 Details
-
appendBlock
Appends the content of a block to a value. The values used by the block will be captured when this method is called, so any future changes to template values will not affect text which was appended when this method is called.- Parameters:
valueBlockId
- the ID of the value and the block- Throws:
TemplateException
- when thevalueId
orblockId
aren't known- Since:
- 1.0
- See Also:
-
appendBlock
Appends the content of a block to a value. The values used by the block will be captured when this method is called, so any future changes to template values will not affect text which was appended when this method is called.- Parameters:
valueId
- the ID of the valueblockId
- the ID of the block- Throws:
TemplateException
- when thevalueId
orblockId
aren't known- Since:
- 1.0
- See Also:
-
setBlock
Replaces the specified value with the content of the specified block. The values used by the block will be captured when this method is called, so any future changes to template values will not affect the specified value text.- Parameters:
valueBlockId
- the ID of the value and the block- Throws:
TemplateException
- when thevalueId
orblockId
aren't known- Since:
- 1.0
- See Also:
-
setBlock
Replaces the specified value with the content of the specified block. The values used by the block will be captured when this method is called, so any future changes to template values will not affect the specified value text.- Parameters:
valueId
- the ID of the valueblockId
- the ID of the block- Throws:
TemplateException
- when thevalueId
orblockId
aren't known- Since:
- 1.0
- See Also:
-
getBlock
Returns the evaluated content of the specified block as a text.- Parameters:
id
- the ID of the block in the template- Returns:
- the evaluated textual content of the specified block
- Throws:
TemplateException
- when the block ID isn't known- Since:
- 1.0
- See Also:
-
getContent
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 (resource bundle localization, block localization, value renderers, ...).
- Returns:
- the entire textual content of the template
- Throws:
TemplateException
- when an error occurred during the processing of the specialized tags- Since:
- 1.0
- See Also:
-
writeBlock
Writes the evaluated contents of the specified block to the given output stream, usingUTF-8
encoding.- Parameters:
id
- the ID of the blockout
- the stream to write to- Throws:
IOException
- when errors occur during the manipulation of the output streamTemplateException
- when the block ID isn't known- Since:
- 1.0
- See Also:
-
writeContent
Writes the complete evaluated template content to the given stream, using UTF-8 encoding.- Parameters:
out
- the stream to which the template contents should be written- Throws:
IOException
- when errors occur during the manipulation of the output streamTemplateException
- when an error occurs during the template content evaluation- Since:
- 1.0
- See Also:
-
writeContent
Writes the complete evaluated template content to the given stream, using the specified charset for encoding.- Parameters:
out
- the stream to which the template contents should be writtencharsetName
- the name of the charset to use- Throws:
IOException
- when errors occur during the manipulation of the output stream; orwhen the character set isn't valid
TemplateException
- when an error occurs during the template content evaluation- Since:
- 1.0
- See Also:
-
write
This method is a shorthand forwriteContent(OutputStream)
.- Parameters:
out
- the stream to which the template contents should be written- Throws:
IOException
- when errors occur during the manipulation of the output stream; orwhen the character set isn't valid
TemplateException
- when an error occurs during the template content evaluation- Since:
- 1.0
- See Also:
-
getDeferredBlock
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- Returns:
- a list of the contents of the specified block
- Throws:
TemplateException
- if no such block exists; orif an error occurred during the retrieval
- Since:
- 1.0
- See Also:
-
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. This structure is mainly used internally by the framework. The list structure also makes it possible to optimize performance and memory usage.
- Returns:
- a list of the contents of this template
- Throws:
TemplateException
- if an error occurred during the retrieval- Since:
- 1.0
- See Also:
-
createInternalValue
InternalValue createInternalValue()Returns an anonymous value that can be used to construct complex content for use within this template. SeeInternalValue
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.- Returns:
- a new internal value instance for constructing more complex parts of this template
- Since:
- 1.0
- See Also:
-
setValue
Sets the specified value in this template to content that's structured in the internal format.- Parameters:
id
- the ID of the value in this templatedeferredContent
- content in the internal format- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the value of the given internal value.- Parameters:
id
- the ID of the value in this templateinternalValue
- an internal value,null
set the value content to blank content- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the result of callingString.valueOf
on the givenvalue
.- Parameters:
id
- the ID of the value in this templatevalue
- an object- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template totrue
orfalse
depending on the givenvalue
.- Parameters:
id
- the ID of the value in this templatevalue
- a boolean value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the single specified character.- Parameters:
id
- the ID of the value in this templatevalue
- a character- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the given characters. The given value must not benull
.- Parameters:
id
- the ID of the value in this templatevalue
- a string of characters- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the specified range of the given character string. The specified number of bytes fromvalue
will be used, starting at the character specified byoffset
.- Parameters:
id
- the ID of the value in this templatevalue
- a character stringoffset
- the index invalue
of the first character to usecount
- the number of characters to use- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the given double precision floating point value. This method uses the String.valueOf method to print the given value, which probably prints more digits than you like. You probably wantString.format
orNumberFormat
instead.- Parameters:
id
- the ID of the value in this templatevalue
- a floating point value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValue
Sets the specified value in this template to the given floating point value. This method uses the String.valueOf method to print the given value, which probably prints more digits than you like. You probably wantString.format
orNumberFormat
instead.- Parameters:
id
- the ID of the value in this templatevalue
- a floating point value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValue
Sets the specified value in this template to the given integer.- Parameters:
id
- the ID of the value in this templatevalue
- an integer- Throws:
TemplateException
- if the specified value does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the given long.- Parameters:
id
- the ID of the value in this templatevalue
- a long- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the given string, or an empty string ifvalue
isnull
.- Parameters:
id
- the ID of the value in this templatevalue
- a string, ornull
- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the given character sequence, or an empty character sequence ifvalue
isnull
.- Parameters:
id
- the ID of the value in this templatevalue
- a character sequence, ornull
- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValue
Sets the specified value in this template to the current content of the given template. The given template's value will be evaluated immediately, instead of being stored to be evaluated later.If the given template is
null
, the specified value will be set to an empty string.- Parameters:
id
- the ID of the value in this templatetemplate
- a template- Throws:
TemplateException
- if the specified value ID does not exist in this template; orif an error occurred during the evaluation of the template parameter
- Since:
- 1.0
- See Also:
-
setValueEncoded(java.lang.String, java.lang.Object)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setValueEncoded
Sets the specified value in this template to the result of callingString.valueOf
on the givenvalue
and encodes it with theTemplateEncoder
that's registered for this template- Parameters:
id
- the ID of the value in this templatevalue
- an object to will be encoded- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
setBean
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" andlast
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.
- Parameters:
bean
- a bean whose properties will be used to fill in values in the template- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
- See Also:
-
setBean
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" andlast
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.
- Parameters:
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- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
- See Also:
-
setBean
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 isnull
, 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" andlast
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
istrue
, 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.
- Parameters:
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 property values have to be encoded; orfalse
otherwise- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
- See Also:
-
removeBean
Reverts all values to their defaults when the identifiers match properties of the given bean, whether those values were set with a previous call tosetBean
. 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.- Parameters:
bean
- a bean- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
- See Also:
-
removeBean
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 tosetBean
. 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.- Parameters:
bean
- a bean whose properties will be used to determine which values to remove from the templateprefix
- a prefix- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
- See Also:
-
appendValue
Appends the result of callingString.valueOf
on the givenvalue
to the specified value in this template.- Parameters:
id
- the ID of the value in this templatevalue
- an object- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends"true"
or"false"
to the specified value in this template, depending on the givenvalue
.- Parameters:
id
- the ID of the value in this templatevalue
- a boolean value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValue
Appends the single specified character to the specified value in this template.- Parameters:
id
- the ID of the value in this templatevalue
- a character- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given characters to the specified value in this template. The given value must not benull
.- Parameters:
id
- the ID of the value in this templatevalue
- a string of characters- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the specified range of the given character string to the specified value in this template. The specified number of bytes fromvalue
will be used, starting at the character specified byoffset
.- Parameters:
id
- the ID of the value in this templatevalue
- a character stringoffset
- the index invalue
of the first character to usecount
- the number of characters to use- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given double precision floating point value to the specified value in this template. This method uses the String.valueOf method to print the given value, which probably prints more digits than you like. You probably wantString.format
orNumberFormat
instead.- Parameters:
id
- the ID of the value in this templatevalue
- a floating point value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given floating point value to the specified value in this template. This method uses the String.valueOf method to print the given value, which probably prints more digits than you like. You probably wantString.format
orNumberFormat
instead.- Parameters:
id
- the ID of the value in this templatevalue
- a floating point value- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given integer to the specified value in this template.- Parameters:
id
- the ID of the value in this templatevalue
- an integer- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given long to the specified value in this template.- Parameters:
id
- the ID of the value in this templatevalue
- a long- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValue
Appends the given string, or an empty string ifvalue
isnull
, to the specified value in this template.- Parameters:
id
- the ID of the value in this templatevalue
- a string, ornull
- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
appendValueEncoded
Appends the result of callingString.valueOf
on the givenvalue
to the specified value in this template and encodes it with theTemplateEncoder
that's registered for this template- Parameters:
id
- the ID of the value in this templatevalue
- an object to will be encoded- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
getValue
Returns the current content of the specified value as a string.- Parameters:
id
- the ID of a value in this template- Returns:
- the current content value of the specified value
- Throws:
TemplateException
- if the specified value ID does not exist in this template- Since:
- 1.0
- See Also:
-
getDefaultValue
Returns the original text of the specified value, before any modification that may have been made usingsetValue(java.lang.String, java.util.List<java.lang.CharSequence>)
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, ornull
- Returns:
- the original text value of the specified value
- Since:
- 1.0
- See Also:
-
hasDefaultValue
Returns whether a default value was specified in this template for the specified value.- Parameters:
id
- the ID of a value in this template- Returns:
- whether the specified value has a default value
- Since:
- 1.0
- See Also:
-
getFilteredBlocks
Each template type supports a set of special block tags that are used for adding automated features like localization, 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
.- Parameters:
filter
- a template factory regular expression- Returns:
- a list of captured groups for matching block ID's
- Since:
- 1.0
- See Also:
-
hasFilteredBlocks
Returns whether any block matched a particular filter at template compilation.- Parameters:
filter
- a template factory regular expression- Returns:
- whether any matching blocks exist in this template
- Since:
- 1.0
- See Also:
-
getFilteredBlock
Returns the matched data of a block that matched a particular filter at template compilation.- Parameters:
filter
- a template factory regular expressionid
- the ID of matched block- Returns:
- the matched data; or
null
of no such filtered block was matched at template compilation time - Since:
- 1.5
- See Also:
-
getFilteredValues
Each template type supports a set of special value tags that are used for adding automated features like authentication, localization, value rendering, 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
.- Parameters:
filter
- a template factory regular expression- Returns:
- a list of captured groups for matching value ID's
- Since:
- 1.0
- See Also:
-
hasFilteredValues
Returns whether any value matched a particular filter at template compilation.- Parameters:
filter
- a template factory regular expression- Returns:
- whether any matching values exist in this template
- Since:
- 1.0
- See Also:
-
getFilteredValue
Returns the matched data of a value that matched a particular filter at template compilation.- Parameters:
filter
- a template factory regular expressionid
- the ID of matched value- Returns:
- the matched data; or
null
of no such filtered value was matched at template compilation time - Since:
- 1.5
- See Also:
-
evaluateL10nTags
Fills all values in this template which match "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.
- Returns:
- the list of names of the template values that were generated
- Since:
- 1.0
-
evaluateLangTags
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.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.- Parameters:
id
- the ID whose language tag should be filled with the appropriate block- Returns:
- the list of names of the template values that were generated
- Since:
- 1.0
-
evaluateRenderTags
Evaluates all values in this template with ID's of the form "render:class
" or "render:class:differentiator
r", where "class
" is the fully-qualified name of a class which extendsValueRenderer
, the result of callingValueRenderer.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 extendsValueRenderer
, a value "render:org.rifers.something.MyRenderer:test
" would create a new instance ofMyRenderer
(using its no-arg constructor), callrender(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 content is generated. You can manually call this method to force evaluation of the tags at any time.
- Returns:
- the list of names of the template values that were generated
- Throws:
TemplateException
- if a class in a render tag cannot be instantiated- Since:
- 1.0
-
hasBlock
Returns whether this template contains a block with the given ID.- Parameters:
id
- the prospective ID of a block- Returns:
- whether this template contains a block with the given ID
- Since:
- 1.0
- See Also:
-
isValueSet
Returns whether the specified value has been set. If this method returnsfalse
, 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
.If the value was automatically set by RIFE2, this method will not return
true
, butisValueGenerated(java.lang.String)
will.- Parameters:
id
- the ID of a value in this template- Returns:
- whether the specified value has been set
- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueGenerated(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
isValueGenerated
Returns whether the specified value has been generated by RIFE2. This values will not be return withisValueSet(java.lang.String)
.If no such value exists in this template, this method will not throw an exception, it will return
false
.- Parameters:
id
- the ID of a value in this template- Returns:
- whether the specified value has been set
- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
addGeneratedValue
Registers a value IDs as being generated by RIFE2.- Parameters:
valueId
- the value ID to register as generated values- Since:
- 1.5
- See Also:
-
addGeneratedValues
Registers a collection of value IDs as being generated by RIFE2.- Parameters:
valueIds
- the value IDs to register as generated values- Since:
- 1.0
- See Also:
-
countValues
int countValues()Returns the number of values in this template which have been set.- Returns:
- the number of values in this template which have been set
- Since:
- 1.0
-
removeValue
Reverts the specified value back to its default value.- Parameters:
id
- the ID of a value in this template- Since:
- 1.0
- See Also:
-
removeValues
Reverts the specified values back to their default value.- Parameters:
ids
- the IDs of values in this template- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
hasValueId(java.lang.String)
-
removeGeneratedValues
void removeGeneratedValues()Reverts the generated values back to their default value.- Since:
- 1.0
- See Also:
-
blankValue
Set the content of the specified value to an empty string.- Parameters:
id
- the ID of a value in this template- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
hasValueId(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
-
clear
void clear()Resets all values in this template and removes any resource bundles. Configuration and localization tags are re-evaluated.- Since:
- 1.0
-
getAvailableValueIds
String[] getAvailableValueIds()Returns a list of the ID's of all values present in this template, including set and unset values.- Returns:
- a list of ID's of all set and unset value
- Since:
- 1.0
-
getUnsetValueIds
Collection<String> getUnsetValueIds()Returns a collection of the ID's of all values in this template which have not been set.- Returns:
- a collection of ID's of values in this template which have not been set
- Since:
- 1.0
-
hasValueId
Returns whether this template contains a value with the given ID.- Parameters:
id
- the potential ID of a value in this template- Returns:
- whether this template contains a value with the given ID
- Since:
- 1.0
- See Also:
-
appendValue(java.lang.String, java.lang.Object)
appendValueEncoded(java.lang.String, java.lang.Object)
setValue(java.lang.String, java.util.List<java.lang.CharSequence>)
setValueEncoded(java.lang.String, java.lang.Object)
isValueSet(java.lang.String)
removeValue(java.lang.String)
removeValues(java.util.Collection<java.lang.String>)
blankValue(java.lang.String)
hasValueId(java.lang.String)
-
getModificationTime
long getModificationTime()Returns when the file corresponding to this template was modified, in milliseconds since the Unix epoch.- Returns:
- the time at which the underlying template file was modified
- Since:
- 1.0
-
createNewInstance
Template createNewInstance()Creates a new template, using the same factory, name and encoding as those that were used to create this template instance.- Returns:
- a new template instance with the same parameters as this one
- Since:
- 1.0
-
getFactoryIdentifier
String getFactoryIdentifier()Returns the unique identifier of the factory that was used to instantiate this template.- Returns:
- the unique identifier of this template's factory
- Since:
- 1.0
-
getEncoding
String getEncoding()Returns the encoding of this the content of this template.- Returns:
- the encoding that was used when instantiating the template
- Since:
- 1.0
-
getBeanHandler
BeanHandler getBeanHandler()Returns this template's bean handler. The bean handler is used for filling bean values into template values, and for building forms.- Returns:
- this template's bean handler
- Since:
- 1.0
-
getFormBuilder
FormBuilder getFormBuilder()Returns this template's form builder. The form builder can be used for generating forms and fields.- Returns:
- this template's form builder
- Since:
- 1.0
-
getEncoder
TemplateEncoder getEncoder()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.- Returns:
- this template's encoder
- Since:
- 1.0
-
addResourceBundles
Adds a list of resource bundles to this template. Resource bundles are used in many places, including when generating labels for forms, generating options for<select>
tags, and using localized text.- Parameters:
resourceBundles
- a list of resource bundle- Since:
- 1.0
- See Also:
-
addResourceBundle
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 using localized text.- Parameters:
resourceBundle
- a resource bundle- Since:
- 1.0
- See Also:
-
getResourceBundles
List<ResourceBundle> getResourceBundles()Returns a list of the resource bundles used by this template. This will contain any bundles added throughaddResourceBundle
as well as any default resource bundles.- Returns:
- a list of this template's resource bundles
- Since:
- 1.0
- See Also:
-
hasResourceBundles
boolean hasResourceBundles()Returns whether this template has any resource bundles registered.- Returns:
- whether this template contains any resource bundles
- Since:
- 1.0
- See Also:
-
setLanguage
Sets this template's current language code, such as "en".This is used when
filling localized text values
.- Parameters:
lang
- a 2-letter language code for the language to be used by this template- Since:
- 1.0
- See Also:
-
getLanguage
String getLanguage()Returns this template's current 2-letter language code. This code is used whenfilling localized text values
. If the language has not been set, it defaults to the language set by the RIFE configuration parameter "L10N_DEFAULT_LANGUAGE
".- Returns:
- the 2-letter language code currently used by this template
- Since:
- 1.0
- See Also:
-
setAttribute
Sets an attribute that will be associated with this template instance.For general purpose attributes of object instances, it's recommended to use the fully qualified classname of the object as the attribute name.
- Parameters:
name
- the name of the attributevalue
- the value of the attribute- Since:
- 1.5
- See Also:
-
setAttributes
Sets the given attributes to the corresponding data. Calling this method is equivalent to callingsetAttribute
for each entry in the given map.- Parameters:
map
- a map of attribute names and data- Since:
- 1.5
- See Also:
-
removeAttribute
Removes an attribute from this template instance.- Parameters:
name
- the name of the attribute- Since:
- 1.5
- See Also:
-
hasAttribute
Checks whether an attribute exists in this template instance.- Returns:
true
if the attribute exists;false
otherwise- Since:
- 1.5
- See Also:
-
getAttribute
Returns the data of an attribute that was set in this template instance.- Returns:
- the attribute's data; or
null
of no such attribute could be found - Since:
- 1.5
- See Also:
-
getAttributes
Returns the name and data of all attributes that have been set in this template instance.- Returns:
- the attributes currently set in this template
- Since:
- 1.5
- See Also:
-
getValueOrAttribute
Returns the content of a value or the data of an attribute with a particular name.If the value with the provided name has content, it will be returned. Otherwise, if an attribute with the provided name has data, the string presentation of that will be returned. If neither are present, and a default value was provided, that will be returned. Otherwise,
null
will be returned.- Parameters:
name
- the name of the value or attribute- Returns:
- the string presentation of the value or attribute with the provided name; or
null
if neither have data - Since:
- 1.5
-
getDependencies
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.- Returns:
- a list of URL's and last modification dates of resources on which this template depends
- Since:
- 1.0
-
getName
String getName()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".- Returns:
- this template's name, without path or file extension
- Since:
- 1.0
-
getFullName
String getFullName()Returns this template's full name, as it was used to instantiate it by a template factory.- Returns:
- this template's full name
- Since:
- 1.0
-
getDefaultContentType
String getDefaultContentType()Returns this template's default content type, for exampletext/html
.- Returns:
- this template's default content type; or
null
if no default content type is known for this template instance - Since:
- 1.0
-
clone
Object clone()Returns a shallow copy of this template, with the same values.- Returns:
- a shallow copy of this template
- Since:
- 1.0
-