public abstract class RequestContextUtils
extends java.lang.Object
DispatcherServlet
.
Supports lookup of current WebApplicationContext, LocaleResolver, Locale, ThemeResolver, Theme, and MultipartResolver.
RequestContext
,
DispatcherServlet
Constructor and Description |
---|
RequestContextUtils() |
Modifier and Type | Method and Description |
---|---|
static FlashMapManager |
getFlashMapManager(HttpServletRequest request)
Return the FlashMapManager instance to save flash attributes with
before a redirect.
|
static java.util.Map<java.lang.String,?> |
getInputFlashMap(HttpServletRequest request)
Return a read-only
Map with "input" flash attributes saved on a
previous request. |
static java.util.Locale |
getLocale(HttpServletRequest request)
Retrieve the current locale from the given request, using the
LocaleResolver bound to the request by the DispatcherServlet
(if available), falling back to the request's accept-header Locale.
|
static LocaleResolver |
getLocaleResolver(HttpServletRequest request)
Return the LocaleResolver that has been bound to the request by the
DispatcherServlet.
|
static FlashMap |
getOutputFlashMap(HttpServletRequest request)
Return the "output" FlashMap with attributes to save for a subsequent request.
|
static Theme |
getTheme(HttpServletRequest request)
Retrieves the current theme from the given request, using the ThemeResolver
and ThemeSource bound to the request by the DispatcherServlet.
|
static ThemeResolver |
getThemeResolver(HttpServletRequest request)
Return the ThemeResolver that has been bound to the request by the
DispatcherServlet.
|
static ThemeSource |
getThemeSource(HttpServletRequest request)
Return the ThemeSource that has been bound to the request by the
DispatcherServlet.
|
static java.util.TimeZone |
getTimeZone(HttpServletRequest request)
Retrieve the current time zone from the given request, using the
TimeZoneAwareLocaleResolver bound to the request by the DispatcherServlet
(if available), falling back to the system's default time zone.
|
static WebApplicationContext |
getWebApplicationContext(ServletRequest request)
Look for the WebApplicationContext associated with the DispatcherServlet
that has initiated request processing.
|
static WebApplicationContext |
getWebApplicationContext(ServletRequest request,
ServletContext servletContext)
Look for the WebApplicationContext associated with the DispatcherServlet
that has initiated request processing, and for the global context if none
was found associated with the current request.
|
public static WebApplicationContext getWebApplicationContext(ServletRequest request) throws java.lang.IllegalStateException
request
- current HTTP requestjava.lang.IllegalStateException
- if no servlet-specific context has been foundpublic static WebApplicationContext getWebApplicationContext(ServletRequest request, ServletContext servletContext) throws java.lang.IllegalStateException
request
- current HTTP requestservletContext
- current servlet contextjava.lang.IllegalStateException
- if neither a servlet-specific nor a
global context has been foundpublic static LocaleResolver getLocaleResolver(HttpServletRequest request)
request
- current HTTP requestnull
if not foundpublic static java.util.Locale getLocale(HttpServletRequest request)
This method serves as a straightforward alternative to the standard
Servlet ServletRequest.getLocale()
method,
falling back to the latter if no more specific locale has been found.
Consider using LocaleContextHolder.getLocale()
which will normally be populated with the same Locale.
request
- current HTTP requestgetLocaleResolver(javax.servlet.http.HttpServletRequest)
,
LocaleContextHolder.getLocale()
public static java.util.TimeZone getTimeZone(HttpServletRequest request)
Note: This method returns null
if no specific time zone can be
resolved for the given request. This is in contrast to getLocale(javax.servlet.http.HttpServletRequest)
where there is always the request's accept-header locale to fall back to.
Consider using LocaleContextHolder.getTimeZone()
which will normally be populated with the same TimeZone: That method only
differs in terms of its fallback to the system time zone if the LocaleResolver
hasn't provided provided a specific time zone (instead of this method's null
).
request
- current HTTP requestnull
if none associatedgetLocaleResolver(javax.servlet.http.HttpServletRequest)
,
LocaleContextHolder.getTimeZone()
public static ThemeResolver getThemeResolver(HttpServletRequest request)
request
- current HTTP requestnull
if not foundpublic static ThemeSource getThemeSource(HttpServletRequest request)
request
- current HTTP requestpublic static Theme getTheme(HttpServletRequest request)
request
- current HTTP requestnull
if not foundgetThemeResolver(javax.servlet.http.HttpServletRequest)
public static java.util.Map<java.lang.String,?> getInputFlashMap(HttpServletRequest request)
Map
with "input" flash attributes saved on a
previous request.request
- the current requestnull
if not foundFlashMap
public static FlashMap getOutputFlashMap(HttpServletRequest request)
public static FlashMapManager getFlashMapManager(HttpServletRequest request)
request
- the current requestFlashMapManager
instance (never null
within a DispatcherServlet request)