org.springframework.web.servlet.support
Class RequestContextUtils


public abstract class RequestContextUtils

Utility class for easy access to various request-specific state, set by the DispatcherServlet.

Author:
Juergen Hoeller
Since: 03.03.2003

Method Summary
 static LocalegetLocale(HttpServletRequest request)
          Retrieves the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet.
 static LocaleResolvergetLocaleResolver(HttpServletRequest request)
          Return the LocaleResolver that has been bound to the request by the DispatcherServlet.
 static MultipartResolvergetMultipartResolver(HttpServletRequest request)
          Return the MultipartResolver that has been bound to the request by the DispatcherServlet.
 static ThemegetTheme(HttpServletRequest request)
          Retrieves the current theme from the given request, using the ThemeResolver bound to the request by the DispatcherServlet, and the current WebApplicationContext.
 static ThemeResolvergetThemeResolver(HttpServletRequest request)
          Return the ThemeResolver that has been bound to the request by the DispatcherServlet.
 static WebApplicationContextgetWebApplicationContext(ServletRequest request)
          Look for the WebApplicationContext associated with the controller servlet that has initiated request processing.
 static WebApplicationContextgetWebApplicationContext(ServletRequest request, ServletContext servletContext)
          Look for the WebApplicationContext associated with the controller servlet that has initiated request processing, and for the global context if none was found associated with the current request.

Method Detail

getLocale

public static Locale getLocale(HttpServletRequest request)
throws java.lang.IllegalStateException
Retrieves the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet.
Parameters:
request - current HTTP request
Returns: the current locale
Throws:
IllegalStateException - if no LocaleResolver has been found

getLocaleResolver

public static LocaleResolver getLocaleResolver(HttpServletRequest request)
throws java.lang.IllegalStateException
Return the LocaleResolver that has been bound to the request by the DispatcherServlet.
Parameters:
request - current HTTP request
Returns: the current LocaleResolver
Throws:
IllegalStateException - if no LocaleResolver has been found

getMultipartResolver

public static MultipartResolver getMultipartResolver(HttpServletRequest request)
Return the MultipartResolver that has been bound to the request by the DispatcherServlet.
Parameters:
request - current HTTP request
Returns: the current MultipartResolver, or null if not a multipart request

getTheme

public static Theme getTheme(HttpServletRequest request)
throws java.lang.IllegalStateException
Retrieves the current theme from the given request, using the ThemeResolver bound to the request by the DispatcherServlet, and the current WebApplicationContext.
Parameters:
request - current HTTP request
Returns: the current theme
Throws:
IllegalStateException - if no ThemeResolver has been found

getThemeResolver

public static ThemeResolver getThemeResolver(HttpServletRequest request)
throws java.lang.IllegalStateException
Return the ThemeResolver that has been bound to the request by the DispatcherServlet.
Parameters:
request - current HTTP request
Returns: the current ThemeResolver
Throws:
IllegalStateException - if no ThemeResolver has been found

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(ServletRequest request)
throws java.lang.IllegalStateException
Look for the WebApplicationContext associated with the controller servlet that has initiated request processing.
Parameters:
request - current HTTP request
Returns: the request-specific web application context
Throws:
IllegalStateException - if neither a servlet-specific nor global context has been found

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(ServletRequest request, ServletContext servletContext)
throws java.lang.IllegalStateException
Look for the WebApplicationContext associated with the controller servlet that has initiated request processing, and for the global context if none was found associated with the current request. This method is useful to allow components outside our framework, such as JSP tag handlers, to access the most specific application context available.
Parameters:
request - current HTTP request
servletContext - current servlet context
Returns: the request-specific or global web application context if no request-specific context has been set
Throws:
IllegalStateException - if neither a servlet-specific nor global context has been found