Top Description Constructors Methods
org.springframework.web.servlet.i18n

public Class FixedLocaleResolver

extends AbstractLocaleContextResolver
Class Inheritance
Imports
java.util.Locale, .TimeZone, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.context.i18n.LocaleContext, .TimeZoneAwareLocaleContext, org.springframework.lang.Nullable

org.springframework.web.servlet.LocaleResolver 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.

Author
Juergen Hoeller
Since
1.1
See Also
setDefaultLocale, setDefaultTimeZone

Constructor Summary

AccessConstructor and Description
public
FixedLocaleResolver()

Create a default FixedLocaleResolver, exposing a configured default locale (or the JVM's default locale as fallback).

public
FixedLocaleResolver(Locale
the locale to expose
locale
)

Create a FixedLocaleResolver that exposes the given locale.

public
FixedLocaleResolver(Locale
the locale to expose
locale
,
TimeZone
the time zone to expose
timeZone
)

Create a FixedLocaleResolver that exposes the given locale and time zone.

Method Summary

Modifier and TypeMethod and Description
public Locale
public LocaleContext
resolveLocaleContext(HttpServletRequest
the request to resolve the locale context for
request
)

Implements org.springframework.web.servlet.LocaleContextResolver.resolveLocaleContext.

Resolve the current locale context via the given request.

public void
setLocaleContext(HttpServletRequest
the request to be used for locale modification
request
,
HttpServletResponse
the response to be used for locale modification
response
,
LocaleContext
the new locale context, or null to clear the locale
localeContext
)

Implements org.springframework.web.servlet.LocaleContextResolver.setLocaleContext.

Set the current locale context to the given one, potentially including a locale with associated time zone information.

Inherited from org.springframework.web.servlet.i18n.AbstractLocaleContextResolver:
getDefaultTimeZonesetDefaultTimeZone

Constructor Detail

FixedLocaleResolverback to summary
public FixedLocaleResolver()

Create a default FixedLocaleResolver, exposing a configured default locale (or the JVM's default locale as fallback).

See Also
setDefaultLocale, setDefaultTimeZone
FixedLocaleResolverback to summary
public FixedLocaleResolver(Locale locale)

Create a FixedLocaleResolver that exposes the given locale.

Parameters
locale:Locale

the locale to expose

FixedLocaleResolverback to summary
public FixedLocaleResolver(Locale locale, TimeZone timeZone)

Create a FixedLocaleResolver that exposes the given locale and time zone.

Parameters
locale:Locale

the locale to expose

timeZone:TimeZone

the time zone to expose

Method Detail

resolveLocaleback to summary
public Locale resolveLocale(HttpServletRequest request)

Overrides default org.springframework.web.servlet.LocaleContextResolver.resolveLocale.

Implements org.springframework.web.servlet.LocaleResolver.resolveLocale.

Doc from org.springframework.web.servlet.LocaleContextResolver.resolveLocale.

Default implementation of LocaleResolver#resolveLocale(HttpServletRequest) that delegates to resolveLocaleContext(HttpServletRequest), falling back to HttpServletRequest#getLocale() if necessary.

Parameters
request:HttpServletRequest

the request to resolve the locale for

Returns:Locale

the current locale (never null)

Annotations
@Override
resolveLocaleContextback to summary
public LocaleContext resolveLocaleContext(HttpServletRequest request)

Implements org.springframework.web.servlet.LocaleContextResolver.resolveLocaleContext.

Doc from org.springframework.web.servlet.LocaleContextResolver.resolveLocaleContext.

Resolve the current locale context via the given request.

This is primarily intended for framework-level processing; consider using org.springframework.web.servlet.support.RequestContextUtils or org.springframework.web.servlet.support.RequestContext for application-level access to the current locale and/or time zone.

The returned context may be a org.springframework.context.i18n.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.

Parameters
request:HttpServletRequest

the request to resolve the locale context for

Returns:LocaleContext

the current locale context (never null

Annotations
@Override
setLocaleContextback to summary
public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext)

Implements org.springframework.web.servlet.LocaleContextResolver.setLocaleContext.

Doc from org.springframework.web.servlet.LocaleContextResolver.setLocaleContext.

Set the current locale context to the given one, potentially including a locale with associated time zone information.

Parameters
request:HttpServletRequest

the request to be used for locale modification

response:HttpServletResponse

the response to be used for locale modification

localeContext:LocaleContext

the new locale context, or null to clear the locale

Annotations
@Override