Class CmsJspStatusBean


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
  • Field Details

  • Constructor Details

    • 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, 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 Details

    • forwardToErrorPage

      @Deprecated public boolean forwardToErrorPage(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

      Returns the error message.

      Returns:
      the error message
    • getException

      Returns the exception.

      Returns:
      the exception
    • getLocale

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

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

      public String getPageContent(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

      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

      Returns the request Uri.

      Returns:
      the request Uri
    • getResourceUri

      public String getResourceUri(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

      Returns the servlet name.

      Returns:
      the servlet name
    • getSiteRoot

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

      Returns:
      the site root of the requested resource
    • getStatusCode

      Returns the status code.

      Returns:
      the status code
    • getStatusCodeMessage

      Returns the status code message.

      Returns:
      the status code message
    • getTemplateUri

      Returns the URI used for template part inclusion.

      Returns:
      the URI used for template part inclusion
    • includeTemplatePart

      public void includeTemplatePart(String target, 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(String target, String element, Map<String,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 String key(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 String key(String keyName, 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 String keyStatus(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(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
    • getLocalizeParameters

      Returns the parameter object for localization.

      Returns:
      the parameter object for localization
      See Also:
    • 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, 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(String errorMessage)
      Sets the error message.

      Parameters:
      errorMessage - the error message to set
    • setException

      protected void setException(Throwable exception)
      Sets the exception.

      Parameters:
      exception - the exception to set
    • setLocale

      protected void setLocale(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(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(String requestUri)
      Sets the request Uri.

      Parameters:
      requestUri - the request Uri to set
    • setServletName

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

      Parameters:
      servletName - the servlet name to set
    • setSiteRoot

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

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

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

      Parameters:
      statusCode - the status code to set
    • setStatusCodeMessage

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

      Parameters:
      statusCodeMessage - the status code message to set