本文整理汇总了Java中org.springframework.ui.context.Theme类的典型用法代码示例。如果您正苦于以下问题:Java Theme类的具体用法?Java Theme怎么用?Java Theme使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Theme类属于org.springframework.ui.context包,在下文中一共展示了Theme类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
}
示例2: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
示例3: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
}
示例4: setParentThemeSource
import org.springframework.ui.context.Theme; //导入依赖的package包/类
@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);
}
}
}
示例5: initParent
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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());
}
}
}
}
示例6: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
@Override
public Theme getTheme(String themeName) {
if (this.parentThemeSource != null) {
return this.parentThemeSource.getTheme(themeName);
}
else {
return null;
}
}
示例7: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
}
示例8: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
示例9: changeTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
示例10: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
@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;
}
}
示例11: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* @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);
}
示例12: setParentThemeSource
import org.springframework.ui.context.Theme; //导入依赖的package包/类
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);
}
}
}
示例13: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
public Theme getTheme(String themeName) {
if (this.parentThemeSource != null) {
return this.parentThemeSource.getTheme(themeName);
}
else {
return null;
}
}
示例14: getTheme
import org.springframework.ui.context.Theme; //导入依赖的package包/类
/**
* 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;
}
示例15: getColor
import org.springframework.ui.context.Theme; //导入依赖的package包/类
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));
}