Class CmsFlexController
- java.lang.Object
-
- org.opencms.flex.CmsFlexController
-
public class CmsFlexController extends java.lang.Object
Controller for getting access to the CmsObject, should be used as a request attribute.- Since:
- 6.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTRIBUTE_NAMEConstant for the controller request attribute name.
-
Constructor Summary
Constructors Constructor Description CmsFlexController(CmsObject cms, CmsResource resource, CmsFlexCache cache, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean streaming, boolean top)Default constructor.CmsFlexController(CmsObject cms, CmsFlexController base)Creates a new controller form the old one, exchanging just the provided OpenCms user context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all data of this controller.CmsFlexCachegetCmsCache()Returns the CmsFlexCache instance where all results from this request will be cached in.CmsObjectgetCmsObject()Returns the wrapped CmsObject.static CmsObjectgetCmsObject(javax.servlet.ServletRequest req)Returns the wrapped CmsObject form the provided request, ornullif the request is not running inside OpenCms.CmsResourcegetCmsResource()This method provides access to the top-level CmsResource of the request which is of a type that supports the FlexCache, i.e.static CmsFlexControllergetController(javax.servlet.ServletRequest req)Returns the controller from the given request, ornullif the request is not running inside OpenCms.CmsFlexRequestgetCurrentRequest()Returns the current flex request.CmsFlexResponsegetCurrentResponse()Returns the current flex response.longgetDateExpires()Returns the combined "expires" date for all resources read during this request.longgetDateLastModified()Returns the combined "last modified" date for all resources read during this request.intgetResponseStackSize()Returns the size of the response stack.java.lang.ThrowablegetThrowable()Returns an exception (Throwable) that was caught during inclusion of sub elements, or null if no exceptions where thrown in sub elements.static java.lang.ThrowablegetThrowable(javax.servlet.ServletRequest req)Provides access to a root cause Exception that might have occurred in a complex include scenario.java.lang.StringgetThrowableResourceUri()Returns the URI of a VFS resource that caused the exception that was caught during inclusion of sub elements, might return null if no URI information was available for the exception.static java.lang.StringgetThrowableResourceUri(javax.servlet.ServletRequest req)Provides access to URI of a VFS resource that caused an exception that might have occurred in a complex include scenario.javax.servlet.http.HttpServletRequestgetTopRequest()Returns the current http request.javax.servlet.http.HttpServletResponsegetTopResponse()Returns the current http response.static booleanisCmsOnlineRequest(javax.servlet.ServletRequest req)Checks if the provided request is running in OpenCms and the current users project is the online project.static booleanisCmsRequest(javax.servlet.ServletRequest req)Checks if the provided request is running in OpenCms.booleanisEmptyRequestList()Returnstrueif the controller does not yet contain any requests.booleanisForwardMode()Returnstrueif this controller is currently in "forward" mode.static booleanisNotModifiedSince(javax.servlet.http.HttpServletRequest req, long dateLastModified)Checks if the request has the "If-Modified-Since" header set, and if so, if the header date value is equal to the provided last modification date.booleanisStreaming()Returnstrueif the generated output of the response should be written to the stream directly.booleanisTop()Returnstrueif this controller was generated as top level controller.voidpop()Removes the topmost request/response pair from the stack.voidpush(CmsFlexRequest req, CmsFlexResponse res)Adds another flex request/response pair to the stack.static voidregisterUncacheableAttribute(java.lang.String attributeName)Tells the flex controller to never cache the given attribute.static voidremoveController(javax.servlet.ServletRequest req)Removes the controller attribute from a request.voidremoveUncacheableAttributes(java.util.Map<java.lang.String,java.lang.Object> attributeMap)Removes request attributes which shouldn't be cached in flex cache entries from a map.static voidsetController(javax.servlet.ServletRequest req, CmsFlexController controller)Stores the given controller in the given request (using a request attribute).static voidsetDateExpiresHeader(javax.servlet.http.HttpServletResponse res, long dateExpires, long maxAge)Sets theExpiresdate header for a given http request.static voidsetDateLastModifiedHeader(javax.servlet.http.HttpServletResponse res, long dateLastModified)Sets the "last modified" date header for a given http request.voidsetForwardMode(boolean value)Sets the value of the "forward mode" flag.java.lang.ThrowablesetThrowable(java.lang.Throwable throwable, java.lang.String resource)Sets an exception (Throwable) that was caught during inclusion of sub elements.voidsuspendFlexResponse()Puts the response in a suspended state.voidupdateDates(long dateLastModified, long dateExpires)Updates the "last modified" date and the "expires" date for all resources read during this request with the given values.
-
-
-
Field Detail
-
ATTRIBUTE_NAME
public static final java.lang.String ATTRIBUTE_NAME
Constant for the controller request attribute name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsFlexController
public CmsFlexController(CmsObject cms, CmsFlexController base)
Creates a new controller form the old one, exchanging just the provided OpenCms user context.- Parameters:
cms- the OpenCms user context for this controllerbase- the base controller
-
CmsFlexController
public CmsFlexController(CmsObject cms, CmsResource resource, CmsFlexCache cache, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean streaming, boolean top)
Default constructor.- Parameters:
cms- the initial CmsObject to wrap in the controllerresource- the file requestedcache- the instance of the flex cachereq- the current requestres- the current responsestreaming- indicates if the response is streamingtop- indicates if the response is the top response
-
-
Method Detail
-
getCmsObject
public static CmsObject getCmsObject(javax.servlet.ServletRequest req)
Returns the wrapped CmsObject form the provided request, ornullif the request is not running inside OpenCms.- Parameters:
req- the current request- Returns:
- the wrapped CmsObject
-
getController
public static CmsFlexController getController(javax.servlet.ServletRequest req)
Returns the controller from the given request, ornullif the request is not running inside OpenCms.- Parameters:
req- the request to get the controller from- Returns:
- the controller from the given request, or
nullif the request is not running inside OpenCms
-
getThrowable
public static java.lang.Throwable getThrowable(javax.servlet.ServletRequest req)
Provides access to a root cause Exception that might have occurred in a complex include scenario.- Parameters:
req- the current request- Returns:
- the root cause exception or null if no root cause exception is available
- See Also:
getThrowable()
-
getThrowableResourceUri
public static java.lang.String getThrowableResourceUri(javax.servlet.ServletRequest req)
Provides access to URI of a VFS resource that caused an exception that might have occurred in a complex include scenario.- Parameters:
req- the current request- Returns:
- to URI of a VFS resource that caused an exception, or
null - See Also:
getThrowableResourceUri()
-
isCmsOnlineRequest
public static boolean isCmsOnlineRequest(javax.servlet.ServletRequest req)
Checks if the provided request is running in OpenCms and the current users project is the online project.- Parameters:
req- the current request- Returns:
trueif the request is running in OpenCms and the current users project is the online project,falseotherwise
-
isCmsRequest
public static boolean isCmsRequest(javax.servlet.ServletRequest req)
Checks if the provided request is running in OpenCms.- Parameters:
req- the current request- Returns:
trueif the request is running in OpenCms,falseotherwise
-
isNotModifiedSince
public static boolean isNotModifiedSince(javax.servlet.http.HttpServletRequest req, long dateLastModified)
Checks if the request has the "If-Modified-Since" header set, and if so, if the header date value is equal to the provided last modification date.- Parameters:
req- the request to set the "If-Modified-Since" date header fromdateLastModified- the date to compare the header with- Returns:
trueif the header is set and the header date is equal to the provided date
-
registerUncacheableAttribute
public static void registerUncacheableAttribute(java.lang.String attributeName)
Tells the flex controller to never cache the given attribute.- Parameters:
attributeName- the attribute which shouldn't be cached
-
removeController
public static void removeController(javax.servlet.ServletRequest req)
Removes the controller attribute from a request.- Parameters:
req- the request to remove the controller from
-
setController
public static void setController(javax.servlet.ServletRequest req, CmsFlexController controller)
Stores the given controller in the given request (using a request attribute).- Parameters:
req- the request where to store the controller incontroller- the controller to store
-
setDateExpiresHeader
public static void setDateExpiresHeader(javax.servlet.http.HttpServletResponse res, long dateExpires, long maxAge)
Sets theExpiresdate header for a given http request.Also sets the
cache-control: max-ageheader to the time of the expiration. A certain upper limit is imposed on the expiration date parameter to ensure the resources are not cached to long in proxies. This can be controlled by themaxAgeparameter. IfmaxAgeis lower then 0, then a default max age of 86400000 msec (1 day) is used.- Parameters:
res- the response to set the "Expires" date header formaxAge- maximum amount of time in milliseconds the response remains validdateExpires- the date to set (if this is not in the future, it is ignored)
-
setDateLastModifiedHeader
public static void setDateLastModifiedHeader(javax.servlet.http.HttpServletResponse res, long dateLastModified)
Sets the "last modified" date header for a given http request.- Parameters:
res- the response to set the "last modified" date header fordateLastModified- the date to set (if this is lower then 0, the current time is set)
-
clear
public void clear()
Clears all data of this controller.
-
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
-
getCmsObject
public CmsObject getCmsObject()
Returns the wrapped CmsObject.- Returns:
- the wrapped CmsObject
-
getCmsResource
public CmsResource getCmsResource()
This method provides access to the top-level CmsResource 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.- Returns:
- the requested top-level CmsFile
-
getCurrentRequest
public CmsFlexRequest getCurrentRequest()
Returns the current flex request.- Returns:
- the current flex request
-
getCurrentResponse
public CmsFlexResponse getCurrentResponse()
Returns the current flex response.- Returns:
- the current flex response
-
getDateExpires
public long getDateExpires()
Returns the combined "expires" date for all resources read during this request.- Returns:
- the combined "expires" date for all resources read during this request
-
getDateLastModified
public long getDateLastModified()
Returns the combined "last modified" date for all resources read during this request.- Returns:
- the combined "last modified" date for all resources read during this request
-
getResponseStackSize
public int getResponseStackSize()
Returns the size of the response stack.- Returns:
- the size of the response stack
-
getThrowable
public java.lang.Throwable getThrowable()
Returns an exception (Throwable) that was caught during inclusion of sub elements, or null if no exceptions where thrown in sub elements.- Returns:
- an exception (Throwable) that was caught during inclusion of sub elements
-
getThrowableResourceUri
public java.lang.String getThrowableResourceUri()
Returns the URI of a VFS resource that caused the exception that was caught during inclusion of sub elements, might return null if no URI information was available for the exception.- Returns:
- the URI of a VFS resource that caused the exception that was caught during inclusion of sub elements
-
getTopRequest
public javax.servlet.http.HttpServletRequest getTopRequest()
Returns the current http request.- Returns:
- the current http request
-
getTopResponse
public javax.servlet.http.HttpServletResponse getTopResponse()
Returns the current http response.- Returns:
- the current http response
-
isEmptyRequestList
public boolean isEmptyRequestList()
Returnstrueif the controller does not yet contain any requests.- Returns:
trueif the controller does not yet contain any requests
-
isForwardMode
public boolean isForwardMode()
Returnstrueif this controller is currently in "forward" mode.- Returns:
trueif this controller is currently in "forward" mode
-
isStreaming
public boolean isStreaming()
Returnstrueif the generated output of the response should be written to the stream directly.- Returns:
trueif the generated output of the response should be written to the stream directly
-
isTop
public boolean isTop()
Returnstrueif this controller was generated as top level controller.If a resource (e.g. a JSP) is processed and it's content is included in another resource, then this will be
false.- Returns:
trueif this controller was generated as top level controller- See Also:
I_CmsResourceLoader.dump(CmsObject, CmsResource, String, java.util.Locale, HttpServletRequest, HttpServletResponse),CmsJspActionElement.getContent(String)
-
pop
public void pop()
Removes the topmost request/response pair from the stack.
-
push
public void push(CmsFlexRequest req, CmsFlexResponse res)
Adds another flex request/response pair to the stack.- Parameters:
req- the request to addres- the response to add
-
removeUncacheableAttributes
public void removeUncacheableAttributes(java.util.Map<java.lang.String,java.lang.Object> attributeMap)
Removes request attributes which shouldn't be cached in flex cache entries from a map.- Parameters:
attributeMap- the map of attributes
-
setForwardMode
public void setForwardMode(boolean value)
Sets the value of the "forward mode" flag.- Parameters:
value- the forward mode to set
-
setThrowable
public java.lang.Throwable setThrowable(java.lang.Throwable throwable, java.lang.String resource)
Sets an exception (Throwable) that was caught during inclusion of sub elements.If another exception is already set in this controller, then the additional exception is ignored.
- Parameters:
throwable- the exception (Throwable) to setresource- the URI of the VFS resource the error occurred on (might benullif unknown)- Returns:
- the exception stored in the controller
-
suspendFlexResponse
public void suspendFlexResponse()
Puts the response in a suspended state.
-
updateDates
public void updateDates(long dateLastModified, long dateExpires)
Updates the "last modified" date and the "expires" date for all resources read during this request with the given values.The currently stored value for "last modified" is only updated with the new value if the new value is either larger (i.e. newer) then the stored value, or if the new value is less then zero, which indicates that the "last modified" optimization can not be used because the element is dynamic.
The stored "expires" value is only updated if the new value is smaller then the stored value.
- Parameters:
dateLastModified- the value to update the "last modified" date withdateExpires- the value to update the "expires" date with
-
-