001/* 002 * Copyright 2002-2013 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 023import org.springframework.context.i18n.LocaleContext; 024 025/** 026 * Extension of {@link LocaleResolver}, adding support for a rich locale context 027 * (potentially including locale and time zone information). 028 * 029 * @author Juergen Hoeller 030 * @since 4.0 031 * @see org.springframework.context.i18n.LocaleContext 032 * @see org.springframework.context.i18n.TimeZoneAwareLocaleContext 033 * @see org.springframework.context.i18n.LocaleContextHolder 034 * @see org.springframework.web.servlet.support.RequestContext#getTimeZone 035 * @see org.springframework.web.servlet.support.RequestContextUtils#getTimeZone 036 */ 037public interface LocaleContextResolver extends LocaleResolver { 038 039 /** 040 * Resolve the current locale context via the given request. 041 * <p>This is primarily intended for framework-level processing; consider using 042 * {@link org.springframework.web.servlet.support.RequestContextUtils} or 043 * {@link org.springframework.web.servlet.support.RequestContext} for 044 * application-level access to the current locale and/or time zone. 045 * <p>The returned context may be a 046 * {@link org.springframework.context.i18n.TimeZoneAwareLocaleContext}, 047 * containing a locale with associated time zone information. 048 * Simply apply an {@code instanceof} check and downcast accordingly. 049 * <p>Custom resolver implementations may also return extra settings in 050 * the returned context, which again can be accessed through downcasting. 051 * @param request the request to resolve the locale context for 052 * @return the current locale context (never {@code null} 053 * @see #resolveLocale(HttpServletRequest) 054 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale 055 * @see org.springframework.web.servlet.support.RequestContextUtils#getTimeZone 056 */ 057 LocaleContext resolveLocaleContext(HttpServletRequest request); 058 059 /** 060 * Set the current locale context to the given one, 061 * potentially including a locale with associated time zone information. 062 * @param request the request to be used for locale modification 063 * @param response the response to be used for locale modification 064 * @param localeContext the new locale context, or {@code null} to clear the locale 065 * @throws UnsupportedOperationException if the LocaleResolver implementation 066 * does not support dynamic changing of the locale or time zone 067 * @see #setLocale(HttpServletRequest, HttpServletResponse, Locale) 068 * @see org.springframework.context.i18n.SimpleLocaleContext 069 * @see org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext 070 */ 071 void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext); 072 073}