Interface LocaleContextResolver
- All Superinterfaces:
- LocaleResolver
- All Known Implementing Classes:
- AbstractLocaleContextResolver,- CookieLocaleResolver,- FixedLocaleResolver,- SessionLocaleResolver
LocaleResolver that adds support for a rich locale context
 (potentially including locale and time zone information).
 Also provides default implementations of resolveLocale(jakarta.servlet.http.HttpServletRequest) and
 setLocale(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, java.util.Locale) which delegate to resolveLocaleContext(jakarta.servlet.http.HttpServletRequest) and
 setLocaleContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, org.springframework.context.i18n.LocaleContext), respectively.
- Since:
- 4.0
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptiondefault LocaleresolveLocale(HttpServletRequest request) Default implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.resolveLocaleContext(HttpServletRequest request) Resolve the current locale context via the given request.default voidsetLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.voidsetLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.
- 
Method Details- 
resolveLocaleContextResolve the current locale context via the given request.This is primarily intended for framework-level processing; consider using RequestContextUtilsorRequestContextfor application-level access to the current locale and/or time zone.The returned context may be a TimeZoneAwareLocaleContext, containing a locale with associated time zone information. Simply apply aninstanceofcheck and downcast accordingly.Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting. - Parameters:
- request- the request to resolve the locale context for
- Returns:
- the current locale context (never null
- See Also:
 
- 
setLocaleContextvoid setLocaleContext(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- localeContext- the new locale context, or- nullto clear the locale
- Throws:
- UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale or time zone
- See Also:
 
- 
resolveLocaleDefault implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.- Specified by:
- resolveLocalein interface- LocaleResolver
- Parameters:
- request- the request to resolve the locale for
- Returns:
- the current locale (never null)
- Since:
- 6.0
 
- 
setLocaledefault void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.- Specified by:
- setLocalein interface- LocaleResolver
- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- locale- the new locale, or- nullto clear the locale
- Throws:
- UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale
- Since:
- 6.0
 
 
-