com.opencms.flex.cache
Class CmsFlexRequest

java.lang.Object
  |
  +--javax.servlet.ServletRequestWrapper
        |
        +--javax.servlet.http.HttpServletRequestWrapper
              |
              +--com.opencms.flex.cache.CmsFlexRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class CmsFlexRequest
extends javax.servlet.http.HttpServletRequestWrapper

Wrapper class for a HttpServletRequest.

This class wrapps the standard HttpServletRequest so that it's output can be delivered to the CmsFlexCache.

Version:
$Revision: 1.12 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com)

Field Summary
static String C_ATTR_PROCESSED
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
CmsFlexRequest(CmsFlexRequest req, String resource)
          Constructs a new wrapper layer around a (already wrapped) CmsFlexRequest.
CmsFlexRequest(javax.servlet.http.HttpServletRequest req, CmsFile file, CmsFlexCache cache, CmsObject cms)
          Creates a new CmsFlexRequest wrapper which is most likley the "Top" request wrapper, i.e. the wrapper that is constructed around the first "real" (not wrapped) request.
 
Method Summary
 Map addParameterMap(Map map)
          Adds the specified Map to the paramters of the request.
 CmsFlexCache getCmsCache()
          Returns the CmsFlexCache instance where all results from this request will be cached in.
 CmsFile getCmsFile()
          This method provides access to the top-level CmsFile of the request which is of a type that supports the FlexCache, i.e. usually the CmsFile that is identical to the file uri requested by the user, not he current included element.
protected  Set getCmsIncludeCalls()
          Returns the Set of include calls which will be passed to the next wrapping layer.
 CmsObject getCmsObject()
          Returns the CmsObject that belongs to the request.
 CmsFlexRequestDispatcher getCmsRequestDispatcher(String target)
          Replacement for the standard servlet API getRequestDispatcher() method.
 CmsFlexRequestDispatcher getCmsRequestDispatcher(String cms_target, String ext_target)
          Replacement for the standard servlet API getRequestDispatcher() method.
 String getCmsRequestedResource()
          Returns the OpenCms URI of the resource requested by the user.
 String getCmsResource()
          Returns the name of the resource currently processed.
 javax.servlet.http.HttpServletRequest getCmsTopRequest()
          This returns the "Top" request, i.e. the first wrapped request that is not of type CmsFlexRequest.
 String getParameter(String name)
          Return the value of the specified request parameter, if any; otherwise, return null.
 Map getParameterMap()
          Returns a Map of the parameters of this request.
 Enumeration getParameterNames()
          Return the names of all defined request parameters for this request.
 String[] getParameterValues(String name)
          Returns the defined values for the specified request parameter, if any; otherwise, return null.
 javax.servlet.RequestDispatcher getRequestDispatcher(String target)
          Overloads the standard servlet API getRequestDispatcher() method, which is the main purpose of this wrapper implementation.
 String getRequestURI()
          Wraps the request URI, overloading the standard API.
 StringBuffer getRequestURL()
          Wraps the request URL, overloading the standard API, the wrapped URL will always point to the currently included VFS resource.
 boolean isDoRecompile()
          Checks if JSPs should always be recompiled.
 boolean isOnline()
          Indicates that this request belongs to an online project.
 void setParameterMap(Map map)
          Sets the specified Map as paramter map of the request.
 String toAbsolute(String location)
          Convert (if necessary) and return the absolute URI that represents the resource referenced by this possibly relative URI for this request.
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole
 
Methods inherited from class javax.servlet.ServletRequestWrapper
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRequest, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding, setRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocale, getLocales, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getScheme, getServerName, getServerPort, isSecure, removeAttribute, setAttribute, setCharacterEncoding
 

Field Detail

C_ATTR_PROCESSED

public static String C_ATTR_PROCESSED
Constructor Detail

CmsFlexRequest

public CmsFlexRequest(javax.servlet.http.HttpServletRequest req,
                      CmsFile file,
                      CmsFlexCache cache,
                      CmsObject cms)
