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.server.i18n; 018 019import org.springframework.context.i18n.LocaleContext; 020import org.springframework.lang.Nullable; 021import org.springframework.web.server.ServerWebExchange; 022 023/** 024 * Interface for web-based locale context resolution strategies that allows 025 * for both locale context resolution via the request and locale context modification 026 * via the HTTP exchange. 027 * 028 * <p>The {@link org.springframework.context.i18n.LocaleContext} object can potentially 029 * includes associated time zone and other locale related information. 030 * 031 * @author Sebastien Deleuze 032 * @since 5.0 033 * @see LocaleContext 034 */ 035public interface LocaleContextResolver { 036 037 /** 038 * Resolve the current locale context via the given exchange. 039 * <p>The returned context may be a 040 * {@link org.springframework.context.i18n.TimeZoneAwareLocaleContext}, 041 * containing a locale with associated time zone information. 042 * Simply apply an {@code instanceof} check and downcast accordingly. 043 * <p>Custom resolver implementations may also return extra settings in 044 * the returned context, which again can be accessed through downcasting. 045 * @param exchange current server exchange 046 * @return the current locale context (never {@code null}) 047 */ 048 LocaleContext resolveLocaleContext(ServerWebExchange exchange); 049 050 /** 051 * Set the current locale context to the given one, 052 * potentially including a locale with associated time zone information. 053 * @param exchange current server exchange 054 * @param localeContext the new locale context, or {@code null} to clear the locale 055 * @throws UnsupportedOperationException if the LocaleResolver implementation 056 * does not support dynamic changing of the locale or time zone 057 * @see org.springframework.context.i18n.SimpleLocaleContext 058 * @see org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext 059 */ 060 void setLocaleContext(ServerWebExchange exchange, @Nullable LocaleContext localeContext); 061 062}