## org.codehaus.groovy.grails.web.util
Class WebUtils

    java.lang.Object
      org.springframework.web.util.WebUtils
          org.codehaus.groovy.grails.web.util.WebUtils

    public class WebUtils

extends WebUtils

Utility methods to access commons objects and perform common web related functions for the internal framework

Since:
  1.0

  Created: Oct 10, 2007
Author:
  Graeme Rocher

Field Summary
`static String` `DISPATCH_ACTION_PARAMETER`
`static String` `ENABLE_FILE_EXTENSIONS`
`static char` `SLASH`

Fields inherited from class org.springframework.web.util.WebUtils

`CONTENT_TYPE_CHARSET_PREFIX, DEFAULT_CHARACTER_ENCODING, DEFAULT_WEB_APP_ROOT_KEY, ERROR_EXCEPTION_ATTRIBUTE, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ERROR_MESSAGE_ATTRIBUTE, ERROR_REQUEST_URI_ATTRIBUTE, ERROR_SERVLET_NAME_ATTRIBUTE, ERROR_STATUS_CODE_ATTRIBUTE, FORWARD_CONTEXT_PATH_ATTRIBUTE, FORWARD_PATH_INFO_ATTRIBUTE, FORWARD_QUERY_STRING_ATTRIBUTE, FORWARD_REQUEST_URI_ATTRIBUTE, FORWARD_SERVLET_PATH_ATTRIBUTE, HTML_ESCAPE_CONTEXT_PARAM, INCLUDE_CONTEXT_PATH_ATTRIBUTE, INCLUDE_PATH_INFO_ATTRIBUTE, INCLUDE_QUERY_STRING_ATTRIBUTE, INCLUDE_REQUEST_URI_ATTRIBUTE, INCLUDE_SERVLET_PATH_ATTRIBUTE, SESSION_MUTEX_ATTRIBUTE, SUBMIT_IMAGE_SUFFIXES, TEMP_DIR_CONTEXT_ATTRIBUTE, WEB_APP_ROOT_KEY_PARAM`

Constructor Summary
`WebUtils()`

Method Summary
`static boolean` `areFileExtensionsEnabled()` Returns the value of the "grails.mime.file.extensions" setting configured in COnfig.groovy
`static String` `buildDispatchUrlForMapping(UrlMappingInfo info)` Constructs the URI to forward to using the given request and UrlMappingInfo instance
`static void` `clearGrailsWebRequest()` Removes any GrailsWebRequest instance from the current request.
`static String` `forwardRequestForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info)`
`static String` `forwardRequestForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info, Map model)`
`static String` `forwardRequestForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info, Map model, boolean includeParams)` Forwards a request for the given UrlMappingInfo object and model
`static String` `getFormatFromURI(String uri)` Obtains the format from the URI.
`static String` `getForwardURI(HttpServletRequest request)` Obtains the forwardURI from the request, since Grails uses a forwarding technique for URL mappings.
`static String` `getRequestURIForGrailsDispatchURI(HttpServletRequest request)` The Grails dispatch servlet maps URIs like /app/grails/example/index.dispatch.
`static IncludedContent` `includeForUrl(String includeUrl, HttpServletRequest request, HttpServletResponse response, Map model)` Includes the given URL returning the resulting content as a String
`static IncludedContent` `includeForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info, Map model)` Include whatever the given UrlMappingInfo maps to within the current response
`static GrailsApplication` `lookupApplication(ServletContext servletContext)` Looks up the GrailsApplication instance
`static HandlerInterceptor[]` `lookupHandlerInterceptors(ServletContext servletContext)` Looks up all of the HandlerInterceptor instances registered for the application
`static UrlMappingsHolder` `lookupUrlMappings(ServletContext servletContext)` Looks up the UrlMappingsHolder instance
`static ViewResolver` `lookupViewResolver(ServletContext servletContext)`
`static WebRequestInterceptor[]` `lookupWebRequestInterceptors(ServletContext servletContext)` Looks up all of the WebRequestInterceptor instances registered with the application
`static View` `resolveView(HttpServletRequest request, String viewName, String controllerName, ViewResolver viewResolver)` Resolves a view for the given view name and controller name
`static View` `resolveView(HttpServletRequest request, UrlMappingInfo info, String viewName, ViewResolver viewResolver)` Resolves a view for the given view and UrlMappingInfo instance
`static GrailsWebRequest` `retrieveGrailsWebRequest()` Returns the GrailsWebRequest associated with the current request.
`static void` `storeGrailsWebRequest(GrailsWebRequest webRequest)` Helper method to store the given GrailsWebRequest for the current request.
`static String` `toQueryString(Map parameters)` Converts the given parameters to a query string using the default UTF-8 encoding
`static String` `toQueryString(Map params, String encoding)` Converts the given params into a query string started with ?

