Professional Documents
Culture Documents
/**
* This implementation returns a SimpleTheme instance, holding a
* ResourceBundle-based MessageSource whose basename corresponds to
* the given theme name (prefixed by the configured "basenamePrefix").
* <p>SimpleTheme instances are cached per theme name. Use a reloadable
* MessageSource if themes should reflect changes to the underlying file
s.
* @see #setBasenamePrefix
* @see #createMessageSource
*/
public Theme getTheme(String themeName) {
if (themeName == null) {
return null;
}
synchronized (this.themeCache) {
Theme theme = this.themeCache.get(themeName);
if (theme == null) {
String basename = this.basenamePrefix + themeNam
e;
MessageSource messageSource = createMessageSourc
e(basename);
theme = new SimpleTheme(themeName, messageSource
);
initParent(theme);
this.themeCache.put(themeName, theme);
if (logger.isDebugEnabled()) {
logger.debug("Theme created: name '" + t
hemeName + "', basename [" + basename + "]");
}
}
return theme;
}
}
/**
* Create a MessageSource for the given basename,
* to be used as MessageSource for the corresponding theme.
* <p>Default implementation creates a ResourceBundleMessageSource.
* for the given basename. A subclass could create a specifically
* configured ReloadableResourceBundleMessageSource, for example.
* @param basename the basename to create a MessageSource for
* @return the MessageSource
* @see org.springframework.context.support.ResourceBundleMessageSource
* @see org.springframework.context.support.ReloadableResourceBundleMess
ageSource
*/
protected MessageSource createMessageSource(String basename) {
ResourceBundleMessageSource messageSource = new ResourceBundleMe
ssageSource();
messageSource.setBasename(basename);
return messageSource;
}
/**
* Initialize the MessageSource of the given theme with the
* one from the corresponding parent of this ThemeSource.
* @param theme the Theme to (re-)initialize
*/
protected void initParent(Theme theme) {
if (theme.getMessageSource() instanceof HierarchicalMessageSourc
e) {
HierarchicalMessageSource messageSource = (HierarchicalM
essageSource) theme.getMessageSource();
if (getParentThemeSource() != null && messageSource.getP
arentMessageSource() == null) {
Theme parentTheme = getParentThemeSource().getTh
eme(theme.getName());
if (parentTheme != null) {
messageSource.setParentMessageSource(par
entTheme.getMessageSource());
}
}
}
}
}