Deprecate support for theme
As seen in gh-28868, the support for Themes is now deprecated as of Spring Framework 6.0 and will be removed in a future release. Closes gh-29114
This commit is contained in:
@@ -53,7 +53,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.RequestPath;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.ui.context.ThemeSource;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
@@ -130,6 +129,7 @@ import org.springframework.web.util.WebUtils;
|
||||
* Implementations for a fixed theme and for cookie and session storage are included.
|
||||
* The ThemeResolver bean name is "themeResolver"; default is
|
||||
* {@link org.springframework.web.servlet.theme.FixedThemeResolver}.
|
||||
* Theme support is deprecated as of 6.0
|
||||
* </ul>
|
||||
*
|
||||
* <p><b>NOTE: The {@code @RequestMapping} annotation will only be processed if a
|
||||
@@ -170,6 +170,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
public static final String LOCALE_RESOLVER_BEAN_NAME = "localeResolver";
|
||||
|
||||
/** Well-known name for the ThemeResolver object in the bean factory for this namespace. */
|
||||
@Deprecated
|
||||
public static final String THEME_RESOLVER_BEAN_NAME = "themeResolver";
|
||||
|
||||
/**
|
||||
@@ -227,12 +228,14 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
* Request attribute to hold the current ThemeResolver, retrievable by views.
|
||||
* @see org.springframework.web.servlet.support.RequestContextUtils#getThemeResolver
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String THEME_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_RESOLVER";
|
||||
|
||||
/**
|
||||
* Request attribute to hold the current ThemeSource, retrievable by views.
|
||||
* @see org.springframework.web.servlet.support.RequestContextUtils#getThemeSource
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String THEME_SOURCE_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_SOURCE";
|
||||
|
||||
/**
|
||||
@@ -311,6 +314,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
|
||||
/** ThemeResolver used by this servlet. */
|
||||
@Nullable
|
||||
@Deprecated
|
||||
private ThemeResolver themeResolver;
|
||||
|
||||
/** List of HandlerMappings used by this servlet. */
|
||||
@@ -557,6 +561,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
* <p>If no bean is defined with the given name in the BeanFactory for this namespace,
|
||||
* we default to a FixedThemeResolver.
|
||||
*/
|
||||
@Deprecated
|
||||
private void initThemeResolver(ApplicationContext context) {
|
||||
try {
|
||||
this.themeResolver = context.getBean(THEME_RESOLVER_BEAN_NAME, ThemeResolver.class);
|
||||
@@ -799,8 +804,10 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
* @see #getWebApplicationContext()
|
||||
*/
|
||||
@Nullable
|
||||
public final ThemeSource getThemeSource() {
|
||||
return (getWebApplicationContext() instanceof ThemeSource ? (ThemeSource) getWebApplicationContext() : null);
|
||||
@Deprecated
|
||||
public final org.springframework.ui.context.ThemeSource getThemeSource() {
|
||||
return (getWebApplicationContext() instanceof org.springframework.ui.context.ThemeSource ?
|
||||
(org.springframework.ui.context.ThemeSource) getWebApplicationContext() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,9 @@ import org.springframework.lang.Nullable;
|
||||
* @since 17.06.2003
|
||||
* @see org.springframework.ui.context.Theme
|
||||
* @see org.springframework.ui.context.ThemeSource
|
||||
* @deprecated as of 6.0, with no direct replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ThemeResolver {
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
|
||||
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;
|
||||
import org.springframework.web.servlet.support.SessionFlashMapManager;
|
||||
import org.springframework.web.servlet.theme.FixedThemeResolver;
|
||||
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
@@ -236,9 +235,10 @@ public abstract class MvcNamespaceUtils {
|
||||
* Registers an {@link FixedThemeResolver} under a well-known name
|
||||
* unless already registered.
|
||||
*/
|
||||
@Deprecated
|
||||
private static void registerThemeResolver(ParserContext context, @Nullable Object source) {
|
||||
if (!containsBeanInHierarchy(context, DispatcherServlet.THEME_RESOLVER_BEAN_NAME)) {
|
||||
RootBeanDefinition beanDef = new RootBeanDefinition(FixedThemeResolver.class);
|
||||
RootBeanDefinition beanDef = new RootBeanDefinition(org.springframework.web.servlet.theme.FixedThemeResolver.class);
|
||||
beanDef.setSource(source);
|
||||
beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
context.getRegistry().registerBeanDefinition(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, beanDef);
|
||||
|
||||
@@ -82,7 +82,6 @@ import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.RequestToViewNameTranslator;
|
||||
import org.springframework.web.servlet.ThemeResolver;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.function.support.HandlerFunctionAdapter;
|
||||
import org.springframework.web.servlet.function.support.RouterFunctionMapping;
|
||||
@@ -105,7 +104,6 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor;
|
||||
import org.springframework.web.servlet.support.SessionFlashMapManager;
|
||||
import org.springframework.web.servlet.theme.FixedThemeResolver;
|
||||
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.ViewResolverComposite;
|
||||
@@ -1165,8 +1163,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ThemeResolver themeResolver() {
|
||||
return new FixedThemeResolver();
|
||||
@Deprecated
|
||||
public org.springframework.web.servlet.ThemeResolver themeResolver() {
|
||||
return new org.springframework.web.servlet.theme.FixedThemeResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -35,9 +35,6 @@ import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext;
|
||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.ui.context.Theme;
|
||||
import org.springframework.ui.context.ThemeSource;
|
||||
import org.springframework.ui.context.support.ResourceBundleThemeSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -48,7 +45,6 @@ import org.springframework.web.bind.EscapedErrors;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.LocaleContextResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.ThemeResolver;
|
||||
import org.springframework.web.util.HtmlUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
@@ -83,6 +79,7 @@ public class RequestContext {
|
||||
* <p>Same as AbstractThemeResolver's default, but not linked in here to avoid package interdependencies.
|
||||
* @see org.springframework.web.servlet.theme.AbstractThemeResolver#ORIGINAL_DEFAULT_THEME_NAME
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String DEFAULT_THEME_NAME = "theme";
|
||||
|
||||
/**
|
||||
@@ -111,8 +108,9 @@ public class RequestContext {
|
||||
@Nullable
|
||||
private TimeZone timeZone;
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
private Theme theme;
|
||||
private org.springframework.ui.context.Theme theme;
|
||||
|
||||
@Nullable
|
||||
private Boolean defaultHtmlEscape;
|
||||
@@ -392,7 +390,8 @@ public class RequestContext {
|
||||
* Return the current theme (never {@code null}).
|
||||
* <p>Resolved lazily for more efficiency when theme support is not being used.
|
||||
*/
|
||||
public Theme getTheme() {
|
||||
@Deprecated
|
||||
public org.springframework.ui.context.Theme getTheme() {
|
||||
if (this.theme == null) {
|
||||
// Lazily determine theme to use for this RequestContext.
|
||||
this.theme = RequestContextUtils.getTheme(this.request);
|
||||
@@ -409,12 +408,13 @@ public class RequestContext {
|
||||
* <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());
|
||||
@Deprecated
|
||||
protected org.springframework.ui.context.Theme getFallbackTheme() {
|
||||
org.springframework.ui.context.ThemeSource themeSource = RequestContextUtils.getThemeSource(getRequest());
|
||||
if (themeSource == null) {
|
||||
themeSource = new ResourceBundleThemeSource();
|
||||
themeSource = new org.springframework.ui.context.support.ResourceBundleThemeSource();
|
||||
}
|
||||
Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME);
|
||||
org.springframework.ui.context.Theme theme = themeSource.getTheme(DEFAULT_THEME_NAME);
|
||||
if (theme == null) {
|
||||
throw new IllegalStateException("No theme defined and no fallback theme found");
|
||||
}
|
||||
@@ -427,8 +427,9 @@ public class RequestContext {
|
||||
* @param theme the new theme
|
||||
* @see ThemeResolver#setThemeName
|
||||
*/
|
||||
public void changeTheme(@Nullable Theme theme) {
|
||||
ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
|
||||
@Deprecated
|
||||
public void changeTheme(@Nullable org.springframework.ui.context.Theme theme) {
|
||||
org.springframework.web.servlet.ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
|
||||
if (themeResolver == null) {
|
||||
throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
|
||||
}
|
||||
@@ -442,8 +443,9 @@ public class RequestContext {
|
||||
* @param themeName the name of the new theme
|
||||
* @see ThemeResolver#setThemeName
|
||||
*/
|
||||
@Deprecated
|
||||
public void changeTheme(String themeName) {
|
||||
ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
|
||||
org.springframework.web.servlet.ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
|
||||
if (themeResolver == null) {
|
||||
throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
|
||||
}
|
||||
@@ -734,6 +736,7 @@ public class RequestContext {
|
||||
* @param defaultMessage the String to return if the lookup fails
|
||||
* @return the message
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code, String defaultMessage) {
|
||||
String msg = getTheme().getMessageSource().getMessage(code, null, defaultMessage, getLocale());
|
||||
return (msg != null ? msg : "");
|
||||
@@ -748,6 +751,7 @@ public class RequestContext {
|
||||
* @param defaultMessage the String to return if the lookup fails
|
||||
* @return the message
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code, @Nullable Object[] args, String defaultMessage) {
|
||||
String msg = getTheme().getMessageSource().getMessage(code, args, defaultMessage, getLocale());
|
||||
return (msg != null ? msg : "");
|
||||
@@ -762,6 +766,7 @@ public class RequestContext {
|
||||
* @param defaultMessage the String to return if the lookup fails
|
||||
* @return the message
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code, @Nullable List<?> args, String defaultMessage) {
|
||||
String msg = getTheme().getMessageSource().getMessage(code, (args != null ? args.toArray() : null),
|
||||
defaultMessage, getLocale());
|
||||
@@ -776,6 +781,7 @@ public class RequestContext {
|
||||
* @return the message
|
||||
* @throws org.springframework.context.NoSuchMessageException if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code) throws NoSuchMessageException {
|
||||
return getTheme().getMessageSource().getMessage(code, null, getLocale());
|
||||
}
|
||||
@@ -789,6 +795,7 @@ public class RequestContext {
|
||||
* @return the message
|
||||
* @throws org.springframework.context.NoSuchMessageException if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code, @Nullable Object[] args) throws NoSuchMessageException {
|
||||
return getTheme().getMessageSource().getMessage(code, args, getLocale());
|
||||
}
|
||||
@@ -802,6 +809,7 @@ public class RequestContext {
|
||||
* @return the message
|
||||
* @throws org.springframework.context.NoSuchMessageException if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(String code, @Nullable List<?> args) throws NoSuchMessageException {
|
||||
return getTheme().getMessageSource().getMessage(code, (args != null ? args.toArray() : null), getLocale());
|
||||
}
|
||||
@@ -814,6 +822,7 @@ public class RequestContext {
|
||||
* @return the message
|
||||
* @throws org.springframework.context.NoSuchMessageException if not found
|
||||
*/
|
||||
@Deprecated
|
||||
public String getThemeMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException {
|
||||
return getTheme().getMessageSource().getMessage(resolvable, getLocale());
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.ui.context.Theme;
|
||||
import org.springframework.ui.context.ThemeSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
@@ -40,7 +38,6 @@ import org.springframework.web.servlet.FlashMap;
|
||||
import org.springframework.web.servlet.FlashMapManager;
|
||||
import org.springframework.web.servlet.LocaleContextResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.ThemeResolver;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@@ -187,8 +184,9 @@ public abstract class RequestContextUtils {
|
||||
* @return the current ThemeResolver, or {@code null} if not found
|
||||
*/
|
||||
@Nullable
|
||||
public static ThemeResolver getThemeResolver(HttpServletRequest request) {
|
||||
return (ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
|
||||
@Deprecated
|
||||
public static org.springframework.web.servlet.ThemeResolver getThemeResolver(HttpServletRequest request) {
|
||||
return (org.springframework.web.servlet.ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +196,9 @@ public abstract class RequestContextUtils {
|
||||
* @return the current ThemeSource
|
||||
*/
|
||||
@Nullable
|
||||
public static ThemeSource getThemeSource(HttpServletRequest request) {
|
||||
return (ThemeSource) request.getAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE);
|
||||
@Deprecated
|
||||
public static org.springframework.ui.context.ThemeSource getThemeSource(HttpServletRequest request) {
|
||||
return (org.springframework.ui.context.ThemeSource) request.getAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,9 +209,10 @@ public abstract class RequestContextUtils {
|
||||
* @see #getThemeResolver
|
||||
*/
|
||||
@Nullable
|
||||
public static Theme getTheme(HttpServletRequest request) {
|
||||
ThemeResolver themeResolver = getThemeResolver(request);
|
||||
ThemeSource themeSource = getThemeSource(request);
|
||||
@Deprecated
|
||||
public static org.springframework.ui.context.Theme getTheme(HttpServletRequest request) {
|
||||
org.springframework.web.servlet.ThemeResolver themeResolver = getThemeResolver(request);
|
||||
org.springframework.ui.context.ThemeSource themeSource = getThemeSource(request);
|
||||
if (themeResolver != null && themeSource != null) {
|
||||
String themeName = themeResolver.resolveThemeName(request);
|
||||
return themeSource.getTheme(themeName);
|
||||
|
||||
@@ -122,8 +122,10 @@ import org.springframework.context.NoSuchMessageException;
|
||||
* @see HtmlEscapeTag#setDefaultHtmlEscape
|
||||
* @see org.springframework.web.util.WebUtils#HTML_ESCAPE_CONTEXT_PARAM
|
||||
* @see ArgumentTag
|
||||
* @deprecated as of 6.0, with no direct replacement
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Deprecated
|
||||
public class ThemeTag extends MessageTag {
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,9 @@ import org.springframework.web.servlet.ThemeResolver;
|
||||
* @author Juergen Hoeller
|
||||
* @author Jean-Pierre Pawlak
|
||||
* @since 17.06.2003
|
||||
* @deprecated as of 6.0, with no concrete replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractThemeResolver implements ThemeResolver {
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,9 @@ import org.springframework.web.util.WebUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 17.06.2003
|
||||
* @see #setThemeName
|
||||
* @deprecated as of 6.0, with no direct replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class CookieThemeResolver extends CookieGenerator implements ThemeResolver {
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.springframework.lang.Nullable;
|
||||
* @author Juergen Hoeller
|
||||
* @since 17.06.2003
|
||||
* @see #setDefaultThemeName
|
||||
* @deprecated as of 6.0, with no direct replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class FixedThemeResolver extends AbstractThemeResolver {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,9 @@ import org.springframework.web.util.WebUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 17.06.2003
|
||||
* @see #setThemeName
|
||||
* @deprecated as of 6.0, with no concrete replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class SessionThemeResolver extends AbstractThemeResolver {
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,9 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 20.06.2003
|
||||
* @see org.springframework.web.servlet.ThemeResolver
|
||||
* @deprecated as of 6.0, with no concrete replacement
|
||||
*/
|
||||
@Deprecated
|
||||
public class ThemeChangeInterceptor implements HandlerInterceptor {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user