org.opencms.jsp.util
Class CmsJspStatusBean

java.lang.Object
  extended by org.opencms.jsp.CmsJspBean
      extended by org.opencms.jsp.CmsJspActionElement
          extended by org.opencms.jsp.util.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
Version:
$Revision: 1.16 $
Author:
Andreas Zahner

Field Summary
static java.lang.String ERROR_MESSAGE
          Request attribute key for the error message.
static java.lang.String ERROR_REQUEST_URI
          Request attribute key for the error request URI.
static java.lang.String ERROR_SERVLET_NAME
          Request attribute key for the error servlet name.
static java.lang.String ERROR_STATUS_CODE
          Request attribute key for the error status code.
static java.lang.String UNKKNOWN_STATUS_CODE
          Default name for an unknown error status code.
static java.lang.String VFS_FOLDER_HANDLER
          The OpenCms VFS path containing the handler files.
 
Fields inherited from class org.opencms.jsp.CmsJspActionElement
NOT_INITIALIZED
 
Constructor Summary
CmsJspStatusBean()
          Empty constructor, required for every JavaBean.
CmsJspStatusBean(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Constructor, with parameters.
CmsJspStatusBean(javax.servlet.jsp.PageContext context, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.Throwable t)
          Constructor, with parameters.
 
Method Summary
 java.lang.String getErrorMessage()
          Returns the error message.
 java.lang.Throwable getException()
          Returns the exception.
 java.util.Locale getLocale()
          Returns the locale to use for the error page.
protected  java.lang.Object[] getLocalizeParameters()
          Returns the parameter object for localization.
protected  CmsMessages getMessages()
          Returns the initialized messages object to read localized messages from.
 java.lang.String getPageContent(java.lang.String element)
          Returns the processed output of the specified element of an OpenCms page.
 java.lang.String getRequestResourceName()
          Returns the absolute path of the requested resource in the VFS of OpenCms.
 java.lang.String getRequestUri()
          Returns the request Uri.
 java.lang.String getResourceUri(java.lang.String resourceName)
          Returns the full Workplace resource path to the selected resource.
 java.lang.String getServletName()
          Returns the servlet name.
 java.lang.String getSiteRoot()
          Returns the site root of the requested resource.
 java.lang.Integer getStatusCode()
          Returns the status code.
 java.lang.String getStatusCodeMessage()
          Returns the status code message.
 java.lang.String getTemplateUri()
          Returns the URI used for template part inclusion.
 void includeTemplatePart(java.lang.String target, java.lang.String element)
          Include a template part to display on the error page.
 void includeTemplatePart(java.lang.String target, java.lang.String element, java.util.Map parameterMap)
          Include a template part to display on the error page.
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.
 java.lang.String key(java.lang.String keyName)
          Returns the localized resource string for a given message key.
 java.lang.String key(java.lang.String keyName, java.lang.String defaultKeyName)
          Returns the localized resource string for a given message key.
 java.lang.String keyStatus(java.lang.String keyName)
          Returns the localized resource string for a given message key depending on the HTTP status.
protected  void setErrorMessage(java.lang.String errorMessage)
          Sets the error message.
protected  void setException(java.lang.Throwable exception)
          Sets the exception.
protected  void setLocale(java.util.Locale locale)
          Sets the locale to use for the error page.
protected  void setLocalizeParameters(java.lang.Object[] localizeParameters)
          Sets the parameter object for localization.
protected  void setMessages(CmsMessages messages)
          Sets the initialized messages object to read localized messages from.
protected  void setRequestUri(java.lang.String requestUri)
          Sets the request Uri.
protected  void setServletName(java.lang.String servletName)
          Sets the servlet name.
protected  void setSiteRoot(java.lang.String siteRoot)
          Sets the site root of the requested resource.
protected  void setStatusCode(java.lang.Integer statusCode)
          Sets the status code.
protected  void setStatusCodeMessage(java.lang.String statusCodeMessage)
          Sets the status code message.
 void setTemplateUri(java.lang.String templateUri)
          Sets the URI used for template part inclusion.
 boolean showException()
          Returns true if the current user has the "DEVELOPER" role and can view the exception stacktrace.
 
Methods inherited from class org.opencms.jsp.CmsJspActionElement
editable, editable, editable, editableManualClose, editableManualOpen, getContent, getContent, getMessages, getMessages, getMessages, getMessages, getNavigation, img, img, include, include, include, include, include, includeSilent, includeSilent, includeSilent, includeSilent, info, label, link, properties, properties, property, property, property, property, template, template, template, toAbsolute, user
 
Methods inherited from class org.opencms.jsp.CmsJspBean
getCmsObject, getController, getJspContext, getMessage, getRequest, getRequestContext, getResponse, handleException, init, isNotInitialized, isSupressingExceptions, setContentType, setStatus, setSupressingExceptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_MESSAGE

public static final java.lang.String ERROR_MESSAGE
Request attribute key for the error message.

See Also:
Constant Field Values

ERROR_REQUEST_URI

public static final java.lang.String ERROR_REQUEST_URI
Request attribute key for the error request URI.

See Also:
Constant Field Values

ERROR_SERVLET_NAME

public static final java.lang.String ERROR_SERVLET_NAME
Request attribute key for the error servlet name.

See Also:
Constant Field Values

ERROR_STATUS_CODE

public static final java.lang.String ERROR_STATUS_CODE
Request attribute key for the error status code.

See Also:
Constant Field Values

UNKKNOWN_STATUS_CODE

public static final java.lang.String UNKKNOWN_STATUS_CODE
Default name for an unknown error status code.

See Also:
Constant Field Values

VFS_FOLDER_HANDLER

public static final java.lang.String VFS_FOLDER_HANDLER
The OpenCms VFS path containing the handler files.

See Also:
Constant Field Values
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

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 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:

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

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

getLocalizeParameters

protected java.lang.Object[] getLocalizeParameters()
Returns the parameter object for localization.

Returns:
the parameter object for localization
See Also:
for a more detailed object description

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