Creates a new CmsFlexRequest wrapper which is most likley the "Top" request wrapper, i.e. the wrapper that is constructed around the first "real" (not wrapped) request.

Parameters:
file - the CmsFile (target resource) that has been requested
req - the request to wrap
cache - the CmsFlexCache used to store the cached result (needed by the dispatcher)
cms - the CmsObject for this request, containing the user authorization, needed by the dispatcher

CmsFlexRequest

public CmsFlexRequest(CmsFlexRequest req,
                      String resource)
Constructs a new wrapper layer around a (already wrapped) CmsFlexRequest.

Parameters:
req - the request to be wrapped
resource - the target resource that has been requested
Method Detail

getCmsTopRequest

public javax.servlet.http.HttpServletRequest getCmsTopRequest()
This returns the "Top" request, i.e. the first wrapped request that is not of type CmsFlexRequest.

This is needed for access to the requestDispatcher of this top request, which is used to access external resources (like JSP files that must reside in the file system).

Returns:
the top request

getCmsObject

public CmsObject getCmsObject()
Returns the CmsObject that belongs to the request.

Returns:
the CmsObject that belongs to the request

getCmsCache

public CmsFlexCache getCmsCache()
Returns the CmsFlexCache instance where all results from this request will be cached in.

This is public so that pages like the Flex Cache Administration page have a way to access the cache object.

Returns:
the CmsFlexCache instance where all results from this request will be cached in

getCmsFile

public CmsFile getCmsFile()
This method provides access to the top-level CmsFile of the request which is of a type that supports the FlexCache, i.e. usually the CmsFile that is identical to the file uri requested by the user, not he current included element.

In case a JSP is used as a sub-element in a XMLTemplate, this method will not return the top-level uri but the "topmost" file of a type that is supported by the FlexCache. In case you need the top uri, use getCmsObject().getRequestContext().getUri().

Returns:
the requested top-level CmsFile

getCmsResource

public String getCmsResource()
Returns the name of the resource currently processed.

This might be the name of an included resource, not neccesarily the name the resource requested by the user.

Returns:
the name of the resource currently processed
See Also:
getCmsRequestedResource()

getCmsRequestedResource

public String getCmsRequestedResource()
Returns the OpenCms URI of the resource requested by the user.

This might not be the resource currently processed, which might be an included resource. Same as calling CmsRequestContext.getUri().

Returns:
the OpenCms URI of the resource requested by the user
See Also:
getCmsResource(), CmsRequestContext.getUri()

toAbsolute

public String toAbsolute(String location)
Convert (if necessary) and return the absolute URI that represents the resource referenced by this possibly relative URI for this request.

Adjust for resources in the OpenCms VFS by cutting of servlet context and servlet name. If this URI is already absolute, return it unchanged. Return URI also unchanged if it is not well-formed.

Parameters:
location - URI to be (possibly) converted and then returned
Returns:
the location converted to an absolut location

getCmsRequestDispatcher

public CmsFlexRequestDispatcher getCmsRequestDispatcher(String cms_target,
                                                        String ext_target)
Replacement for the standard servlet API getRequestDispatcher() method.

This variation is used if an external file (probably JSP) is dispached to. This external file must have a "mirror" version, i.e. a file in the OpenCms VFS that represents the external file.

Parameters:
cms_target - the OpenCms file that is a "mirror" version of the external file
ext_target - the external file (outside the OpenCms VFS)
Returns:
the constructed CmsFlexRequestDispatcher

getCmsRequestDispatcher

public CmsFlexRequestDispatcher getCmsRequestDispatcher(String target)
Replacement for the standard servlet API getRequestDispatcher() method.

This variation can be used if you know that you are dealing with a CmsFlexRequest, so you can avoid casting the result of getRequestDispatcher() to the CmsFlexRequestDispatcher.

Parameters:
target - the target for the request dispatcher
Returns:
the constructed CmsFlexRequestDispatcher

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String target)
Overloads the standard servlet API getRequestDispatcher() method, which is the main purpose of this wrapper implementation.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest
Overrides:
getRequestDispatcher in class javax.servlet.ServletRequestWrapper
Parameters:
target - the target for the request dispatcher
Returns:
the constructed RequestDispatcher

