/*
 * Copyright 2002-2013 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.servlet.i18n;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.support.RequestContextUtils;

/**
 * Interceptor that allows for changing the current locale on every request,
 * via a configurable request parameter (default parameter name: "locale").
 *
 * @author Juergen Hoeller
 * @since 20.06.2003
 * @see org.springframework.web.servlet.LocaleResolver
 */
public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {

	/**
	 * Default name of the locale specification parameter: "locale".
	 */
	public static final String DEFAULT_PARAM_NAME = "locale";

	private String paramName = DEFAULT_PARAM_NAME;


	/**
	 * Set the name of the parameter that contains a locale specification
	 * in a locale change request. Default is "locale".
	 */
	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	/**
	 * Return the name of the parameter that contains a locale specification
	 * in a locale change request.
	 */
	public String getParamName() {
		return this.paramName;
	}


	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws ServletException {

		String newLocale = request.getParameter(this.paramName);
		if (newLocale != null) {
			LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
			if (localeResolver == null) {
				throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
			}
			localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale));
		}
		// Proceed in any case.
		return true;
	}

}

@@ -17,17 +17,17 @@
 2002-201
-3
+5
  the ori
@@ -795,16 +795,61 @@
 ponse;%0A%0A
+import org.springframework.util.ObjectUtils;%0A
 import o
@@ -1609,16 +1609,48 @@
 _NAME;%0A%0A
+%09private String%5B%5D httpMethods;%0A%0A
 %0A%09/**%0A%09 
@@ -2033,16 +2033,370 @@
 me;%0A%09%7D%0A%0A
+%09/**%0A%09 * Configure the HTTP method(s) over which the locale can be changed.%0A%09 * @param httpMethods the methods%0A%09 * @since 4.2%0A%09 */%0A%09public void setHttpMethods(String... httpMethods) %7B%0A%09%09this.httpMethods = httpMethods;%0A%09%7D%0A%0A%09/**%0A%09 * Return the configured HTTP methods.%0A%09 * @since 4.2%0A%09 */%0A%09public String%5B%5D getHttpMethods() %7B%0A%09%09return this.httpMethods;%0A%09%7D%0A%0A
 %0A%09@Overr
@@ -2615,16 +2615,64 @@
 null) %7B%0A
+%09%09%09if (checkHttpMethod(request.getMethod())) %7B%0A%09
 %09%09%09Local
@@ -2745,24 +2745,25 @@
 equest);%0A%09%09%09
+%09
 if (localeRe
@@ -2776,24 +2776,25 @@
  == null) %7B%0A
+%09
 %09%09%09%09throw ne
@@ -2817,16 +2817,24 @@
 ception(
+%0A%09%09%09%09%09%09%09
 %22No Loca
@@ -2893,18 +2893,20 @@
 ?%22);%0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%09local
@@ -2987,16 +2987,21 @@
 cale));%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09//
@@ -3041,10 +3041,280 @@
 ue;%0A%09%7D%0A%0A
+%09private boolean checkHttpMethod(String currentMethod) %7B%0A%09%09if (ObjectUtils.isEmpty(getHttpMethods())) %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09for (String httpMethod : getHttpMethods()) %7B%0A%09%09%09if (httpMethod.equalsIgnoreCase(currentMethod)) %7B%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%0A
 %7D%0A

Add httpMethods property to LocalChangeInterceptor