|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.AbstractMessageSource de.schwarzrot.app.service.XtensibleResourceBundleMessageSource
public class XtensibleResourceBundleMessageSource
MessageSource
implementation that
accesses resource bundles using specified basenames. This class relies on the
underlying JDK's ResourceBundle
implementation, in
combination with the JDK's standard message parsing provided by
MessageFormat
.
This MessageSource is copied from
org.springframework.context.support.ResourceBundleMessageSource
.
Unfortunatelly that class offers no oportunity to extend the resource-bundle
at runtime.
The main difference is the possibility to add basenames, so that the same MessageSource could be extended by plugins or other dynamic application parts.
Extending ResourceBundleMessageSource was not possible due to the lack of access to basenames from derived classes.
adapted by:, Reinhard Mantey
addBasename(java.lang.String)
,
ResourceBundleMessageSource
,
ResourceBundle
,
MessageFormat
Field Summary |
---|
Fields inherited from class org.springframework.context.support.AbstractMessageSource |
---|
logger |
Constructor Summary | |
---|---|
XtensibleResourceBundleMessageSource()
|
Method Summary | |
---|---|
void |
addBasename(String basename)
main reason for duplicating org.springframework.context.support.ResourceBundleMessageSource
This way plugins could add their resource-bundles without changing code
in base-classes. |
void |
addBasenames(String[] basenames)
add multiple basenames - useful to add the basenames from another XtensibleResourceBundleMessageSource |
protected ResourceBundle |
doGetBundle(String basename,
Locale locale)
Obtain the resource bundle for the given basename and Locale. |
String[] |
getBasenames()
to merge different MessageSources we need to get the basenames ... |
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: essentially, a fully-qualified classpath location. |
void |
setBasenames(String[] basenames)
Set an array of basenames, each following ResourceBundle conventions: essentially, a
fully-qualified classpath location. |
void |
setBeanClassLoader(ClassLoader classLoader)
|
void |
setBundleClassLoader(ClassLoader classLoader)
Set the ClassLoader to load resource bundles with. |
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 XtensibleResourceBundleMessageSource()
Method Detail |
---|
public void addBasename(String basename)
org.springframework.context.support.ResourceBundleMessageSource
This way plugins could add their resource-bundles without changing code
in base-classes.
Opposed to setBasenames()
any existing basenames are
preserved.
basename
- - the new base to addpublic void addBasenames(String[] basenames)
basenames
- - the bunch of new bases to addpublic String[] getBasenames()
public void setBasename(String basename)
ResourceBundle
conventions: essentially, a fully-qualified classpath location. If it
doesn't contain a package qualifier (such as org.mypackage
),
it will be resolved from the classpath root.
Messages will normally be held in the "/lib" or "/classes" directory of a web application's WAR structure. They can also be held in jar files on the class path.
Note that ResourceBundle names are effectively classpath locations: As a
consequence, the JDK's standard ResourceBundle treats dots as package
separators. This means that "test.theme" is effectively equivalent to
"test/theme", just like it is for programmatic
java.util.ResourceBundle
usage.
basename
- - the new basename to addsetBasenames(java.lang.String[])
,
ResourceBundle.getBundle(String)
public void setBasenames(String[] basenames)
ResourceBundle
conventions: essentially, a
fully-qualified classpath location. If it doesn't contain a package
qualifier (such as org.mypackage
), it will be resolved from
the classpath root.
The associated resource bundles will be checked sequentially when resolving a message code. Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.
Note that ResourceBundle names are effectively classpath locations: As a
consequence, the JDK's standard ResourceBundle treats dots as package
separators. This means that "test.theme" is effectively equivalent to
"test/theme", just like it is for programmatic
java.util.ResourceBundle
usage.
setBasename(java.lang.String)
,
ResourceBundle.getBundle(String)
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
public void setBundleClassLoader(ClassLoader classLoader)
Default is the containing BeanFactory's
bean
ClassLoader
, or the default ClassLoader determined by
ClassUtils.getDefaultClassLoader()
if
not running within a BeanFactory.
public String toString()
toString
in class Object
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 ClassLoader getBundleClassLoader()
Default is the containing BeanFactory's bean ClassLoader.
setBundleClassLoader(java.lang.ClassLoader)
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
MissingResourceException
- if thrown by the ResourceBundleprotected 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 Localeprotected MessageFormat resolveCode(String code, Locale locale)
resolveCode
in class AbstractMessageSource
protected String resolveCodeWithoutArguments(String code, Locale locale)
resolveCodeWithoutArguments
in class AbstractMessageSource
|
SRJRCFrames v0.1.296 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |