ResourceBundleModel (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.ext.beans, class: ResourceBundleModel

Package freemarker.ext.beans

# Class ResourceBundleModel

java.lang.Object
freemarker.ext.beans.BeanModel
freemarker.ext.beans.ResourceBundleModel

All Implemented Interfaces:
  `WrapperTemplateModel`, `AdapterTemplateModel`, `TemplateHashModel`, `TemplateHashModelEx`, `TemplateMethodModel`, `TemplateMethodModelEx`, `TemplateModel`, `TemplateModelWithAPISupport`

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:

- `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

- ## Field Summary

  ### Fields inherited from class freemarker.ext.beans.BeanModel

  `object, wrapper`

  ### Fields inherited from interface freemarker.template.TemplateModel

  `NOTHING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ResourceBundleModel​(ResourceBundle bundle, BeansWrapper wrapper)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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()`
  Helper method to support TemplateHashModelEx.
  `int`
  `size()`

  ### Methods inherited from class freemarker.ext.beans.BeanModel

  `get, get, getAdaptedObject, getAPI, getBeforeMethodCall, getWrappedObject, hasPlainGetMethod, keys, toString, unwrap, values, wrap`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### ResourceBundleModel

    public ResourceBundleModel​(ResourceBundle bundle, BeansWrapper wrapper)

- ## Method Details

  - ### 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 class `BeanModel`
    Throws:
      `TemplateModelException`

  - ### isEmpty

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

  - ### size

    public int size()
    Specified by:
      `size` in interface `TemplateHashModelEx`
    Overrides:
      `size` in class `BeanModel`
    Returns:
      the number of key/value mappings in the hash.

  - ### keySet

    protected Set keySet()
    Description copied from class: `BeanModel`
    Helper method to support TemplateHashModelEx. Returns the Set of Strings which are available via the TemplateHashModel interface. Subclasses that override `invokeGenericGet` to provide additional hash keys should also override this method.
    Overrides:
      `keySet` in class `BeanModel`

  - ### 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`
    Specified by:
      `exec` in interface `TemplateMethodModelEx`
    Parameters:
      `arguments` - a `List` of `TemplateModel`-s, containing the arguments passed to the method. If the implementation absolutely wants to operate on POJOs, it can use the static utility methods in the `DeepUnwrap` class to easily obtain them. However, unwrapping is not always possible (or not perfectly), and isn't always efficient, so it's recommended to use the original `TemplateModel` value as much as possible.
    Returns:
      the return value of the method, or `null`. If the returned value does not implement `TemplateModel`, it will be automatically wrapped using the `environment's object wrapper`.
    Throws:
      `TemplateModelException`

  - ### format

    public String format​(String key, Object[] params) throws MissingResourceException
    Provides direct access to caching format engine from code (instead of from script).
    Throws:
      `MissingResourceException`

  - ### getBundle

    public ResourceBundle getBundle()