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(HttpServletRequest) and
setLocale(HttpServletRequest, HttpServletResponse, Locale) which delegate to resolveLocaleContext(HttpServletRequest) and
setLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), respectively.
- Since:
- 4.0
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault LocaleresolveLocale(jakarta.servlet.http.HttpServletRequest request) Default implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.resolveLocaleContext(jakarta.servlet.http.HttpServletRequest request) Resolve the current locale context via the given request.default voidsetLocale(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.voidsetLocaleContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.
-
Method Details
-
resolveLocaleContext
Resolve 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:
-
setLocaleContext
void setLocaleContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.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 modificationresponse- the response to be used for locale modificationlocaleContext- the new locale context, ornullto clear the locale- Throws:
UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale or time zone- See Also:
-
resolveLocale
Default implementation ofLocaleResolver.resolveLocale(HttpServletRequest)that delegates toresolveLocaleContext(HttpServletRequest), falling back toServletRequest.getLocale()if necessary.- Specified by:
resolveLocalein interfaceLocaleResolver- Parameters:
request- the request to resolve the locale for- Returns:
- the current locale (never
null) - Since:
- 6.0
-
setLocale
default void setLocale(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable Locale locale) Default implementation ofLocaleResolver.setLocale(HttpServletRequest, HttpServletResponse, Locale)that delegates tosetLocaleContext(HttpServletRequest, HttpServletResponse, LocaleContext), using aSimpleLocaleContext.- Specified by:
setLocalein interfaceLocaleResolver- Parameters:
request- the request to be used for locale modificationresponse- the response to be used for locale modificationlocale- the new locale, ornullto clear the locale- Throws:
UnsupportedOperationException- if the LocaleResolver implementation does not support dynamic changing of the locale- Since:
- 6.0
-