org.springframework.web.servlet.support
Class RequestContextUtils

java.lang.Object
  extended by org.springframework.web.servlet.support.RequestContextUtils

public abstract class RequestContextUtils
extends Object

Utility class for easy access to request-specific state which has been set by the DispatcherServlet.

Supports lookup of current WebApplicationContext, LocaleResolver, Locale, ThemeResolver, Theme, and MultipartResolver.

Since:
03.03.2003
Author:
Juergen Hoeller
See Also:
RequestContext, DispatcherServlet

Constructor Summary
RequestContextUtils()
           
 
Method Summary
static Locale getLocale(HttpServletRequest request)
          Retrieves the current locale from the given request, using the LocaleResolver bound to the request by the DispatcherServlet.
static LocaleResolver getLocaleResolver(HttpServletRequest request)
          Return the LocaleResolver that has been bound to the request by the DispatcherServlet.
static MultipartResolver getMultipartResolver(ServletRequest request)
          Return the MultipartResolver that has been bound to the request by the DispatcherServlet.
static Theme getTheme(HttpServletRequest request)
          Retrieves the current theme from the given request, using the ThemeResolver 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestContextUtils

public RequestContextUtils()
Method Detail

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(ServletRequest request)
                                                      throws IllegalStateException
Look for the WebApplicationContext associated with the DispatcherServlet that has initiated request processing.

Parameters:
request - current HTTP request
Returns:
the request-specific web application context
Throws:
IllegalStateException - if no servlet-specific context has been found

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(ServletRequest request,
                                                             ServletContext servletContext)
                                                      throws IllegalStateException
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. This method is useful to allow components outside the 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 WebApplicationContext, or the global one if no request-specific context has been found
Throws:
IllegalStateException - if neither a servlet-specific nor a global context has been found

getLocaleResolver

public static LocaleResolver getLocaleResolver(HttpServletRequest request)
                                        throws 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

getLocale

public static Locale getLocale(HttpServletRequest request)
                        throws 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
See Also:
getLocaleResolver(javax.servlet.http.HttpServletRequest)

getThemeResolver

public static ThemeResolver getThemeResolver(HttpServletRequest request)
                                      throws 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

getTheme

public static Theme getTheme(HttpServletRequest request)
                      throws IllegalStateException
Retrieves the current theme from the given request, using the ThemeResolver bound to the request by the DispatcherServlet.

Parameters:
request - current HTTP request
Returns:
the current theme
Throws:
IllegalStateException - if no ThemeResolver has been found
See Also:
getThemeResolver(javax.servlet.http.HttpServletRequest)

getMultipartResolver

public static MultipartResolver getMultipartResolver(ServletRequest 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


Copyright (c) 2002-2006 The Spring Framework Project.