grails.util
Class GrailsWebUtil

java.lang.Object
  extended by grails.util.GrailsWebUtil

public class GrailsWebUtil
extends java.lang.Object

Utility methods for clients using the web framework.

Since:
0.4

Field Summary
static java.lang.String DEFAULT_ENCODING
           
 
Constructor Summary
GrailsWebUtil()
           
 
Method Summary
static GrailsWebRequest bindMockWebRequest()
          Binds a Mock implementation of a GrailsWebRequest object to the current thread.
static GrailsWebRequest bindMockWebRequest(org.springframework.web.context.WebApplicationContext ctx)
          Binds a Mock implementation of a GrailsWebRequest object to the current thread.
static GrailsWebRequest bindMockWebRequest(org.springframework.web.context.WebApplicationContext ctx, org.springframework.mock.web.MockHttpServletRequest request, org.springframework.mock.web.MockHttpServletResponse response)
          Binds a Mock implementation of a GrailsWebRequest object to the current thread.
static org.codehaus.groovy.grails.commons.GrailsApplication currentApplication()
           
static java.util.Map currentConfiguration()
           
static java.util.Map currentFlatConfiguration()
           
static java.lang.String getContentType(java.lang.String name, java.lang.String encoding)
           
static groovy.lang.GroovyObject getControllerFromRequest(javax.servlet.http.HttpServletRequest request)
          Obtains the currently executing controller from the given request if any.
static java.lang.String getUriFromRequest(javax.servlet.http.HttpServletRequest request)
          Retrieves the URI from the request from either the include attribute or the request.getRequestURI() method.
static org.codehaus.groovy.grails.commons.GrailsApplication lookupApplication(javax.servlet.ServletContext servletContext)
          Looks up a GrailsApplication instance from the ServletContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
See Also:
Constant Field Values
Constructor Detail

GrailsWebUtil

public GrailsWebUtil()
Method Detail

lookupApplication

public static org.codehaus.groovy.grails.commons.GrailsApplication lookupApplication(javax.servlet.ServletContext servletContext)
Looks up a GrailsApplication instance from the ServletContext.

Parameters:
servletContext - The ServletContext
Returns:
A GrailsApplication or null if there isn't one

currentApplication

public static org.codehaus.groovy.grails.commons.GrailsApplication currentApplication()
Returns:
The currently bound GrailsApplication instance
Since:
2.0

currentConfiguration

public static java.util.Map currentConfiguration()
Returns:
The currently bound GrailsApplication instance
Since:
2.0

currentFlatConfiguration

public static java.util.Map currentFlatConfiguration()
Returns:
The currently bound GrailsApplication instance
Since:
2.0

bindMockWebRequest

public static GrailsWebRequest bindMockWebRequest(org.springframework.web.context.WebApplicationContext ctx)
Binds a Mock implementation of a GrailsWebRequest object to the current thread. The mock version uses instances of the Spring MockHttpServletRequest, MockHttpServletResponse and MockServletContext classes.

Parameters:
ctx - The WebApplicationContext to use
Returns:
The GrailsWebRequest instance
See Also:
MockHttpServletRequest, MockHttpServletResponse, MockServletContext

bindMockWebRequest

public static GrailsWebRequest bindMockWebRequest(org.springframework.web.context.WebApplicationContext ctx,
                                                  org.springframework.mock.web.MockHttpServletRequest request,
                                                  org.springframework.mock.web.MockHttpServletResponse response)
Binds a Mock implementation of a GrailsWebRequest object to the current thread. The mock version uses instances of the Spring MockHttpServletRequest, MockHttpServletResponse and MockServletContext classes.

Parameters:
ctx - The WebApplicationContext to use
request - The request
response - The response
Returns:
The GrailsWebRequest instance
See Also:
MockHttpServletRequest, MockHttpServletResponse, MockServletContext

bindMockWebRequest

public static GrailsWebRequest bindMockWebRequest()
Binds a Mock implementation of a GrailsWebRequest object to the current thread. The mock version uses instances of the Spring MockHttpServletRequest, MockHttpServletResponse and MockServletContext classes.

Returns:
The GrailsWebRequest instance
See Also:
MockHttpServletRequest, MockHttpServletResponse, MockServletContext

getUriFromRequest

public static java.lang.String getUriFromRequest(javax.servlet.http.HttpServletRequest request)
Retrieves the URI from the request from either the include attribute or the request.getRequestURI() method.

Parameters:
request - The HttpServletRequest instance
Returns:
The String URI

getControllerFromRequest

public static groovy.lang.GroovyObject getControllerFromRequest(javax.servlet.http.HttpServletRequest request)
Obtains the currently executing controller from the given request if any.

Parameters:
request - The request object
Returns:
The controller or null

getContentType

public static java.lang.String getContentType(java.lang.String name,
                                              java.lang.String encoding)