Skip to content

Commit

Permalink
Additional theme removal updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jan 15, 2025
1 parent 9cfece0 commit b8c51a2
Show file tree
Hide file tree
Showing 21 changed files with 20 additions and 133 deletions.
7 changes: 3 additions & 4 deletions framework-docs/modules/ROOT/pages/core/beans/basics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,17 @@ another file or files. The following example shows how to do so:
<beans>
<import resource="services.xml"/>
<import resource="resources/messageSource.xml"/>
<import resource="/resources/themeSource.xml"/>
<bean id="bean1" class="..."/>
<bean id="bean2" class="..."/>
</beans>
----

In the preceding example, external bean definitions are loaded from three files:
`services.xml`, `messageSource.xml`, and `themeSource.xml`. All location paths are
In the preceding example, external bean definitions are loaded from the files
`services.xml` and `messageSource.xml`. All location paths are
relative to the definition file doing the importing, so `services.xml` must be in the
same directory or classpath location as the file doing the importing, while
`messageSource.xml` and `themeSource.xml` must be in a `resources` location below the
`messageSource.xml` must be in a `resources` location below the
location of the importing file. As you can see, a leading slash is ignored. However, given
that these paths are relative, it is better form not to use the slash at all. The
contents of the files being imported, including the top level `<beans/>` element, must
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ Kotlin::
The following code snippet is similar to the one we saw earlier for a request-scoped
bean. However, this time, the `userService` bean has a dependency on a session-scoped
`userPreferences` bean. Note that the `UserPreferences` bean is instantiated by using a
SpEL expression that retrieves the theme from the current HTTP session. In our test, we
need to configure a theme in the mock session managed by the TestContext framework. The
following example shows how to do so:
SpEL expression that retrieves an attribute from the current HTTP session.

.Session-scoped bean configuration
[source,xml,indent=0,subs="verbatim,quotes"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ The `DispatcherServlet` processes requests as follows:
* The locale resolver is bound to the request to let elements in the process
resolve the locale to use when processing the request (rendering the view, preparing
data, and so on). If you do not need locale resolving, you do not need the locale resolver.
* The theme resolver is bound to the request to let elements such as views determine
which theme to use. If you do not use themes, you can ignore it.
* If you specify a multipart file resolver, the request is inspected for multiparts. If
multiparts are found, the request is wrapped in a `MultipartHttpServletRequest` for
further processing by other elements in the process. See xref:web/webmvc/mvc-servlet/multipart.adoc[Multipart Resolver] for further
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")
package org.springframework.docs.web.webmvc.mvcconfig.mvcconfiginterceptors

import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor
import org.springframework.web.servlet.theme.ThemeChangeInterceptor

// tag::snippet[]
@Configuration
class WebConfiguration : WebMvcConfigurer {

override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(LocaleChangeInterceptor())
registry.addInterceptor(ThemeChangeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**")
registry.addInterceptor(UserRoleAuthorizationInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**")
}
}
// end::snippet[]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/admin/**"/>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
<bean class="org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor">
<property name="authorizedRoles" value="ROLE_USER"/>
</bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- end::snippet[] -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
* <p>A HandlerInterceptor gets called before the appropriate HandlerAdapter
* triggers the execution of the handler itself. This mechanism can be used
* for a large field of preprocessing aspects, or common handler behavior
* like locale or theme changes. Its main purpose is to allow for factoring
* like locale changes. Its main purpose is to allow for factoring
* out repetitive handler code.
*
* <p>In an asynchronous processing scenario, the handler may be executed in a
Expand Down Expand Up @@ -75,7 +75,6 @@
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#setInterceptors
* @see org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor
* @see org.springframework.web.servlet.i18n.LocaleChangeInterceptor
* @see org.springframework.web.servlet.theme.ThemeChangeInterceptor
* @see jakarta.servlet.Filter
*/
public interface HandlerInterceptor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@
* <h3><a name="workflow">Workflow</a></h3>
*
* <p>After a {@code DispatcherServlet} has received a request and has
* done its work to resolve locales, themes, and suchlike, it then tries
* done its work to resolve locales, and suchlike, it then tries
* to resolve a Controller, using a
* {@link org.springframework.web.servlet.HandlerMapping HandlerMapping}.
* When a Controller has been found to handle the request, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

/**
* Context holder for request-specific state, like current web application context, current locale,
* current theme, and potential binding errors. Provides easy access to localized messages and
* and potential binding errors. Provides easy access to localized messages and
* Errors instances.
*
* <p>Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* set by the {@link org.springframework.web.servlet.DispatcherServlet}.
*
* <p>Supports lookup of current WebApplicationContext, LocaleResolver,
* Locale, ThemeResolver, Theme, and MultipartResolver.
* Locale, and MultipartResolver.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* The {@code <argument>} tag is based on the JSTL {@code fmt:param} tag.
* The purpose is to support arguments inside the message and theme tags.
* The purpose is to support arguments inside the message tags.
*
* <p>This tag must be nested under an argument aware tag.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,8 +34,7 @@
* <p>The {@code RequestContext} instance provides easy access
* to current state like the
* {@link org.springframework.web.context.WebApplicationContext},
* the {@link java.util.Locale}, the
* {@link org.springframework.ui.context.Theme}, etc.
* the {@link java.util.Locale}, etc.
*
* <p>Mainly intended for
* {@link org.springframework.web.servlet.DispatcherServlet} requests;
Expand Down
2 changes: 1 addition & 1 deletion spring-webmvc/src/main/resources/META-INF/spring.tld
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

<tag>
<description>Argument tag based on the JSTL fmt:param tag. The purpose is to
support arguments inside the spring:message and spring:theme tags.</description>
support arguments inside the spring:message tags.</description>
<name>argument</name>
<tag-class>org.springframework.web.servlet.tags.ArgumentTag</tag-class>
<body-content>JSP</body-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,6 @@
-->
<#macro messageArgsText code, args, text>${springMacroRequestContext.getMessage(code, args, text)?no_esc}</#macro>

<#--
* theme
*
* Macro to translate a theme message code into a message.
-->
<#macro theme code>${springMacroRequestContext.getThemeMessage(code)?no_esc}</#macro>

<#--
* themeText
*
* Macro to translate a theme message code into a message,
* using the given default text if no message found.
-->
<#macro themeText code, text>${springMacroRequestContext.getThemeMessage(code, text)?no_esc}</#macro>

<#--
* themeArgs
*
* Macro to translate a theme message code with arguments into a message.
-->
<#macro themeArgs code, args>${springMacroRequestContext.getThemeMessage(code, args)?no_esc}</#macro>

<#--
* themeArgsText
*
* Macro to translate a theme message code with arguments into a message,
* using the given default text if no message found.
-->
<#macro themeArgsText code, args, text>${springMacroRequestContext.getThemeMessage(code, args, text)?no_esc}</#macro>

<#--
* url
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,8 +40,6 @@ public class DummyMacroRequestContext {

private Map<String, String> messageMap;

private Map<String, String> themeMessageMap;

private String contextPath;


Expand All @@ -54,10 +52,6 @@ public void setMessageMap(Map<String, String> messageMap) {
this.messageMap = messageMap;
}

public void setThemeMessageMap(Map<String, String> themeMessageMap) {
this.themeMessageMap = themeMessageMap;
}


/**
* @see org.springframework.web.servlet.support.RequestContext#getMessage(String)
Expand Down Expand Up @@ -89,36 +83,6 @@ public String getMessage(String code, List<?> args, String defaultMsg) {
return (msg != null ? msg + args : defaultMsg);
}

/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String)
*/
public String getThemeMessage(String code) {
return this.themeMessageMap.get(code);
}

/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, String)
*/
public String getThemeMessage(String code, String defaultMsg) {
String msg = this.themeMessageMap.get(code);
return (msg != null ? msg : defaultMsg);
}

/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, List)
*/
public String getThemeMessage(String code, List<?> args) {
return this.themeMessageMap.get(code) + args;
}

