📄 cmsjspstatusbean.java
字号:
includeTemplatePart(target, element, null);
}
/**
* Include a template part to display on the error page.<p>
*
* @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
* @param element the element (template selector) to display from the target
* @param parameterMap a map of the request parameters
*
* @throws JspException in case there were problems including the target
*/
public void includeTemplatePart(String target, String element, Map parameterMap) throws JspException {
// store current site root and URI
String currentSiteRoot = getRequestContext().getSiteRoot();
String currentUri = getRequestContext().getUri();
// set the Locale in the request parameter Map
if (parameterMap == null) {
parameterMap = new HashMap(1);
}
parameterMap.put(CmsLocaleManager.PARAMETER_LOCALE, getLocale().toString());
try {
// set site root and URI to display template part correct
getRequestContext().setSiteRoot(getSiteRoot());
getRequestContext().setUri(getTemplateUri());
// include the template part
include(target, element, parameterMap);
} finally {
// reset site root and requested URI to status JSP
getRequestContext().setSiteRoot(currentSiteRoot);
getRequestContext().setUri(currentUri);
}
}
/**
* Returns the localized resource string for a given message key.<p>
*
* If the key was not found in the bundle, the return value is
* <code>"??? " + keyName + " ???"</code>.<p>
*
* The key can use the following parameters for formatting:
* <ul>
* <li>0: the HTTP status code</li>
* <li>1: the requested URI</li>
* <li>2: the generated error message</li>
* <li>3: the servlet name</li>
* <li>4: the date of the request</li>
* </ul>
*
* @param keyName the key for the desired string
* @return the resource string for the given key
*/
public String key(String keyName) {
return key(keyName, null);
}
/**
* Returns the localized resource string for a given message key.<p>
*
* For a detailed parameter description, see {@link CmsJspStatusBean#key(String)}.<p>
*
* @param keyName the key for the desired string
* @param defaultKeyName the default key for the desired string, used if the keyName delivered no resource string
* @return the resource string for the given key
*/
public String key(String keyName, String defaultKeyName) {
String value = getMessages().key(keyName, getLocalizeParameters());
if (value.startsWith(CmsMessages.UNKNOWN_KEY_EXTENSION) && CmsStringUtil.isNotEmpty(defaultKeyName)) {
value = getMessages().key(defaultKeyName, getLocalizeParameters());
}
return CmsStringUtil.escapeHtml(value);
}
/**
* Returns the localized resource string for a given message key depending on the HTTP status.<p>
*
* 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 {@link CmsJspStatusBean#key(String)}.<p>
*
* @param keyName the key for the desired string
* @return the resource string for the given key
*/
public String keyStatus(String keyName) {
keyName += "_";
return key(keyName + getStatusCodeMessage(), keyName + UNKKNOWN_STATUS_CODE);
}
/**
* Sets the URI used for template part inclusion.<p>
*
* @param templateUri the URI used for template part inclusion
*/
public void setTemplateUri(String templateUri) {
m_templateUri = templateUri;
}
/**
* Returns true if the current user has the "DEVELOPER" role and can view the exception stacktrace.<p>
*
* @return true if the current user has the "DEVELOPER" role and can view the exception stacktrace
*/
public boolean showException() {
return getCmsObject().hasRole(CmsRole.DEVELOPER);
}
/**
* Returns the parameter object for localization.<p>
*
* @return the parameter object for localization
*
* @see #key(String) for a more detailed object description
*/
protected Object[] getLocalizeParameters() {
if (m_localizeParameters == null) {
m_localizeParameters = new Object[] {
getStatusCodeMessage(),
getRequestUri(),
getErrorMessage(),
getServletName(),
new Date(getRequestContext().getRequestTime())};
}
return m_localizeParameters;
}
/**
* Returns the initialized messages object to read localized messages from.<p>
*
* @return the initialized messages object to read localized messages from
*/
protected CmsMessages getMessages() {
if (m_messages == null) {
// initialize the localized messages
m_messages = new CmsMessages(Messages.get().getBundleName(), getLocale().toString());
}
return m_messages;
}
/**
* Initializes the members of this bean with the information retrieved from the current request.<p>
*
* @param req the JSP request
* @param t the exception that lead to the error
*/
protected void initMembers(HttpServletRequest req, Throwable t) {
// get the status error attribute values from the request
m_servletName = (String)req.getAttribute(ERROR_SERVLET_NAME);
m_errorMessage = (String)req.getAttribute(ERROR_MESSAGE);
m_requestUri = (String)req.getAttribute(ERROR_REQUEST_URI);
m_statusCode = (Integer)req.getAttribute(ERROR_STATUS_CODE);
if (m_statusCode == null || m_requestUri == null) {
// check if the error request is invoked via Apache/HTTPd ErrorDocument and mod_jk
// to use this you need to add the following to "jk.conf":
// JkEnvVar REDIRECT_URL none
// JkEnvVar REDIRECT_STATUS none
// JkEnvVar REDIRECT_SERVLET_NAME OpenCmsServlet
String jkUri = (String)req.getAttribute("REDIRECT_URL");
String jkStatusCode = (String)req.getAttribute("REDIRECT_STATUS");
String jkServletName = (String)req.getAttribute("REDIRECT_SERVLET_NAME");
try {
if (!"none".equals(jkStatusCode) && !"none".equals(jkUri)) {
m_servletName = jkServletName;
m_requestUri = jkUri;
m_statusCode = new Integer(jkStatusCode);
}
} catch (NullPointerException e) {
// attibute not set, ignore
} catch (NumberFormatException e) {
// status code not a number, ignore
}
}
// get the status code as String
if (m_statusCode != null) {
m_statusCodeMessage = String.valueOf(m_statusCode.intValue());
} else {
m_statusCodeMessage = UNKKNOWN_STATUS_CODE;
}
m_exception = t;
// determine the best locale to use from the users browser settings
CmsAcceptLanguageHeaderParser parser = new CmsAcceptLanguageHeaderParser(
req,
OpenCms.getWorkplaceManager().getDefaultLocale());
List acceptedLocales = parser.getAcceptedLocales();
List workplaceLocales = OpenCms.getWorkplaceManager().getLocales();
m_locale = OpenCms.getLocaleManager().getFirstMatchingLocale(acceptedLocales, workplaceLocales);
if (m_locale == null) {
// no match found - use OpenCms default locale
m_locale = OpenCms.getWorkplaceManager().getDefaultLocale();
}
// store the site root of the request
m_siteRoot = OpenCms.getSiteManager().matchRequest(req).getSiteRoot();
}
/**
* Sets the error message.<p>
*
* @param errorMessage the error message to set
*/
protected void setErrorMessage(String errorMessage) {
m_errorMessage = errorMessage;
}
/**
* Sets the exception.<p>
*
* @param exception the exception to set
*/
protected void setException(Throwable exception) {
m_exception = exception;
}
/**
* Sets the locale to use for the error page.<p>
*
* @param locale the locale to use for the error page
*/
protected void setLocale(Locale locale) {
m_locale = locale;
}
/**
* Sets the parameter object for localization.<p>
*
* @param localizeParameters the parameter object for localization
*/
protected void setLocalizeParameters(Object[] localizeParameters) {
m_localizeParameters = localizeParameters;
}
/**
* Sets the initialized messages object to read localized messages from.<p>
*
* @param messages the initialized messages object to read localized messages from
*/
protected void setMessages(CmsMessages messages) {
m_messages = messages;
}
/**
* Sets the request Uri.<p>
*
* @param requestUri the request Uri to set
*/
protected void setRequestUri(String requestUri) {
m_requestUri = requestUri;
}
/**
* Sets the servlet name.<p>
*
* @param servletName the servlet name to set
*/
protected void setServletName(String servletName) {
m_servletName = servletName;
}
/**
* Sets the site root of the requested resource.<p>
*
* @param siteRoot the site root of the requested resource
*/
protected void setSiteRoot(String siteRoot) {
m_siteRoot = siteRoot;
}
/**
* Sets the status code.<p>
*
* @param statusCode the status code to set
*/
protected void setStatusCode(Integer statusCode) {
m_statusCode = statusCode;
}
/**
* Sets the status code message.<p>
*
* @param statusCodeMessage the status code message to set
*/
protected void setStatusCodeMessage(String statusCodeMessage) {
m_statusCodeMessage = statusCodeMessage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -