Class CmsFlexController

java.lang.Object
org.opencms.flex.CmsFlexController

public class CmsFlexController extends Object
Controller for getting access to the CmsObject, should be used as a request attribute.

Since:
6.0.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Information about where to redirect to.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant 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.
    Creates a new controller form the old one, exchanging just the provided OpenCms user context.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 CmsObject
    getCmsObject(javax.servlet.ServletRequest req)
    Returns the wrapped CmsObject form the provided request, or null if 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.
    getController(javax.servlet.ServletRequest req)
    Returns the controller from the given request, or null if the request is not running inside OpenCms.
    Returns the current flex request.
    Returns the current flex response.
    long
    Returns the combined "expires" date for all resources read during this request.
    long
    Returns the combined "last modified" date for all resources read during this request.
    Gets the information about where to redirect to.
    int
    Returns 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 Throwable
    getThrowable(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 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.
    javax.servlet.http.HttpServletRequest
    Returns the current http request.
    javax.servlet.http.HttpServletResponse
    Returns the current http response.
    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.
    static boolean
    isCmsRequest(javax.servlet.ServletRequest req)
    Checks if the provided request is running in OpenCms.
    boolean
    Returns true if the controller does not yet contain any requests.
    boolean
    Returns true if this controller is currently in "forward" mode.
    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.
    boolean
    Returns true if the generated output of the response should be written to the stream directly.
    boolean
    Returns true if this controller was generated as top level controller.
    void
    pop()
    Removes the topmost request/response pair from the stack.
    void
    Adds another flex request/response pair to the stack.
    static void
    Tells the flex controller to never cache the given attribute.
    static void
    removeController(javax.servlet.ServletRequest req)
    Removes the controller attribute from a request.
    void
    Removes request attributes which shouldn't be cached in flex cache entries from a map.
    static void
    setController(javax.servlet.ServletRequest req, CmsFlexController controller)
    Stores the given controller in the given request (using a request attribute).
    static void
    setDateExpiresHeader(javax.servlet.http.HttpServletResponse res, long dateExpires, long maxAge)
    Sets the Expires date header for a given http request.
    static void
    setDateLastModifiedHeader(javax.servlet.http.HttpServletResponse res, long dateLastModified)
    Sets the "last modified" date header for a given http request.
    void
    setForwardMode(boolean value)
    Sets the value of the "forward mode" flag.
    void
    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.
    void
    Puts the response in a suspended state.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 controller
      base - 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 controller
      resource - the file requested
      cache - the instance of the flex cache
      req - the current request
      res - the current response
      streaming - indicates if the response is streaming
      top - indicates if the response is the top response
  • Method Details

    • getCmsObject

      public static CmsObject getCmsObject(javax.servlet.ServletRequest req)
      Returns the wrapped CmsObject form the provided request, or null if 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, or null if the request is not running inside OpenCms.

      Parameters:
      req - the request to get the controller from
      Returns:
      the controller from the given request, or null if the request is not running inside OpenCms
    • getThrowable

      public static 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:
    • getThrowableResourceUri

      public static 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:
    • 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:
      true if the request is running in OpenCms and the current users project is the online project, false otherwise
    • isCmsRequest

      public static boolean isCmsRequest(javax.servlet.ServletRequest req)
      Checks if the provided request is running in OpenCms.

      Parameters:
      req - the current request
      Returns:
      true if the request is running in OpenCms, false otherwise
    • 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 from
      dateLastModified - the date to compare the header with
      Returns:
      true if the header is set and the header date is equal to the provided date
    • registerUncacheableAttribute

      public static void registerUncacheableAttribute(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 in
      controller - the controller to store
    • setDateExpiresHeader

      public static void setDateExpiresHeader(javax.servlet.http.HttpServletResponse res, long dateExpires, long maxAge)
      Sets the Expires date header for a given http request.

      Also sets the cache-control: max-age header 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 the maxAge parameter. If maxAge is 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 for
      maxAge - maximum amount of time in milliseconds the response remains valid
      dateExpires - 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 for
      dateLastModified - 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

      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

      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
    • getRedirectInfo

      Gets the information about where to redirect to.
      Returns:
      the redirect information
    • getResponseStackSize

      public int 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

      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()
      Returns true if the controller does not yet contain any requests.

      Returns:
      true if the controller does not yet contain any requests
    • isForwardMode

      public boolean isForwardMode()
      Returns true if this controller is currently in "forward" mode.

      Returns:
      true if this controller is currently in "forward" mode
    • isStreaming

      public boolean isStreaming()
      Returns true if the generated output of the response should be written to the stream directly.

      Returns:
      true if the generated output of the response should be written to the stream directly
    • isTop

      public boolean isTop()
      Returns true if 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:
      true if this controller was generated as top level controller
      See Also:
    • 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 add
      res - the response to add
    • removeUncacheableAttributes

      public void removeUncacheableAttributes(Map<String,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
    • setRedirectInfo

      public void setRedirectInfo(CmsFlexController.RedirectInfo redirectInfo)
      Sets the information about where to redirect to.
      Parameters:
      redirectInfo - the redirect information
    • setThrowable

      public Throwable setThrowable(Throwable throwable, 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 set
      resource - the URI of the VFS resource the error occurred on (might be null if 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 with
      dateExpires - the value to update the "expires" date with