001/* 002 * Copyright 2002-2016 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet; 018 019import java.util.Locale; 020import javax.servlet.http.HttpServletRequest; 021import javax.servlet.http.HttpServletResponse; 022 023/** 024 * Interface for web-based locale resolution strategies that allows for 025 * both locale resolution via the request and locale modification via 026 * request and response. 027 * 028 * <p>This interface allows for implementations based on request, session, 029 * cookies, etc. The default implementation is 030 * {@link org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver}, 031 * simply using the request's locale provided by the respective HTTP header. 032 * 033 * <p>Use {@link org.springframework.web.servlet.support.RequestContext#getLocale()} 034 * to retrieve the current locale in controllers or views, independent 035 * of the actual resolution strategy. 036 * 037 * <p>Note: As of Spring 4.0, there is an extended strategy interface 038 * called {@link LocaleContextResolver}, allowing for resolution of 039 * a {@link org.springframework.context.i18n.LocaleContext} object, 040 * potentially including associated time zone information. Spring's 041 * provided resolver implementations implement the extended 042 * {@link LocaleContextResolver} interface wherever appropriate. 043 * 044 * @author Juergen Hoeller 045 * @since 27.02.2003 046 * @see LocaleContextResolver 047 * @see org.springframework.context.i18n.LocaleContextHolder 048 * @see org.springframework.web.servlet.support.RequestContext#getLocale 049 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale 050 */ 051public interface LocaleResolver { 052 053 /** 054 * Resolve the current locale via the given request. 055 * Can return a default locale as fallback in any case. 056 * @param request the request to resolve the locale for 057 * @return the current locale (never {@code null}) 058 */ 059 Locale resolveLocale(HttpServletRequest request); 060 061 /** 062 * Set the current locale to the given one. 063 * @param request the request to be used for locale modification 064 * @param response the response to be used for locale modification 065 * @param locale the new locale, or {@code null} to clear the locale 066 * @throws UnsupportedOperationException if the LocaleResolver 067 * implementation does not support dynamic changing of the locale 068 */ 069 void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale); 070 071}