org.apache.beehive.netui.pageflow.scoping
Class ScopedServletUtils

Object
  extended by ScopedServletUtils

public class ScopedServletUtils
extends Object

Utilities for creating scoped wrapper versions of HttpRequest, HttpResponse, ServletContext. These wrappers are the basis for a scoped servlet environment, which can be used to scope the Struts framework.


Field Summary
static String SCOPE_ID_PARAM
           
 
Constructor Summary
ScopedServletUtils()
           
 
Method Summary
static String decodeURI(HttpServletRequest request)
           
static HttpServletRequest getOuterRequest(HttpServletRequest request)
          Get the outer (unwrapped) request.
static ServletRequest getOuterServletRequest(ServletRequest request)
          Get the outer (unwrapped) request.
static String getRelativeURI(HttpServletRequest request)
          Get the request URI, relative to the webapp root.
static String getRelativeURI(HttpServletRequest request, String uri)
          Get a URI relative to the webapp root.
static String getRelativeURI(String contextPath, String uri)
          Get a URI relative to a given webapp root.
static String getScopedName(String baseName, Object scopeKey)
          Get a scoped version of a given name.
static ScopedRequest getScopedRequest(HttpServletRequest realRequest, String overrideURI, ServletContext servletContext, Object scopeKey)
          Deprecated. Use getScopedRequest(HttpServletRequest, String, ServletContext, Object, boolean).
static ScopedRequest getScopedRequest(HttpServletRequest realRequest, String overrideURI, ServletContext servletContext, Object scopeKey, boolean seeOuterRequestAttributes)
          Get the cached ScopedRequest wrapper.
static Object getScopedRequestAttribute(String attrName, ServletRequest request)
          Get an attribute from the given request, and if it is a ScopedRequest, ensure that the attribute is not "showing through" from the outer request, even if the ScopedRequest allows that by default.
static ScopedResponse getScopedResponse(HttpServletResponse realResponse, ScopedRequest scopedRequest)
          Get the cached wrapper servlet response.
static Object getScopedSessionAttr(String attrName, HttpServletRequest request)
          If the request is a ScopedRequest, this returns an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.getAttribute(java.lang.String).
static String getScopedSessionAttrName(String attrName, HttpServletRequest request)
          If the request is a ScopedRequest, this returns an attribute name scoped to that request's scope-ID; otherwise, it returns the given attribute name.
static String normalizeURI(String uri)
          Resolve "." and ".." in a URI.
static void removeScopedSessionAttr(String attrName, HttpServletRequest request)
          If the request is a ScopedRequest, this removes an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.removeAttribute(java.lang.String).
static void renameScope(Object oldScopeKey, Object newScopeKey, HttpServletRequest request)
          Find all scoped objects (ScopedRequest, ScopedResponse) which have a certain scope-key, replaces this scope-key with the new one, and re-caches the objects the new scope-key.
static void setScopedSessionAttr(String attrName, Object val, HttpServletRequest request)
          If the request is a ScopedRequest, this sets an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.setAttribute(java.lang.String, java.lang.Object).
static ScopedRequest unwrapRequest(ServletRequest request)
          Unwraps the contained ScopedRequest from the given ServletRequest, which may be a ServletRequestWrapper.
static ScopedResponse unwrapResponse(ServletResponse response)
          Unwraps the contained ScopedResponseImpl from the given ServletResponse, which may be a ServletResponseWrapper.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCOPE_ID_PARAM

public static final String SCOPE_ID_PARAM
See Also:
Constant Field Values
Constructor Detail

ScopedServletUtils

public ScopedServletUtils()
Method Detail

getScopedRequest

public static ScopedRequest getScopedRequest(HttpServletRequest realRequest,
                                             String overrideURI,
                                             ServletContext servletContext,
                                             Object scopeKey)
Deprecated. Use getScopedRequest(HttpServletRequest, String, ServletContext, Object, boolean).

Get the cached ScopedRequest wrapper. If none exists, creates one and caches it.

Parameters:
realRequest - the "real" (outer) HttpServletRequest, which will be wrapped.
overrideURI - the request-URI for the wrapped object. This URI must begin with the context path.
servletContext - the current ServletContext.
scopeKey - the scope-key associated with the new (or looked-up) scoped request.
Returns:
the cached (or newly-created) ScopedRequest.

getScopedRequest

public static ScopedRequest getScopedRequest(HttpServletRequest realRequest,
                                             String overrideURI,
                                             ServletContext servletContext,
                                             Object scopeKey,
                                             boolean seeOuterRequestAttributes)
Get the cached ScopedRequest wrapper. If none exists, creates one and caches it.

