use of org.alfresco.web.bean.ErrorBean in project acs-community-packaging by Alfresco.
the class SystemErrorTag method doStartTag.
/**
* @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
*/
public int doStartTag() throws JspException {
// get the error details from the bean, this may be in a portlet
// session or a normal servlet session.
ErrorBean errorBean = null;
if (Application.inPortalServer()) {
errorBean = AlfrescoFacesPortlet.getErrorBean(pageContext.getRequest());
} else {
errorBean = (ErrorBean) pageContext.getSession().getAttribute(ErrorBean.ERROR_BEAN_NAME);
}
if (errorBean == null) {
// if we reach here the error was caught by the declaration in web.xml so
// pull all the information from the request and create the error bean
Throwable error = (Throwable) pageContext.getRequest().getAttribute("javax.servlet.error.exception");
String uri = (String) pageContext.getRequest().getAttribute("javax.servlet.error.request_uri");
// create and store the ErrorBean
errorBean = new ErrorBean();
pageContext.getSession().setAttribute(ErrorBean.ERROR_BEAN_NAME, errorBean);
errorBean.setLastError(error);
errorBean.setReturnPage(uri);
}
Throwable lastError = errorBean.getLastError();
try {
Writer out = pageContext.getOut();
ResourceBundle bundle = Application.getBundle(pageContext.getSession());
String errorMessage;
String errorDetails;
if (lastError == null) {
String messageKey = errorBean.getErrorMessageKey();
errorMessage = bundle.getString(messageKey == null ? MSG_ERROR_NOT_STORED : messageKey);
errorDetails = bundle.getString(MSG_ERROR_NO_STACK_TRACE);
} else {
errorMessage = getLastErrorMessage(lastError, bundle);
errorDetails = getStackTrace(lastError);
}
out.write("<div");
if (this.styleClass != null) {
out.write(" class='");
out.write(this.styleClass);
out.write("'");
}
out.write(">");
out.write(errorMessage);
out.write("</div>");
// work out initial state
boolean hidden = !this.showDetails;
String display = "inline";
String toggleTitle = "Hide";
if (hidden) {
display = "none";
toggleTitle = "Show";
}
// output the script to handle toggling of details
out.write("<script language='JavaScript'>\n");
out.write("var hidden = ");
out.write(Boolean.toString(hidden));
out.write(";\n");
out.write("function toggleDetails() {\n");
out.write("if (hidden) {\n");
out.write("document.getElementById('detailsTitle').innerHTML = '");
out.write(bundle.getString(MSG_HIDE_DETAILS));
out.write("<br/><br/>';\n");
out.write("document.getElementById('details').style.display = 'inline';\n");
out.write("hidden = false;\n");
out.write("} else {\n");
out.write("document.getElementById('detailsTitle').innerHTML = '");
out.write(bundle.getString(MSG_SHOW_DETAILS));
out.write("';\n");
out.write("document.getElementById('details').style.display = 'none';\n");
out.write("hidden = true;\n");
out.write("} } </script>\n");
// output the initial toggle state
out.write("<br/>");
out.write("<a id='detailsTitle' href='javascript:toggleDetails();'>");
out.write(toggleTitle);
out.write(" Details</a>");
out.write("<div style='padding-top:5px;display:");
out.write(display);
out.write("' id='details'");
if (this.detailsStyleClass != null) {
out.write(" class='");
out.write(this.detailsStyleClass);
out.write("'");
}
out.write(">");
out.write(errorDetails);
out.write("</div>");
// output a link to return to the application
out.write("\n<div style='padding-top:16px;'><a href='");
if (Application.inPortalServer()) {
// NOTE: we don't have to specify the page for the portlet, just the VIEW_ID parameter
// being present will cause the current JSF view to be re-displayed
String url = AlfrescoFacesPortlet.getRenderURL(pageContext.getRequest(), Collections.singletonMap("org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID", new String[] { "current-view" }));
out.write(url.toString());
} else {
String returnPage = null;
if (errorBean != null) {
returnPage = errorBean.getReturnPage();
}
if (returnPage == null) {
out.write("javascript:history.back();");
} else {
out.write(returnPage);
}
}
out.write("'>");
out.write(bundle.getString(MSG_RETURN_TO_APP));
out.write("</a></div>");
// this can be used by the user if the app has got into a total mess
if (Application.inPortalServer() == false) {
out.write("\n<div style='padding-top:16px;'><a href='");
out.write(((HttpServletRequest) pageContext.getRequest()).getContextPath());
out.write("'>");
out.write(bundle.getString(MSG_RETURN_HOME));
out.write("</a></div>");
out.write("\n<div style='padding-top:16px;'><a href='");
out.write(((HttpServletRequest) pageContext.getRequest()).getContextPath());
out.write(ExternalAccessServlet.generateExternalURL("logout", null));
out.write("'>");
out.write(bundle.getString(MSG_LOGOUT));
out.write("</a></div>");
}
} catch (IOException ioe) {
throw new JspException(ioe);
} finally {
// clear out the error bean otherwise the next error could be hidden
pageContext.getSession().removeAttribute(ErrorBean.ERROR_BEAN_NAME);
}
return SKIP_BODY;
}
Aggregations