Methods inherited from class org.springframework.web.util.WebUtils

`clearErrorRequestAttributes, exposeErrorRequestAttributes, exposeForwardRequestAttributes, exposeRequestAttributes, extractFilenameFromUrlPath, extractFullFilenameFromUrlPath, findParameterValue, findParameterValue, getCookie, getDefaultHtmlEscape, getOrCreateSessionAttribute, getParametersStartingWith, getRealPath, getRequiredSessionAttribute, getSessionAttribute, getSessionId, getSessionMutex, getTargetPage, getTempDir, hasSubmitParameter, isDefaultHtmlEscape, isIncludeRequest, removeWebAppRootSystemProperty, setSessionAttribute, setWebAppRootSystemProperty`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SLASH

    public static final char SLASH

See Also:
  Constant Field Values

### ENABLE_FILE_EXTENSIONS

    public static final String ENABLE_FILE_EXTENSIONS

See Also:
  Constant Field Values

### DISPATCH_ACTION_PARAMETER

    public static final String DISPATCH_ACTION_PARAMETER

See Also:
  Constant Field Values

Constructor Detail

### WebUtils

    public WebUtils()

Method Detail

### lookupViewResolver

    public static ViewResolver lookupViewResolver(ServletContext servletContext)

### lookupHandlerInterceptors

    public static HandlerInterceptor[] lookupHandlerInterceptors(ServletContext servletContext)

  Looks up all of the HandlerInterceptor instances registered for the application

  Parameters:
    `servletContext` - The ServletContext instance
  Returns:
    An array of HandlerInterceptor instances

### lookupWebRequestInterceptors

    public static WebRequestInterceptor[] lookupWebRequestInterceptors(ServletContext servletContext)

  Looks up all of the WebRequestInterceptor instances registered with the application

  Parameters:
    `servletContext` - The ServletContext instance
  Returns:
    An array of WebRequestInterceptor instances

### lookupUrlMappings

    public static UrlMappingsHolder lookupUrlMappings(ServletContext servletContext)

  Looks up the UrlMappingsHolder instance

  Parameters:
    `servletContext` - The ServletContext object
  Returns:
    The UrlMappingsHolder

### getRequestURIForGrailsDispatchURI

    public static String getRequestURIForGrailsDispatchURI(HttpServletRequest request)

  The Grails dispatch servlet maps URIs like /app/grails/example/index.dispatch. This method infers the controller URI for the dispatch URI so that /app/grails/example/index.dispatch becomes /app/example/index

  Parameters:
    `request` - The request

### lookupApplication

    public static GrailsApplication lookupApplication(ServletContext servletContext)

  Looks up the GrailsApplication instance

  Returns:
    The GrailsApplication instance

### resolveView

    public static View resolveView(HttpServletRequest request,
                                   UrlMappingInfo info,
                                   String viewName,
                                   ViewResolver viewResolver)
                            throws Exception

  Resolves a view for the given view and UrlMappingInfo instance

  Parameters:
    `request` - The request
    `info` - The info
    `viewName` - The view name
    `viewResolver` - The view resolver
  Returns:
    The view or null
  Throws:
    `Exception`

### resolveView

    public static View resolveView(HttpServletRequest request,
                                   String viewName,
                                   String controllerName,
                                   ViewResolver viewResolver)
                            throws Exception

  Resolves a view for the given view name and controller name

  Parameters:
    `request` - The request
    `viewName` - The view name
    `controllerName` - The controller name
    `viewResolver` - The resolver
  Returns:
    A View or null
  Throws:
    `Exception` - Thrown if an error occurs

### buildDispatchUrlForMapping

    public static String buildDispatchUrlForMapping(UrlMappingInfo info)

  Constructs the URI to forward to using the given request and UrlMappingInfo instance

  Parameters:
    `info` - The UrlMappingInfo
  Returns:
    The URI to forward to