Parameters:
realRequest - the "real" (outer) HttpServletRequest, which will be wrapped.
overrideURI - the request-URI for the wrapped object. This URI must begin with the context path.
servletContext - the current ServletContext.
scopeKey - the scope-key associated with the new (or looked-up) scoped request.
seeOuterRequestAttributes - if true, a request attribute will be "seen" in the outer request, if it is not found within the scoped request; if false, attributes are only seen when they are present in the scoped request.
Returns:
the cached (or newly-created) ScopedRequest.

getScopedResponse

public static ScopedResponse getScopedResponse(HttpServletResponse realResponse,
                                               ScopedRequest scopedRequest)
Get the cached wrapper servlet response. If none exists, creates one and caches it.

Parameters:
realResponse - the "real" (outer) ServletResponse, which will be wrapped.
scopedRequest - the ScopedRequest returned from getScopedRequest(javax.servlet.http.HttpServletRequest, java.lang.String, javax.servlet.ServletContext, java.lang.Object).
Returns:
the cached (or newly-created) ScopedResponse.

renameScope

public static void renameScope(Object oldScopeKey,
                               Object newScopeKey,
                               HttpServletRequest request)
Find all scoped objects (ScopedRequest, ScopedResponse) which have a certain scope-key, replaces this scope-key with the new one, and re-caches the objects the new scope-key.

Parameters:
oldScopeKey -
newScopeKey -
request - the real (outer) request, where the scoped objects are cached.

getScopedName

public static String getScopedName(String baseName,
                                   Object scopeKey)
Get a scoped version of a given name.

Parameters:
baseName - the name to be scoped.
scopeKey - the context key for scoping the name.
Returns:
a scoped version of the given name.

getOuterRequest

public static HttpServletRequest getOuterRequest(HttpServletRequest request)
Get the outer (unwrapped) request.

Parameters:
request - the request to unwrap.
Returns:
the outer request, if the given request is a ScopedRequest (or wraps a ScopedRequest); otherwise, the given request itself.

getOuterServletRequest

public static ServletRequest getOuterServletRequest(ServletRequest request)
Get the outer (unwrapped) request.

Parameters:
request - the request to unwrap.
Returns:
the outer request, if the given request is a ScopedRequest (or wraps a ScopedRequest); otherwise, the given request itself.

unwrapRequest

public static ScopedRequest unwrapRequest(ServletRequest request)
Unwraps the contained ScopedRequest from the given ServletRequest, which may be a ServletRequestWrapper.

Parameters:
request - the ScopedRequest, or a wrapper (ServletRequestWrapper) around it.
Returns:
the unwrapped ScopedRequest.

unwrapResponse

public static ScopedResponse unwrapResponse(ServletResponse response)
Unwraps the contained ScopedResponseImpl from the given ServletResponse, which may be a ServletResponseWrapper.

Parameters:
response - the ScopedResponse, or a wrapper (ServletResponseWrapper) around it.
Returns:
the unwrapped ScopedResponseImpl.

getScopedSessionAttrName

public static String getScopedSessionAttrName(String attrName,
                                              HttpServletRequest request)
If the request is a ScopedRequest, this returns an attribute name scoped to that request's scope-ID; otherwise, it returns the given attribute name.


getScopedSessionAttr

public static Object getScopedSessionAttr(String attrName,
                                          HttpServletRequest request)
If the request is a ScopedRequest, this returns an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.getAttribute(java.lang.String).


setScopedSessionAttr

public static void setScopedSessionAttr(String attrName,
                                        Object val,
                                        HttpServletRequest request)
If the request is a ScopedRequest, this sets an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.setAttribute(java.lang.String, java.lang.Object).


removeScopedSessionAttr

public static void removeScopedSessionAttr(String attrName,
                                           HttpServletRequest request)
If the request is a ScopedRequest, this removes an attribute whose name is scoped to that request's scope-ID; otherwise, it is a straight passthrough to HttpSession.removeAttribute(java.lang.String).


getScopedRequestAttribute

public static Object getScopedRequestAttribute(String attrName,
                                               ServletRequest request)
Get an attribute from the given request, and if it is a ScopedRequest, ensure that the attribute is not "showing through" from the outer request, even if the ScopedRequest allows that by default.


getRelativeURI

public static final String getRelativeURI(HttpServletRequest request)
Get the request URI, relative to the webapp root.

Parameters:
request - the current HttpServletRequest.

getRelativeURI

public static final String getRelativeURI(HttpServletRequest request,
                                          String uri)
Get a URI relative to the webapp root.

Parameters:
request - the current HttpServletRequest.
uri - the URI which should be made relative.

getRelativeURI

public static final String getRelativeURI(String contextPath,
                                          String uri)
Get a URI relative to a given webapp root.

Parameters:
contextPath - the webapp context path, e.g., "/myWebapp"
uri - the URI which should be made relative.

normalizeURI

public static String normalizeURI(String uri)
Resolve "." and ".." in a URI.


decodeURI

public static String decodeURI(HttpServletRequest request)