Class CmsFlexController
- Since:
- 6.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInformation about where to redirect to. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCmsFlexController(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
Modifier and TypeMethodDescriptionvoidaddDateHeader(String name, long date) Method overload from the standard HttpServletResponse API.voidMethod overload from the standard HttpServletResponse API.voidaddIntHeader(String name, int value) Method overload from the standard HttpServletResponse API.voidclear()Clears all data of this controller.Returns the CmsFlexCache instance where all results from this request will be cached in.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.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.Returns the current flex request.Returns the current flex response.longReturns the combined "expires" date for all resources read during this request.longReturns the combined "last modified" date for all resources read during this request.Gets the information about where to redirect to.intReturns the size of the response stack.Returns an exception (Throwable) that was caught during inclusion of sub elements, or null if no exceptions where thrown in sub elements.static ThrowablegetThrowable(javax.servlet.ServletRequest req) Provides access to a root cause Exception that might have occurred in a complex include scenario.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 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.HttpServletRequestReturns the current http request.javax.servlet.http.HttpServletResponseReturns 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.booleanReturnstrueif the controller does not yet contain any requests.booleanReturnstrueif 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.booleanReturnstrueif 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(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(Map<String, Object> attributeMap) Removes request attributes which shouldn't be cached in flex cache entries from a map.voidsetContentType(String contentType) Special method for setting the content type from a JSP in a way that is compatible with both Tomcat and Jetty and also works with the Flex Cache.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.voidsetDateHeader(String name, long date) Method overload from the standard HttpServletResponse API.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.voidMethod overload from the standard HttpServletResponse API.voidsetIntHeader(String name, int value) Method overload from the standard HttpServletResponse API.voidsetRedirectInfo(CmsFlexController.RedirectInfo redirectInfo) Sets the information about where to redirect to.setThrowable(Throwable throwable, String resource) Sets an exception (Throwable) that was caught during inclusion of sub elements.voidPuts 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 Details
-
ATTRIBUTE_NAME
Constant for the controller request attribute name.- See Also:
-
HEADER_OPENCMS_CONTENT_TYPE
Fake HTTP header used to store information about the content type in a CmsFlexResponse. Should never be actually sent to the client.- See Also:
-
-
Constructor Details
-
CmsFlexController
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 Details
-
getCmsObject
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
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
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:
-
getThrowableResourceUri
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:
-
isCmsOnlineRequest
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
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
Tells the flex controller to never cache the given attribute.- Parameters:
attributeName- the attribute which shouldn't be cached
-
removeController
Removes the controller attribute from a request.- Parameters:
req- the request to remove the controller from
-
setController
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 fordateExpires- the date to set (if this is not in the future, it is ignored)maxAge- maximum amount of time in milliseconds the response remains valid
-
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)
-
addDateHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-date-- See Also:
-
addHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-value-- See Also:
-
addIntHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-value-- See Also:
-
clear
Clears all data of this controller. -
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
Returns the wrapped CmsObject.- Returns:
- the wrapped CmsObject
-
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
Returns the current flex request.- Returns:
- the current flex request
-
getCurrentResponse
Returns the current flex response.- Returns:
- the current flex response
-
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
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
-
getRedirectInfo
Gets the information about where to redirect to.- Returns:
- the redirect information
-
getResponseStackSize
Returns the size of the response stack.- Returns:
- the size of the response stack
-
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
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
Returns the current http request.- Returns:
- the current http request
-
getTopResponse
Returns the current http response.- Returns:
- the current http response
-
isEmptyRequestList
Returnstrueif the controller does not yet contain any requests.- Returns:
trueif the controller does not yet contain any requests
-
isForwardMode
Returnstrueif this controller is currently in "forward" mode.- Returns:
trueif this controller is currently in "forward" mode
-
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
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:
-
pop
Removes the topmost request/response pair from the stack. -
push
Adds another flex request/response pair to the stack.- Parameters:
req- the request to addres- the response to add
-
removeUncacheableAttributes
Removes request attributes which shouldn't be cached in flex cache entries from a map.- Parameters:
attributeMap- the map of attributes
-
setContentType
Special method for setting the content type from a JSP in a way that is compatible with both Tomcat and Jetty and also works with the Flex Cache.This is implemented as setting a fake HTTP header which is then translated back to a call to setContentType() in CmsJspLoader.dispatchJsp().
- Parameters:
contentType- the content type to set
-
setDateHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-date-- See Also:
-
setForwardMode
Sets the value of the "forward mode" flag.- Parameters:
value- the forward mode to set
-
setHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-value-- See Also:
-
setIntHeader
Method overload from the standard HttpServletResponse API.The method is added to the controller itself, to automatically have the correct choice for the response to set the header.
- Parameters:
name-value-- See Also:
-
setRedirectInfo
Sets the information about where to redirect to.- Parameters:
redirectInfo- the redirect information
-
setThrowable
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
Puts the response in a suspended state. -
updateDates
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
-