use of org.springframework.ui.context.Theme in project spring-framework by spring-projects.
the class ResourceBundleThemeSource method getTheme.
/**
* 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 files.
* @see #setBasenamePrefix
* @see #createMessageSource
*/
@Override
public Theme getTheme(String themeName) {
if (themeName == null) {
return null;
}
Theme theme = this.themeCache.get(themeName);
if (theme == null) {
synchronized (this.themeCache) {
theme = this.themeCache.get(themeName);
if (theme == null) {
String basename = this.basenamePrefix + themeName;
MessageSource messageSource = createMessageSource(basename);
theme = new SimpleTheme(themeName, messageSource);
initParent(theme);
this.themeCache.put(themeName, theme);
if (logger.isDebugEnabled()) {
logger.debug("Theme created: name '" + themeName + "', basename [" + basename + "]");
}
}
}
}
return theme;
}
use of org.springframework.ui.context.Theme in project spring-framework by spring-projects.
the class RequestContext method getFallbackTheme.
/**
* Determine the fallback theme for this context.
* <p>The default implementation returns the default theme (with name "theme").
* @return the fallback theme (never {@code null})
*/
protected Theme getFallbackTheme() {
ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest());
if (themeSource == null) {
themeSource = new ResourceBundleThemeSource();
}
Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME);
if (theme == null) {
throw new IllegalStateException("No theme defined and no fallback theme found");
}
return theme;
}
use of org.springframework.ui.context.Theme in project libresonic by Libresonic.
the class AbstractChartController method getColor.
private Color getColor(String code, HttpServletRequest request) {
Theme theme = RequestContextUtils.getTheme(request);
Locale locale = RequestContextUtils.getLocale(request);
String colorHex = theme.getMessageSource().getMessage(code, new Object[0], locale);
return new Color(Integer.parseInt(colorHex, 16));
}
Aggregations