Locale/ThemeChangeInterceptor alignment and javadoc polishing
Issue: SPR-11128
This commit is contained in:
parent
cc81aae8c1
commit
5e5add4862
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,14 +17,13 @@
|
||||||
package org.springframework.web.servlet.i18n;
|
package org.springframework.web.servlet.i18n;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.web.servlet.LocaleResolver;
|
import org.springframework.web.servlet.LocaleResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of LocaleResolver that simply uses the primary locale
|
* {@link LocaleResolver} implementation that simply uses the primary locale
|
||||||
* specified in the "accept-language" header of the HTTP request (that is,
|
* specified in the "accept-language" header of the HTTP request (that is,
|
||||||
* the locale sent by the client browser, normally that of the client's OS).
|
* the locale sent by the client browser, normally that of the client's OS).
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -27,7 +27,7 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interceptor that allows for changing the current locale on every request,
|
* Interceptor that allows for changing the current locale on every request,
|
||||||
* via a configurable request parameter.
|
* via a configurable request parameter (default parameter name: "locale").
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 20.06.2003
|
* @since 20.06.2003
|
||||||
|
|
|
@ -26,9 +26,10 @@ import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
|
||||||
import org.springframework.web.util.WebUtils;
|
import org.springframework.web.util.WebUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of LocaleResolver that uses a locale attribute in the user's
|
* {@link org.springframework.web.servlet.LocaleResolver} implementation that
|
||||||
* session in case of a custom setting, with a fallback to the specified default
|
* uses a locale attribute in the user's session in case of a custom setting,
|
||||||
* locale or the request's accept-header locale.
|
* with a fallback to the specified default locale or the request's
|
||||||
|
* accept-header locale.
|
||||||
*
|
*
|
||||||
* <p>This is most appropriate if the application needs user sessions anyway,
|
* <p>This is most appropriate if the application needs user sessions anyway,
|
||||||
* that is, when the HttpSession does not have to be created for the locale.
|
* that is, when the HttpSession does not have to be created for the locale.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,8 +20,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of ThemeResolver that simply uses a fixed theme.
|
* {@link org.springframework.web.servlet.ThemeResolver} implementation
|
||||||
* The fixed name can be defined via the "defaultThemeName" property.
|
* that simply uses a fixed theme. The fixed name can be defined via
|
||||||
|
* the "defaultThemeName" property; out of the box, it is "theme".
|
||||||
*
|
*
|
||||||
* <p>Note: Does not support {@code setThemeName}, as the fixed theme
|
* <p>Note: Does not support {@code setThemeName}, as the fixed theme
|
||||||
* cannot be changed.
|
* cannot be changed.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -26,7 +26,7 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interceptor that allows for changing the current theme on every request,
|
* Interceptor that allows for changing the current theme on every request,
|
||||||
* via a configurable request parameter.
|
* via a configurable request parameter (default parameter name: "theme").
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 20.06.2003
|
* @since 20.06.2003
|
||||||
|
@ -63,12 +63,12 @@ public class ThemeChangeInterceptor extends HandlerInterceptorAdapter {
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
throws ServletException {
|
throws ServletException {
|
||||||
|
|
||||||
|
String newTheme = request.getParameter(this.paramName);
|
||||||
|
if (newTheme != null) {
|
||||||
ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
|
ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);
|
||||||
if (themeResolver == null) {
|
if (themeResolver == null) {
|
||||||
throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
|
throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?");
|
||||||
}
|
}
|
||||||
String newTheme = request.getParameter(this.paramName);
|
|
||||||
if (newTheme != null) {
|
|
||||||
themeResolver.setThemeName(request, response, newTheme);
|
themeResolver.setThemeName(request, response, newTheme);
|
||||||
}
|
}
|
||||||
// Proceed in any case.
|
// Proceed in any case.
|
||||||
|
|
Loading…
Reference in New Issue