getRequestURI

public String getRequestURI()
Wraps the request URI, overloading the standard API.

This ensures that any wrapped request will use the "faked" target parameters. Remember that for the real request, a mixture of PathInfo and other request information is used to idenify the target.

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest
Overrides:
getRequestURI in class javax.servlet.http.HttpServletRequestWrapper
Returns:
a faked URI that will point to the wrapped target in the VFS
See Also:
HttpServletRequest.getRequestURI()

getParameter

public String getParameter(String name)
Return the value of the specified request parameter, if any; otherwise, return null.

If there is more than one value defined, return only the first one.

Specified by:
getParameter in interface javax.servlet.ServletRequest
Overrides:
getParameter in class javax.servlet.ServletRequestWrapper
Parameters:
name - the name of the desired request parameter
See Also:
ServletRequest.getParameter(java.lang.String)

getParameterMap

public Map getParameterMap()
Returns a Map of the parameters of this request.

Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Overrides:
getParameterMap in class javax.servlet.ServletRequestWrapper
Returns:
a Map containing parameter names as keys and parameter values as map values
See Also:
ServletRequest.getParameterMap()

getParameterNames

public Enumeration getParameterNames()
Return the names of all defined request parameters for this request.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Overrides:
getParameterNames in class javax.servlet.ServletRequestWrapper
Returns:
the names of all defined request parameters for this request
See Also:
ServletRequest.getParameterNames()

getParameterValues

public String[] getParameterValues(String name)
Returns the defined values for the specified request parameter, if any; otherwise, return null.

Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Overrides:
getParameterValues in class javax.servlet.ServletRequestWrapper
Parameters:
name - Name of the desired request parameter
Returns:
the defined values for the specified request parameter, if any; null otherwise
See Also:
ServletRequest.getParameterValues(java.lang.String)

addParameterMap

public Map addParameterMap(Map map)
Adds the specified Map to the paramters of the request.

Added parametes will not overwrite existing parameters in the request. Remember that the value for a parameter name in a HttpRequest is a String array. If a parameter name already exists in the HttpRequest, the values will be added to the existing value array. Multiple occurences of the same value for one paramter are also possible.

Parameters:
map - the map to add
Returns:
the merged map of parameters

setParameterMap

public void setParameterMap(Map map)
Sets the specified Map as paramter map of the request.

The map set should be immutable. This will completly replace the parameter map. Use this in combination with getParameterMap() and addParameterMap() in case you want to set the old status of the parameter map after you have modified it for a specific operation.

Parameters:
map - the map to set

getRequestURL

public StringBuffer getRequestURL()
Wraps the request URL, overloading the standard API, the wrapped URL will always point to the currently included VFS resource.

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest
Overrides:
getRequestURL in class javax.servlet.http.HttpServletRequestWrapper
Returns:
a faked URL that will point to the included target in the VFS
See Also:
HttpServletRequest.getRequestURL()

isOnline

public boolean isOnline()
Indicates that this request belongs to an online project.

This is required to distinguish between online and offline resources in the cache. Since the resources have the same name, a suffix [online] or [offline] is added to distinguish the strings when building cache keys. Any resource from a request that isOnline() will be saved with the [online] suffix and vice versa.

The suffixes are used so that we have a simple String name for the resources in the cache. This makes it easy to use a standard HashMap for storage of the resources.

Returns:
true if an online resource was requested, false otherwise

isDoRecompile

public boolean isDoRecompile()
Checks if JSPs should always be recompiled.

This is useful in case directive based includes are used with <%@ include file="..." %> on a JSP. Note that this also forces the request not to be cached.

Returns:
true if JSPs should be recompiled, false otherwise

getCmsIncludeCalls

protected Set getCmsIncludeCalls()
Returns the Set of include calls which will be passed to the next wrapping layer.

The set of include calls is maintained to dectect an endless inclusion loop.

Returns:
the Set of include calls