|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.template.AbstractTemplate
public abstract class AbstractTemplate
| Field Summary | |
|---|---|
protected BeanHandler |
mBeanHandler
|
protected Map<String,Object> |
mCache
|
protected Map<String,InternalValue> |
mConstructedValues
|
protected String |
mDefaultContentType
|
protected List<ResourceBundle> |
mDefaultResourceBundles
|
protected TemplateEncoder |
mEncoder
|
protected Map<String,Object> |
mExpressionVars
|
protected Map<String,InternalString> |
mFixedValues
|
protected TemplateInitializer |
mInitializer
|
protected String |
mLanguage
|
protected List<ResourceBundle> |
mResourceBundles
|
| Constructor Summary | |
|---|---|
protected |
AbstractTemplate()
|
| 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. |
protected abstract boolean |
appendBlockExternalForm(String id,
ExternalValue result)
|
protected abstract boolean |
appendBlockInternalForm(String id,
InternalValue result)
|
protected abstract boolean |
appendDefaultValueExternalForm(String id,
ExternalValue result)
|
protected abstract boolean |
appendDefaultValueInternalForm(String id,
InternalValue result)
|
protected void |
appendTextInternal(InternalValue value,
CharSequence text)
|
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. |
protected void |
appendValueExternalForm(String id,
String tag,
ExternalValue result)
|
protected void |
appendValueInternalForm(String id,
String tag,
InternalValue result)
|
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. |
Template |
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. |
abstract 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. |
abstract String |
getDefaultValue(String id)
Returns the original text of the specified value, before any modification that may have been made using Template.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. |
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. |
abstract 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, ... |
abstract 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 |
getLanguage()
Returns this template's current 2-letter language code. |
abstract long |
getModificationTime()
Returns when the file corresponding to this template was modified, in milliseconds since the Unix epoch. |
Collection<ResourceBundle> |
getResourceBundles()
Returns a list of the resource bundles used by this template. |
abstract 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. |
abstract boolean |
hasFilteredBlocks(String filter)
Returns whether any block matched a particular filter at template compilation. |
abstract 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. |
abstract boolean |
hasValueId(String id)
Returns whether this template contains a value with the given ID. |
protected void |
increasePartsCapacityInternal(InternalValue value,
int size)
|
protected void |
increaseValuesCapacityInternal(InternalValue value,
int size)
|
protected static boolean |
isTemplateClassModified(URL templateResource,
long templateModificationTime,
Map templateDependencies,
String templateModificationState,
ResourceFinder resourceFinder,
String modificationState)
|
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 |
setDefaultContentType(String defaultContentType)
|
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 Template.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 |
writeBlock(String id,
OutputStream out,
String charsetName)
|
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. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.uwyn.rife.template.Template |
|---|
getDependencies, getFullName, getName |
| Field Detail |
|---|
protected TemplateInitializer mInitializer
protected Map<String,InternalString> mFixedValues
protected Map<String,InternalValue> mConstructedValues
protected BeanHandler mBeanHandler
protected TemplateEncoder mEncoder
protected List<ResourceBundle> mDefaultResourceBundles
protected List<ResourceBundle> mResourceBundles
protected Map<String,Object> mExpressionVars
protected String mLanguage
protected Map<String,Object> mCache
protected String mDefaultContentType
| Constructor Detail |
|---|
protected AbstractTemplate()
| Method Detail |
|---|
public final void appendBlock(String valueId,
String blockId)
throws TemplateException
Template
appendBlock in interface TemplatevalueId - the ID of the valueblockId - the ID of the block
TemplateException - when the valueId or
blockId aren't knownTemplate.setBlock(java.lang.String, java.lang.String),
Template.getBlock(java.lang.String),
Template.getContent(),
Template.hasBlock(java.lang.String)
public final void setBlock(String valueId,
String blockId)
throws TemplateException
Template
setBlock in interface TemplatevalueId - the ID of the valueblockId - the ID of the block
TemplateException - when the valueId or
blockId aren't knownTemplate.appendBlock(java.lang.String, java.lang.String),
Template.getBlock(java.lang.String),
Template.getContent(),
Template.hasBlock(java.lang.String)
public String getBlock(String id)
throws TemplateException
Template
getBlock in interface Templateid - the ID of the block in the template
TemplateException - when the block ID isn't knownTemplate.appendBlock(java.lang.String, java.lang.String),
Template.setBlock(java.lang.String, java.lang.String),
Template.getContent(),
Template.hasBlock(java.lang.String)
public final String getContent()
throws TemplateException
TemplateValues 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, ...).
getContent in interface TemplateTemplateException - when an error occurred during the
processing of the specialized tagsTemplate.appendBlock(java.lang.String, java.lang.String),
Template.setBlock(java.lang.String, java.lang.String),
Template.getBlock(java.lang.String),
Template.hasBlock(java.lang.String)
public void writeBlock(String id,
OutputStream out)
throws IOException,
TemplateException
TemplateUTF-8
encoding.
writeBlock in interface Templateid - 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 knownTemplate.writeContent(OutputStream),
Template.writeContent(OutputStream, String),
Template.write(java.io.OutputStream)
public void writeBlock(String id,
OutputStream out,
String charsetName)
throws IOException,
TemplateException
IOException
TemplateException
public final void writeContent(OutputStream out)
throws IOException,
TemplateException
Template
writeContent in interface Templateout - 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 evaluationTemplate.writeBlock(java.lang.String, java.io.OutputStream),
Template.writeContent(OutputStream, String),
Template.write(java.io.OutputStream)
public final void writeContent(OutputStream out,
String charsetName)
throws IOException,
TemplateException
Template
writeContent in interface Templateout - 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 evaluationTemplate.writeBlock(java.lang.String, java.io.OutputStream),
Template.writeContent(OutputStream),
Template.write(java.io.OutputStream)
public final void write(OutputStream out)
throws IOException,
TemplateException
TemplateTemplate.writeContent(OutputStream).
write in interface Templateout - 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 evaluationTemplate.writeBlock(java.lang.String, java.io.OutputStream),
Template.writeContent(OutputStream),
Template.writeContent(OutputStream, String)
public final List<CharSequence> getDeferredBlock(String id)
throws TemplateException
TemplateThis 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.
getDeferredBlock in interface Templateid - the ID of a block in this template
TemplateException - if no such block exists; or
if an error occurred during the retrieval
Template.getDeferredContent()
public final List<CharSequence> getDeferredContent()
throws TemplateException
TemplateThis 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.
getDeferredContent in interface TemplateTemplateException - if an error occurred during the retrievalTemplate.getDeferredBlock(java.lang.String)
public List<String> evaluateRenderTags()
throws TemplateException
TemplateRENDER: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 Template.getContent()). You can
manually call this method to force evaluation of the tags earlier than
that.
evaluateRenderTags in interface TemplateTemplateException - if a class in a render tag cannot be
instantiatedpublic List<String> evaluateConfigTags()
TemplateCONFIG: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.
evaluateConfigTags in interface Templatepublic List<String> evaluateL10nTags()
TemplateL10N: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.
evaluateL10nTags in interface Templatepublic List<String> evaluateLangTags(String id)
TemplateLANG: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 Template.getContent()). You can manually call
this method to force evaluation of the tags earlier than that.
evaluateLangTags in interface Templateid - the ID whose language tag should be filled with the
appropriate block
public List<String> evaluateExpressionTags(String id)
TemplateOGNL: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 Template.getContent()). You can manually call
this method to force evaluation of the tags earlier than that.
evaluateExpressionTags in interface Templateid - the ID whose expression tag will be replaced with the value
of the evaluated expression in the tag ID
public List<String> evaluateExpressionConfigTags(String id)
TemplateThe prefix for OGNL is "OGNL:", the prefix for Groovy
is "GROOVY:" and the prefix for Janino is "JANINO:".
The context for the expressions will be the Config object
returned by Config.getRepInstance().
Expression config tags are evaluated automatically when the output
is generated (such as when calling Template.getContent()). You can
manually call this method to force evaluation of the tags earlier than
that.
evaluateExpressionConfigTags in interface Templateid - the ID whose expression tag will be replaced with the value
of the evaluated expression in the tag ID
public final InternalValue createInternalValue()
TemplateInternalValue 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.
createInternalValue in interface TemplateInternalValue
public final void setValue(String id,
List<CharSequence> deferredContent)
throws TemplateException
Template
setValue in interface Templateid - the ID of the value in this templatedeferredContent - content in the internal format
TemplateException - if the specified value ID does not exist
in this templateTemplate.appendValue(java.lang.String, java.lang.Object),
Template.isValueSet(java.lang.String),
Template.removeValue(java.lang.String),
Template.removeValues(java.util.List) ,
Template.blankValue(java.lang.String),
Template.hasValueId(java.lang.String)
public final void setValue(String id,