org.springframework.ui.context.Theme Java Examples

The following examples show how to use org.springframework.ui.context.Theme. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceBundleThemeSource.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: ResourceBundleThemeSource.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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
@Nullable
public Theme getTheme(String themeName) {
	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;
}
 
Example #3
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: ResourceBundleThemeSource.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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
@Nullable
public Theme getTheme(String themeName) {
	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;
}
 
Example #5
Source File: SimpleWebApplicationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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;
	}
}
 
Example #6
Source File: RequestContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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(@Nullable 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;
}
 
Example #7
Source File: SimpleWebApplicationContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
	}
}
 
Example #8
Source File: RequestContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: RequestContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: RequestContextUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #11
Source File: RequestContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: RequestContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: RequestContextUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #14
Source File: DelegatingThemeSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Theme getTheme(String themeName) {
	if (this.parentThemeSource != null) {
		return this.parentThemeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #15
Source File: ResourceBundleThemeSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
			}
		}
	}
}
 
Example #16
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
		}
	}
}
 
Example #17
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
			}
		}
	}
}
 
Example #18
Source File: DelegatingThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Theme getTheme(String themeName) {
	if (this.parentThemeSource != null) {
		return this.parentThemeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #19
Source File: ResourceBundleThemeSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
		}
	}
}
 
Example #20
Source File: ResourceBundleThemeSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setParentThemeSource(@Nullable 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);
		}
	}
}
 
Example #21
Source File: RequestContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: RequestContextUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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
 */
@Nullable
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;
	}
}
 
Example #23
Source File: DelegatingThemeSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public Theme getTheme(String themeName) {
	if (this.parentThemeSource != null) {
		return this.parentThemeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #24
Source File: ResourceBundleThemeSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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());
			}
		}
	}
}
 
Example #25
Source File: ResourceBundleThemeSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setParentThemeSource(@Nullable 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);
		}
	}
}
 
Example #26
Source File: ResourceBundleThemeSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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());
			}
		}
	}
}
 
Example #27
Source File: DelegatingThemeSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public Theme getTheme(String themeName) {
	if (this.parentThemeSource != null) {
		return this.parentThemeSource.getTheme(themeName);
	}
	else {
		return null;
	}
}
 
Example #28
Source File: RequestContextUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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
 */
@Nullable
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;
	}
}
 
Example #29
Source File: SimpleWebApplicationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
	}
}
 
Example #30
Source File: RequestContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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(@Nullable 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;
}