freemarker.ext.beans
Class ResourceBundleModel
java.lang.Object
|
+--freemarker.ext.beans.ObjectModelBase
|
+--freemarker.ext.beans.ResourceBundleModel
- All Implemented Interfaces:
- TemplateHashModel, TemplateMethodModel, TemplateModel, TemplateObjectModel, TemplateScalarModel
- public final class ResourceBundleModel
- extends ObjectModelBase
- implements TemplateHashModel, TemplateMethodModel
A hash model that wraps a resource bundle. Makes it convenient to store
localized content in the data model. It also acts as a method model that will
take a resource key and arbitrary number of arguments and will apply
MessageFormat
with arguments on the string represented by the key.
Typical usages:
bundle.resourceKey
will retrieve the object from resource bundle
with key resourceKey
bundle("patternKey", arg1, arg2, arg3)
will retrieve the string
from resource bundle with key patternKey
, and will use it as a pattern
for MessageFormat with arguments arg1, arg2 and arg3
- Version:
- $Id: ResourceBundleModel.java,v 1.3 2002/05/11 10:20:30 run2000 Exp $
- Author:
- Attila Szegedi, attila@szegedi.org
Method Summary |
TemplateModel |
exec(java.util.List arguments)
Takes first argument as a resource key, looks up a string in resource bundle
with this key, then applies a MessageFormat.format on the string with the
rest of the arguments. |
java.lang.String |
format(java.lang.String key,
java.lang.Object[] params)
Provides direct access to caching format engine from code (instead of from script). |
TemplateModel |
get(java.lang.String key)
Retrieves the object with specified key from resource bundle, and returns it
wrapped in an appropriate TemplateModel. |
java.util.ResourceBundle |
getBundle()
|
static ResourceBundleModel |
getInstance(java.util.ResourceBundle object)
Returns a model wrapping the specified resource bundle object. |
int |
getType()
Returns the type of this object (which is TYPE_RESOURCE_BUNDLE) |
boolean |
isEmpty()
Returns true if this bundle contains no objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ResourceBundleModel
public ResourceBundleModel(java.util.ResourceBundle bundle)
getInstance
public static final ResourceBundleModel getInstance(java.util.ResourceBundle object)
- Returns a model wrapping the specified resource bundle object. If there is already
a cached model instance for this resource bundle, returns the cached model instance.
Models are cached using
WeakReference
objects. The caching can be turned
off by setting the expose.reflection.nocache system property to
true. In this case calling this method is equivalent to constructing a new model.
- Parameters:
object
- the resource bundle to wrap into a model.- Returns:
- the model for the resource bundle
getType
public int getType()
- Returns the type of this object (which is TYPE_RESOURCE_BUNDLE)
- Overrides:
getType
in class ObjectModelBase
get
public TemplateModel get(java.lang.String key)
throws TemplateModelException
- Retrieves the object with specified key from resource bundle, and returns it
wrapped in an appropriate TemplateModel.
- Specified by:
get
in interface TemplateHashModel
- Following copied from interface:
freemarker.template.TemplateHashModel
- Parameters:
key
- the name by which the TemplateModel
is identified in the template.- Returns:
- the
TemplateModel
referred to by the key,
or null
if not found.
isEmpty
public boolean isEmpty()
- Returns true if this bundle contains no objects.
- Specified by:
isEmpty
in interface TemplateModel
- Overrides:
isEmpty
in class ObjectModelBase
- Following copied from interface:
freemarker.template.TemplateModel
- Returns:
true
if this object is empty, otherwise false
exec
public TemplateModel exec(java.util.List arguments)
throws TemplateModelException
- Takes first argument as a resource key, looks up a string in resource bundle
with this key, then applies a MessageFormat.format on the string with the
rest of the arguments. The created MessageFormats are cached for later reuse.
- Specified by:
exec
in interface TemplateMethodModel
- Following copied from interface:
freemarker.template.TemplateMethodModel
- Parameters:
arguments
- a List
of String
objects
containing the values of the arguments passed to the method.- Returns:
- the
TemplateModel
produced by the method, or null
.
format
public java.lang.String format(java.lang.String key,
java.lang.Object[] params)
throws java.util.MissingResourceException
- Provides direct access to caching format engine from code (instead of from script).
getBundle
public java.util.ResourceBundle getBundle()