freemarker.ext.beans

Class ResourceBundleModel

Implemented Interfaces:
AdapterTemplateModel, TemplateHashModel, TemplateHashModelEx, TemplateMethodModel, TemplateMethodModelEx, TemplateModel, WrapperTemplateModel

public class ResourceBundleModel
extends BeanModel
implements TemplateMethodModelEx

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:

Version:
$Id: ResourceBundleModel.java,v 1.22.2.2 2007/04/02 13:19:37 szegedia Exp $
Author:
Attila Szegedi

Field Summary

Fields inherited from class freemarker.ext.beans.BeanModel

object, wrapper

Fields inherited from interface freemarker.template.TemplateModel

NOTHING

Constructor Summary

ResourceBundleModel(ResourceBundle bundle, BeansWrapper wrapper)

Method Summary

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()

Methods inherited from class freemarker.ext.beans.BeanModel

get, getAdaptedObject, getWrappedObject, hasPlainGetMethod, invokeGenericGet, isEmpty, keySet, keys, size, toString, unwrap, values, wrap

Constructor Details

ResourceBundleModel

public ResourceBundleModel(ResourceBundle bundle,
                           BeansWrapper wrapper)

Method Details

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.
Specified by:
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()

invokeGenericGet

protected TemplateModel invokeGenericGet(Map keyMap,
                                         Class clazz,
                                         String key)
            throws TemplateModelException
Overridden to invoke the getObject method of the resource bundle.
Overrides:
invokeGenericGet in interface BeanModel

isEmpty

public boolean isEmpty()
Returns true if this bundle contains no objects.
Specified by:
isEmpty in interface TemplateHashModel
Overrides:
isEmpty in interface BeanModel

keySet

protected Set keySet()
Overrides:
keySet in interface BeanModel

size

public int size()
Specified by:
size in interface TemplateHashModelEx
Overrides:
size in interface BeanModel