public class ResourceBundleThemeSource extends Object implements HierarchicalThemeSource, BeanClassLoaderAware
ThemeSource implementation that looks up an individual
ResourceBundle per theme. The theme name gets
interpreted as ResourceBundle basename, supporting a common
basename prefix for all themes.setBasenamePrefix(java.lang.String),
ResourceBundle,
ResourceBundleMessageSource| Constructor and Description |
|---|
ResourceBundleThemeSource() |
| Modifier and Type | Method and Description |
|---|---|
protected MessageSource |
createMessageSource(String basename)
Create a MessageSource for the given basename,
to be used as MessageSource for the corresponding theme.
|
ThemeSource |
getParentThemeSource()
Return the parent of this ThemeSource, or
null if none. |
Theme |
getTheme(String themeName)
This implementation returns a SimpleTheme instance, holding a
ResourceBundle-based MessageSource whose basename corresponds to
the given theme name (prefixed by the configured "basenamePrefix").
|
protected void |
initParent(Theme theme)
Initialize the MessageSource of the given theme with the
one from the corresponding parent of this ThemeSource.
|
void |
setBasenamePrefix(String basenamePrefix)
Set the prefix that gets applied to the ResourceBundle basenames,
i.e.
|
void |
setBeanClassLoader(ClassLoader beanClassLoader)
Callback that supplies the bean
class loader to
a bean instance. |
void |
setDefaultEncoding(String defaultEncoding)
Set the default charset to use for parsing resource bundle files.
|
void |
setFallbackToSystemLocale(boolean fallbackToSystemLocale)
Set whether to fall back to the system Locale if no files for a
specific Locale have been found.
|
void |
setParentThemeSource(ThemeSource parent)
Set the parent that will be used to try to resolve theme messages
that this object can't resolve.
|
protected final Log logger
public void setParentThemeSource(ThemeSource parent)
HierarchicalThemeSourcesetParentThemeSource in interface HierarchicalThemeSourceparent - the parent ThemeSource that will be used to
resolve messages that this object can't resolve.
May be null, in which case no further resolution is possible.public ThemeSource getParentThemeSource()
HierarchicalThemeSourcenull if none.getParentThemeSource in interface HierarchicalThemeSourcepublic void setBasenamePrefix(String basenamePrefix)
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.
ResourceBundle.getBundle(String)public void setDefaultEncoding(String defaultEncoding)
ResourceBundleMessageSource's default is the
java.util.ResourceBundle default encoding: ISO-8859-1.
AbstractResourceBasedMessageSource.setDefaultEncoding(java.lang.String)public void setFallbackToSystemLocale(boolean fallbackToSystemLocale)
ResourceBundleMessageSource's default is "true".
AbstractResourceBasedMessageSource.setFallbackToSystemLocale(boolean)public void setBeanClassLoader(ClassLoader beanClassLoader)
BeanClassLoaderAwareclass loader to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader in interface BeanClassLoaderAwarebeanClassLoader - the owning class loader; may be null in
which case a default ClassLoader must be used, for example
the ClassLoader obtained via
ClassUtils.getDefaultClassLoader()public Theme getTheme(String themeName)
SimpleTheme instances are cached per theme name. Use a reloadable MessageSource if themes should reflect changes to the underlying files.
getTheme in interface ThemeSourcethemeName - the name of the themenull if none defined.
Note that, by convention, a ThemeSource should at least be able to
return a default Theme for the default theme name "theme" but may also
return default Themes for other theme names.setBasenamePrefix(java.lang.String),
createMessageSource(java.lang.String)protected MessageSource createMessageSource(String basename)
Default implementation creates a ResourceBundleMessageSource. for the given basename. A subclass could create a specifically configured ReloadableResourceBundleMessageSource, for example.
basename - the basename to create a MessageSource forResourceBundleMessageSource,
ReloadableResourceBundleMessageSourceprotected void initParent(Theme theme)
theme - the Theme to (re-)initialize