Top Description Fields Constructors Methods
org.springframework.context.support

public Class MessageSourceResourceBundle

extends ResourceBundle
Class Inheritance
Imports
java.util.Enumeration, .Locale, .ResourceBundle, org.springframework.context.MessageSource, .NoSuchMessageException, org.springframework.lang.Nullable, org.springframework.util.Assert

Helper class that allows for accessing a Spring org.springframework.context.MessageSource as a java.util.ResourceBundle. Used for example to expose a Spring MessageSource to JSTL web views.
Author
Juergen Hoeller
Since
27.02.2003
See Also
org.springframework.context.MessageSource, java.util.ResourceBundle, org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext

Field Summary

Modifier and TypeField and Description
private final Locale
private final MessageSource
Inherited from java.util.ResourceBundle:
parent

Constructor Summary

AccessConstructor and Description
public
MessageSourceResourceBundle(MessageSource
the MessageSource to retrieve messages from
source
,
Locale
the Locale to retrieve messages for
locale
)

Create a new MessageSourceResourceBundle for the given MessageSource and Locale.

public
MessageSourceResourceBundle(MessageSource
the MessageSource to retrieve messages from
source
,
Locale
the Locale to retrieve messages for
locale
,
ResourceBundle
the parent ResourceBundle to delegate to if no local message found
parent
)

Create a new MessageSourceResourceBundle for the given MessageSource and Locale.

Method Summary

Modifier and TypeMethod and Description
public boolean
containsKey(String
the resource key
key
)

Overrides java.util.ResourceBundle.containsKey.

This implementation checks whether the target MessageSource can resolve a message for the given key, translating NoSuchMessageException accordingly.
public Enumeration<String>
getKeys()

Implements abstract java.util.ResourceBundle.getKeys.

This implementation throws UnsupportedOperationException, as a MessageSource does not allow for enumerating the defined message codes.
public Locale
getLocale()

Overrides java.util.ResourceBundle.getLocale.

This implementation exposes the specified Locale for introspection through the standard ResourceBundle.getLocale() method.
protected Object
handleGetObject(String
the key for the desired object
key
)

Implements abstract java.util.ResourceBundle.handleGetObject.

This implementation resolves the code in the MessageSource.
Inherited from java.util.ResourceBundle:
clearCacheclearCachegetBaseBundleNamegetBundlegetBundlegetBundlegetBundlegetBundlegetBundlegetBundlegetBundlegetObjectgetStringgetStringArrayhandleKeySetkeySetsetParent

Field Detail

localeback to summary
private final Locale locale

Hides java.util.ResourceBundle.locale.

messageSourceback to summary
private final MessageSource messageSource

Constructor Detail

MessageSourceResourceBundleback to summary
public MessageSourceResourceBundle(MessageSource source, Locale locale)

Create a new MessageSourceResourceBundle for the given MessageSource and Locale.

Parameters
source:MessageSource

the MessageSource to retrieve messages from

locale:Locale

the Locale to retrieve messages for

MessageSourceResourceBundleback to summary
public MessageSourceResourceBundle(MessageSource source, Locale locale, ResourceBundle parent)

Create a new MessageSourceResourceBundle for the given MessageSource and Locale.

Parameters
source:MessageSource

the MessageSource to retrieve messages from

locale:Locale

the Locale to retrieve messages for

parent:ResourceBundle

the parent ResourceBundle to delegate to if no local message found

Method Detail

containsKeyback to summary
public boolean containsKey(String key)

Overrides java.util.ResourceBundle.containsKey.

This implementation checks whether the target MessageSource can resolve a message for the given key, translating NoSuchMessageException accordingly. In contrast to ResourceBundle's default implementation in JDK 1.6, this does not rely on the capability to enumerate message keys.

Parameters
key:String

Doc from java.util.ResourceBundle.containsKey.

the resource key

Returns:boolean

Doc from java.util.ResourceBundle.containsKey.

true if the given key is contained in this ResourceBundle or its parent bundles; false otherwise.

Annotations
@Override
getKeysback to summary
public Enumeration<String> getKeys()

Implements abstract java.util.ResourceBundle.getKeys.

This implementation throws UnsupportedOperationException, as a MessageSource does not allow for enumerating the defined message codes.

Returns:Enumeration<String>

Doc from java.util.ResourceBundle.getKeys.

an Enumeration of the keys contained in this ResourceBundle and its parent bundles.

Annotations
@Override
getLocaleback to summary
public Locale getLocale()

Overrides java.util.ResourceBundle.getLocale.

This implementation exposes the specified Locale for introspection through the standard ResourceBundle.getLocale() method.

Returns:Locale

Doc from java.util.ResourceBundle.getLocale.

the locale of this resource bundle

Annotations
@Override
handleGetObjectback to summary
protected Object handleGetObject(String key)

Implements abstract java.util.ResourceBundle.handleGetObject.

This implementation resolves the code in the MessageSource. Returns null if the message could not be resolved.

Parameters
key:String

Doc from java.util.ResourceBundle.handleGetObject.

the key for the desired object

Returns:Object

Doc from java.util.ResourceBundle.handleGetObject.

the object for the given key, or null

Annotations
@Override
@Nullable