/** * 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; } synchronized (this.themeCache) { Theme 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; } }
/** * 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; }
/** * 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 */ 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 + 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; } }
@Override public void setParentThemeSource(ThemeSource parent) { this.parentThemeSource = parent; // Update existing Theme objects. // Usually there shouldn't be any at the time of this call. synchronized (this.themeCache) { for (Theme theme : this.themeCache.values()) { initParent(theme); } } }
/** * 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 HierarchicalMessageSource) { HierarchicalMessageSource messageSource = (HierarchicalMessageSource) theme.getMessageSource(); if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) { Theme parentTheme = getParentThemeSource().getTheme(theme.getName()); if (parentTheme != null) { messageSource.setParentMessageSource(parentTheme.getMessageSource()); } } } }
@Override public Theme getTheme(String themeName) { if (this.parentThemeSource != null) { return this.parentThemeSource.getTheme(themeName); } else { return null; } }
/** * Retrieves the current theme from the given request, using the ThemeResolver * and ThemeSource bound to the request by the DispatcherServlet. * @param request current HTTP request * @return the current theme, or {@code null} if not found * @see #getThemeResolver */ public static Theme getTheme(HttpServletRequest request) { ThemeResolver themeResolver = getThemeResolver(request); ThemeSource themeSource = getThemeSource(request); if (themeResolver != null && themeSource != null) { String themeName = themeResolver.resolveThemeName(request); return themeSource.getTheme(themeName); } else { return null; } }
/** * Return the current theme (never {@code null}). * <p>Resolved lazily for more efficiency when theme support is not being used. */ public Theme getTheme() { if (this.theme == null) { // Lazily determine theme to use for this RequestContext. this.theme = RequestContextUtils.getTheme(this.request); if (this.theme == null) { // No ThemeResolver and ThemeSource available -> try fallback. this.theme = getFallbackTheme(); } } return this.theme; }
/** * Change the current theme to the specified one, * storing the new theme name through the configured {@link ThemeResolver}. * @param theme the new theme * @see ThemeResolver#setThemeName */ public void changeTheme(Theme theme) { ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request); if (themeResolver == null) { throw new IllegalStateException("Cannot change theme if no ThemeResolver configured"); } themeResolver.setThemeName(this.request, this.response, (theme != null ? theme.getName() : null)); this.theme = theme; }
@Override public Theme getTheme(String themeName) { if (AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME.equals(themeName)) { return new SimpleTheme(AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME, this.messageSource); } else { return null; } }
/** * @see org.springframework.ui.context.ThemeSource#getTheme(java.lang.String) */ @Override public Theme getTheme(String ignoredArgument) { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(this.themeName); return new SimpleTheme(themeName, messageSource); }
public void setParentThemeSource(ThemeSource parent) { this.parentThemeSource = parent; // Update existing Theme objects. // Usually there shouldn't be any at the time of this call. synchronized (this.themeCache) { for (Theme theme : this.themeCache.values()) { initParent(theme); } } }
public Theme getTheme(String themeName) { if (this.parentThemeSource != null) { return this.parentThemeSource.getTheme(themeName); } else { return null; } }
/** * Return the current theme (never {@code null}). * <p>Resolved lazily for more efficiency when theme support is not being used. */ public final Theme getTheme() { if (this.theme == null) { // Lazily determine theme to use for this RequestContext. this.theme = RequestContextUtils.getTheme(this.request); if (this.theme == null) { // No ThemeResolver and ThemeSource available -> try fallback. this.theme = getFallbackTheme(); } } return this.theme; }
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)); }
@Override public Theme getTheme(String themeName) { return this.themeSource.getTheme(themeName); }
public Theme getTheme(String themeName) { return this.themeSource.getTheme(themeName); }
public Theme getTheme(String arg0) { logger.debug("Theme name : " + arg0); return super.getTheme(arg0); }