public class FixedLocaleContextResolver extends java.lang.Object implements LocaleContextResolver
LocaleContextResolver
implementation that always returns
a fixed default locale and optionally time zone.
Default is the current JVM's default locale.
Note: Does not support setLocale(Context)
, as the fixed
locale and time zone cannot be changed.
Constructor and Description |
---|
FixedLocaleContextResolver()
Create a default FixedLocaleResolver, exposing a configured default
locale (or the JVM's default locale as fallback).
|
FixedLocaleContextResolver(java.util.Locale locale)
Create a FixedLocaleResolver that exposes the given locale.
|
FixedLocaleContextResolver(java.util.Locale locale,
java.util.TimeZone timeZone)
Create a FixedLocaleResolver that exposes the given locale and time zone.
|
Modifier and Type | Method and Description |
---|---|
LocaleContext |
resolveLocaleContext(ServerWebExchange exchange)
Resolve the current locale context via the given exchange.
|
void |
setLocaleContext(ServerWebExchange exchange,
LocaleContext localeContext)
Set the current locale context to the given one,
potentially including a locale with associated time zone information.
|
public FixedLocaleContextResolver()
public FixedLocaleContextResolver(java.util.Locale locale)
locale
- the locale to exposepublic FixedLocaleContextResolver(java.util.Locale locale, @Nullable java.util.TimeZone timeZone)
locale
- the locale to exposetimeZone
- the time zone to exposepublic LocaleContext resolveLocaleContext(ServerWebExchange exchange)
LocaleContextResolver
The returned context may be a
TimeZoneAwareLocaleContext
,
containing a locale with associated time zone information.
Simply apply an instanceof
check and downcast accordingly.
Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.
resolveLocaleContext
in interface LocaleContextResolver
exchange
- current server exchangenull
)public void setLocaleContext(ServerWebExchange exchange, @Nullable LocaleContext localeContext)
LocaleContextResolver
setLocaleContext
in interface LocaleContextResolver
exchange
- current server exchangelocaleContext
- the new locale context, or null
to clear the localeSimpleLocaleContext
,
SimpleTimeZoneAwareLocaleContext