### forwardRequestForUrlMappingInfo

    public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
                                                         HttpServletResponse response,
                                                         UrlMappingInfo info)
                                                  throws ServletException,
                                                         IOException

  Throws:
    `ServletException`
    `IOException`
  See Also:
    `forwardRequestForUrlMappingInfo(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.codehaus.groovy.grails.web.mapping.UrlMappingInfo, java.util.Map)`

### forwardRequestForUrlMappingInfo

    public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
                                                         HttpServletResponse response,
                                                         UrlMappingInfo info,
                                                         Map model)
                                                  throws ServletException,
                                                         IOException

  Throws:
    `ServletException`
    `IOException`
  See Also:
    `forwardRequestForUrlMappingInfo(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.codehaus.groovy.grails.web.mapping.UrlMappingInfo, java.util.Map, boolean)`

### forwardRequestForUrlMappingInfo

    public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
                                                         HttpServletResponse response,
                                                         UrlMappingInfo info,
                                                         Map model,
                                                         boolean includeParams)
                                                  throws ServletException,
                                                         IOException

  Forwards a request for the given UrlMappingInfo object and model

  Parameters:
    `request` - The request
    `response` - The response
    `info` - The UrlMappingInfo object
    `model` - The Model
    `includeParams` - Whether to include any request parameters
  Returns:
    The URI forwarded too
  Throws:
    `ServletException` - Thrown when an error occurs executing the forward
    `IOException` - Thrown when an error occurs executing the forward

### includeForUrlMappingInfo

    public static IncludedContent includeForUrlMappingInfo(HttpServletRequest request,
                                                           HttpServletResponse response,
                                                           UrlMappingInfo info,
                                                           Map model)

  Include whatever the given UrlMappingInfo maps to within the current response

  Parameters:
    `request` - The request
    `response` - The response
    `info` - The UrlMappingInfo
    `model` - The model
  Returns:
    The included content

### includeForUrl

    public static IncludedContent includeForUrl(String includeUrl,
                                                HttpServletRequest request,
                                                HttpServletResponse response,
                                                Map model)

  Includes the given URL returning the resulting content as a String

  Parameters:
    `includeUrl` - The URL to include
    `request` - The request
    `response` - The response
    `model` - The model
  Returns:
    The content

### toQueryString

    public static String toQueryString(Map params,
                                       String encoding)
                                throws UnsupportedEncodingException

  Converts the given params into a query string started with ?

  Parameters:
    `params` - The params
    `encoding` - The encoding to use
  Returns:
    The query string
  Throws:
    `UnsupportedEncodingException` - If the given encoding is not supported

### toQueryString

    public static String toQueryString(Map parameters)
                                throws UnsupportedEncodingException

  Converts the given parameters to a query string using the default UTF-8 encoding

  Parameters:
    `parameters` - The parameters
  Returns:
    The query string
  Throws:
    `UnsupportedEncodingException` - If UTF-8 encoding is not supported

### getFormatFromURI

    public static String getFormatFromURI(String uri)

  Obtains the format from the URI. The format is the string following the . file extension in the last token of the URI. If nothing comes after the ".", this method assumes that there is no format and returns `null`.

  Parameters:
    `uri` - The URI
  Returns:
    The format or null if none

### areFileExtensionsEnabled

    public static boolean areFileExtensionsEnabled()

  Returns the value of the "grails.mime.file.extensions" setting configured in COnfig.groovy

  Returns:
    True if file extensions are enabled

### retrieveGrailsWebRequest

    public static GrailsWebRequest retrieveGrailsWebRequest()

  Returns the GrailsWebRequest associated with the current request. This is the preferred means of accessing the GrailsWebRequest instance. If the exception is undesired, you can use RequestContextHolder.getRequestAttributes() instead.

  Throws:
    `IllegalStateException` - if this is called outside of a request.

### storeGrailsWebRequest

    public static void storeGrailsWebRequest(GrailsWebRequest webRequest)

  Helper method to store the given GrailsWebRequest for the current request. Ensures consistency between RequestContextHolder and the relevant request attribute. This is the preferred means of updating the current web request.

### clearGrailsWebRequest

    public static void clearGrailsWebRequest()

  Removes any GrailsWebRequest instance from the current request.

### getForwardURI

    public static String getForwardURI(HttpServletRequest request)

  Obtains the forwardURI from the request, since Grails uses a forwarding technique for URL mappings. The actual request URI is held within a request attribute

  Parameters:
    `request` - The request
  Returns:
    The forward URI

Copyright (c) 2005-2009 The Grails project