freemarker.ext.beans
Class ResourceBundleModel
- AdapterTemplateModel, TemplateHashModel, TemplateHashModelEx, TemplateMethodModel, TemplateMethodModelEx, TemplateModel, WrapperTemplateModel
public class ResourceBundleModel
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
$Id: ResourceBundleModel.java,v 1.22.2.2 2007/04/02 13:19:37 szegedia Exp $
Object | exec(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.
|
String | format(String key, Object[] params) - Provides direct access to caching format engine from code (instead of from script).
|
ResourceBundle | getBundle()
|
protected TemplateModel | invokeGenericGet(Map keyMap, Class clazz, String key) - Overridden to invoke the getObject method of the resource bundle.
|
boolean | isEmpty() - Returns true if this bundle contains no objects.
|
protected Set | keySet()
|
int | size()
|
get , getAdaptedObject , getWrappedObject , hasPlainGetMethod , invokeGenericGet , isEmpty , keySet , keys , size , toString , unwrap , values , wrap |
ResourceBundleModel
public ResourceBundleModel(ResourceBundle bundle,
BeansWrapper wrapper)
exec
public Object exec(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.
- exec in interface TemplateMethodModel
format
public String format(String key,
Object[] params)
throws MissingResourceException
Provides direct access to caching format engine from code (instead of from script).
getBundle
public ResourceBundle getBundle()