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