Class CmsJspStatusBean


  • public class CmsJspStatusBean
    extends CmsJspActionElement
    This bean provides methods to generate customized http status error pages, e.g. to handle 404 (not found) errors.

    The JSPs using this bean are placed in the OpenCms VFS folder /system/handler/.

    Since:
    6.0
    • Constructor Detail

      • CmsJspStatusBean

        public CmsJspStatusBean()
        Empty constructor, required for every JavaBean.
      • CmsJspStatusBean

        public CmsJspStatusBean​(javax.servlet.jsp.PageContext context,
                                javax.servlet.http.HttpServletRequest req,
                                javax.servlet.http.HttpServletResponse res)
        Constructor, with parameters.
        Parameters:
        context - the JSP page context object
        req - the JSP request
        res - the JSP response
      • CmsJspStatusBean

        public CmsJspStatusBean​(javax.servlet.jsp.PageContext context,
                                javax.servlet.http.HttpServletRequest req,
                                javax.servlet.http.HttpServletResponse res,
                                java.lang.Throwable t)
        Constructor, with parameters.
        Parameters:
        context - the JSP page context object
        req - the JSP request
        res - the JSP response
        t - the exception that lead to the error
    • Method Detail

      • forwardToErrorPage

        @Deprecated
        public boolean forwardToErrorPage​(java.lang.String rootPath)
        Deprecated.
        will not work for container pages and other pages using cms:include tags
        Tries to forward to the configured error page for the current site root if present.

        Parameters:
        rootPath - the resource to be used as error page
        Returns:
        true if the forward was successful performed, false otherwise
      • getErrorMessage

        public java.lang.String getErrorMessage()
        Returns the error message.

        Returns:
        the error message
      • getException

        public java.lang.Throwable getException()
        Returns the exception.

        Returns:
        the exception
      • getLocale

        public java.util.Locale getLocale()
        Returns the locale to use for the error page.

        Returns:
        the locale to use for the error page
      • getPageContent

        public java.lang.String getPageContent​(java.lang.String element)
        Returns the processed output of the specified element of an OpenCms page.

        The page to get the content from is looked up in the property value "template-elements". If no value is found, the page is read from the "contents/" subfolder of the handler folder.

        For each status code, an individual page can be created by naming it "content${STATUSCODE}.html". If the individual page can not be found, the content is read from "contentunknown.html".

        Parameters:
        element - name of the element
        Returns:
        the processed output of the specified element of an OpenCms page
      • getRequestResourceName

        public java.lang.String getRequestResourceName()
        Returns the absolute path of the requested resource in the VFS of OpenCms.

        Returns:
        the absolute path of the requested resource in the VFS of OpenCms
      • getRequestUri

        public java.lang.String getRequestUri()
        Returns the request Uri.

        Returns:
        the request Uri
      • getResourceUri

        public java.lang.String getResourceUri​(java.lang.String resourceName)
        Returns the full Workplace resource path to the selected resource.

        Parameters:
        resourceName - the name of the resource to get the resource path for
        Returns:
        the full Workplace resource path to the selected resource
      • getServletName

        public java.lang.String getServletName()
        Returns the servlet name.

        Returns:
        the servlet name
      • getSiteRoot

        public java.lang.String getSiteRoot()
        Returns the site root of the requested resource.

        Returns:
        the site root of the requested resource
      • getStatusCode

        public java.lang.Integer getStatusCode()
        Returns the status code.

        Returns:
        the status code
      • getStatusCodeMessage

        public java.lang.String getStatusCodeMessage()
        Returns the status code message.

        Returns:
        the status code message
      • getTemplateUri

        public java.lang.String getTemplateUri()
        Returns the URI used for template part inclusion.

        Returns:
        the URI used for template part inclusion
      • includeTemplatePart

        public void includeTemplatePart​(java.lang.String target,
                                        java.lang.String element)
                                 throws javax.servlet.jsp.JspException
        Include a template part to display on the error page.

        Parameters:
        target - the target uri of the file in the OpenCms VFS (can be relative or absolute)
        element - the element (template selector) to display from the target
        Throws:
        javax.servlet.jsp.JspException - in case there were problems including the target
      • includeTemplatePart

        public void includeTemplatePart​(java.lang.String target,
                                        java.lang.String element,
                                        java.util.Map<java.lang.String,​java.lang.Object> parameterMap)
                                 throws javax.servlet.jsp.JspException
        Include a template part to display on the error page.

        Parameters:
        target - the target uri of the file in the OpenCms VFS (can be relative or absolute)
        element - the element (template selector) to display from the target
        parameterMap - a map of the request parameters
        Throws:
        javax.servlet.jsp.JspException - in case there were problems including the target
      • key

        public java.lang.String key​(java.lang.String keyName)
        Returns the localized resource string for a given message key.

        If the key was not found in the bundle, the return value is "??? " + keyName + " ???".

        The key can use the following parameters for formatting:

        • 0: the HTTP status code
        • 1: the requested URI
        • 2: the generated error message
        • 3: the servlet name
        • 4: the date of the request
        Parameters:
        keyName - the key for the desired string
        Returns:
        the resource string for the given key
      • key

        public java.lang.String key​(java.lang.String keyName,
                                    java.lang.String defaultKeyName)
        Returns the localized resource string for a given message key.

        For a detailed parameter description, see key(String).

        Parameters:
        keyName - the key for the desired string
        defaultKeyName - the default key for the desired string, used if the keyName delivered no resource string
        Returns:
        the resource string for the given key
      • keyStatus

        public java.lang.String keyStatus​(java.lang.String keyName)
        Returns the localized resource string for a given message key depending on the HTTP status.

        Automatically adds a status suffix for the key to get, eg. "keyname" gets the suffix "_404" for a 404 status. For a detailed parameter description, see key(String).

        Parameters:
        keyName - the key for the desired string
        Returns:
        the resource string for the given key
      • logException

        public void logException()
        Writes the exception into the 'opencms.log', if the exception is not null.

      • setTemplateUri

        public void setTemplateUri​(java.lang.String templateUri)
        Sets the URI used for template part inclusion.

        Parameters:
        templateUri - the URI used for template part inclusion
      • showException

        public boolean showException()
        Returns true if the current user has the "DEVELOPER" role and can view the exception stacktrace.

        Returns:
        true if the current user has the "DEVELOPER" role and can view the exception stacktrace
      • getMessages

        protected CmsMessages getMessages()
        Returns the initialized messages object to read localized messages from.

        Returns:
        the initialized messages object to read localized messages from
      • initMembers

        protected void initMembers​(javax.servlet.http.HttpServletRequest req,
                                   java.lang.Throwable t)
        Initializes the members of this bean with the information retrieved from the current request.

        Parameters:
        req - the JSP request
        t - the exception that lead to the error
      • setErrorMessage

        protected void setErrorMessage​(java.lang.String errorMessage)
        Sets the error message.

        Parameters:
        errorMessage - the error message to set
      • setException

        protected void setException​(java.lang.Throwable exception)
        Sets the exception.

        Parameters:
        exception - the exception to set
      • setLocale

        protected void setLocale​(java.util.Locale locale)
        Sets the locale to use for the error page.

        Parameters:
        locale - the locale to use for the error page
      • setLocalizeParameters

        protected void setLocalizeParameters​(java.lang.Object[] localizeParameters)
        Sets the parameter object for localization.

        Parameters:
        localizeParameters - the parameter object for localization
      • setMessages

        protected void setMessages​(CmsMessages messages)
        Sets the initialized messages object to read localized messages from.

        Parameters:
        messages - the initialized messages object to read localized messages from
      • setRequestUri

        protected void setRequestUri​(java.lang.String requestUri)
        Sets the request Uri.

        Parameters:
        requestUri - the request Uri to set
      • setServletName

        protected void setServletName​(java.lang.String servletName)
        Sets the servlet name.

        Parameters:
        servletName - the servlet name to set
      • setSiteRoot

        protected void setSiteRoot​(java.lang.String siteRoot)
        Sets the site root of the requested resource.

        Parameters:
        siteRoot - the site root of the requested resource
      • setStatusCode

        protected void setStatusCode​(java.lang.Integer statusCode)
        Sets the status code.

        Parameters:
        statusCode - the status code to set
      • setStatusCodeMessage

        protected void setStatusCodeMessage​(java.lang.String statusCodeMessage)
        Sets the status code message.

        Parameters:
        statusCodeMessage - the status code message to set