/**
* @see org.springframework.web.servlet.support.RequestContext#getThemeMessage(String, List, String)
*/
public String getThemeMessage(String code, List<?> args, String defaultMsg) {
String msg = this.themeMessageMap.get(code);
return (msg != null ? msg + args : defaultMsg);
}

public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,6 @@ void testMessageArgsWithDefaultMessage() throws Exception {
assertThat(getMacroOutput("MESSAGEARGSWITHDEFAULTMESSAGE")).isEqualTo("Hi");
}

@Test
void testTheme() throws Exception {
assertThat(getMacroOutput("THEME")).isEqualTo("Howdy! Mundo!");
}

@Test
void testDefaultTheme() throws Exception {
assertThat(getMacroOutput("DEFAULTTHEME")).isEqualTo("hi! planet!");
}

@Test
void testThemeArgs() throws Exception {
assertThat(getMacroOutput("THEMEARGS")).isEqualTo("Howdy![World]");
}

@Test
void testThemeArgsWithDefaultMessage() throws Exception {
assertThat(getMacroOutput("THEMEARGSWITHDEFAULTMESSAGE")).isEqualTo("Hi!");
}

@Test
void testUrl() throws Exception {
assertThat(getMacroOutput("URL")).isEqualTo("/springtest/aftercontext.html");
Expand Down Expand Up @@ -291,10 +271,6 @@ private String getMacroOutput(String name) throws Exception {
msgMap.put("hello", "Howdy");
msgMap.put("world", "Mundo");
rc.setMessageMap(msgMap);
Map<String, String> themeMsgMap = new HashMap<>();
themeMsgMap.put("hello", "Howdy!");
themeMsgMap.put("world", "Mundo!");
rc.setThemeMessageMap(themeMsgMap);
rc.setContextPath("/springtest");

TestBean darren = new TestBean("Darren", 99);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
useCodeAsDefaultMessage=false
message-file=context-messages
objectName=test:service=myservice
theme-base=org/springframework/web/context/WEB-INF/

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ MESSAGEARGS
MESSAGEARGSWITHDEFAULTMESSAGE
<@spring.messageArgsText "no.such.code", msgArgs, "Hi"/>

THEME
<@spring.theme "hello"/> <@spring.theme "world"/>

DEFAULTTHEME
<@spring.themeText "no.such.code", "hi!"/> <@spring.themeText "no.such.code", "planet!"/>

THEMEARGS
<@spring.themeArgs "hello", msgArgs/>

THEMEARGSWITHDEFAULTMESSAGE
<@spring.themeArgsText "no.such.code", msgArgs, "Hi!"/>

URL
<@spring.url "/aftercontext.html"/>

Expand Down

0 comments on commit b8c51a2

Please sign in to comment.