|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.context.support.AbstractMessageSource
org.springframework.context.support.ResourceBundleMessageSource
public class ResourceBundleMessageSource
MessageSource that accesses the resource bundles with the specified basenames.
This class relies on the underlying JDK's java.util.ResourceBundle
implementation, in combination with the standard message parsing provided by
java.text.MessageFormat.
This MessageSource caches both the accessed ResourceBundle instances and
the generated MessageFormats for each message. It also implements rendering of
no-arg messages without MessageFormat, as supported by the AbstractMessageSource
base class. The caching provided by this MessageSource is significantly faster
than the built-in caching of the java.util.ResourceBundle class.
Unfortunately, java.util.ResourceBundle caches loaded bundles
forever: Reloading a bundle during VM execution is not possible.
As this MessageSource relies on ResourceBundle, it faces the same limitation.
Consider ReloadableResourceBundleMessageSource for an alternative that is
capable of refreshing the underlying bundle files.
setBasenames(java.lang.String[]),
ReloadableResourceBundleMessageSource,
ResourceBundle,
MessageFormat| Field Summary |
|---|
| Fields inherited from class org.springframework.context.support.AbstractMessageSource |
|---|
logger |
| Constructor Summary | |
|---|---|
ResourceBundleMessageSource()
|
|
| Method Summary | |
|---|---|
protected ResourceBundle |
doGetBundle(String basename,
Locale locale)
Obtain the resource bundle for the given basename and Locale. |
protected ClassLoader |
getBundleClassLoader()
Return the ClassLoader to load resource bundles with. |
protected MessageFormat |
getMessageFormat(ResourceBundle bundle,
String code,
Locale locale)
Return a MessageFormat for the given bundle and code, fetching already generated MessageFormats from the cache. |
protected ResourceBundle |
getResourceBundle(String basename,
Locale locale)
Return a ResourceBundle for the given basename and code, fetching already generated MessageFormats from the cache. |
protected MessageFormat |
resolveCode(String code,
Locale locale)
Resolves the given message code as key in the registered resource bundles, using a cached MessageFormat instance per message code. |
protected String |
resolveCodeWithoutArguments(String code,
Locale locale)
Resolves the given message code as key in the registered resource bundles, returning the value found in the bundle as-is (without MessageFormat parsing). |
void |
setBasename(String basename)
Set a single basename, following ResourceBundle conventions: It is a fully-qualified classname. |
void |
setBasenames(String[] basenames)
Set an array of basenames, each following ResourceBundle conventions. |
void |
setBundleClassLoader(ClassLoader classLoader)
Set the ClassLoader to load resource bundles with. |
void |
setClassLoader(ClassLoader classLoader)
Deprecated. in favor of setBundleClassLoader |
String |
toString()
Show the configuration of this MessageSource. |
| Methods inherited from class org.springframework.context.support.AbstractMessageSource |
|---|
createMessageFormat, formatMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isAlwaysUseMessageFormat, isUseCodeAsDefaultMessage, renderDefaultMessage, resolveArguments, setAlwaysUseMessageFormat, setParentMessageSource, setUseCodeAsDefaultMessage |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ResourceBundleMessageSource()
| Method Detail |
|---|
public void setBasename(String basename)
Messages will normally be held in the /lib or /classes directory of a WAR. They can also be held in Jars on the class path. For example, a Jar in an application's manifest classpath could contain messages for the application.
basename - the single basenamesetBasenames(java.lang.String[]),
ResourceBundlepublic void setBasenames(String[] basenames)
Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.
basenames - an array of basenamessetBasename(java.lang.String),
ResourceBundlepublic void setClassLoader(ClassLoader classLoader)
setBundleClassLoader
setBundleClassLoader(java.lang.ClassLoader)public void setBundleClassLoader(ClassLoader classLoader)
protected ClassLoader getBundleClassLoader()
protected String resolveCodeWithoutArguments(String code,
Locale locale)
resolveCodeWithoutArguments in class AbstractMessageSourcecode - the code of the message to resolvelocale - the Locale to resolve the code for
(subclasses are encouraged to support internationalization)
null if not foundAbstractMessageSource.resolveCode(java.lang.String, java.util.Locale),
MessageFormat
protected MessageFormat resolveCode(String code,
Locale locale)
resolveCode in class AbstractMessageSourcecode - the code of the message to resolvelocale - the Locale to resolve the code for
(subclasses are encouraged to support internationalization)
null if not foundAbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)
protected ResourceBundle getResourceBundle(String basename,
Locale locale)
basename - the basename of the ResourceBundlelocale - the Locale to find the ResourceBundle for
null if none
found for the given basename and Locale
protected ResourceBundle doGetBundle(String basename,
Locale locale)
throws MissingResourceException
basename - the basename to look forlocale - the Locale to look for
MissingResourceException - if no matching bundle could be foundResourceBundle.getBundle(String, java.util.Locale, ClassLoader),
getBundleClassLoader()
protected MessageFormat getMessageFormat(ResourceBundle bundle,
String code,
Locale locale)
throws MissingResourceException
bundle - the ResourceBundle to work oncode - the message code to retrievelocale - the Locale to use to build the MessageFormat
null if no message
defined for the given code
MissingResourceExceptionpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||