use of org.jdom2.DocType in project mycore by MyCoRe-Org.
the class MCRErrorServlet method buildErrorPage.
/**
* Builds a jdom document containing the error parameter.
*
* @param msg the message of the error
* @param statusCode the http status code
* @param requestURI the uri of the request
* @param exceptionType type of the exception
* @param source source of the error
* @param ex exception which is occured
*
* @return jdom document containing all error parameter
*/
public static Document buildErrorPage(String msg, Integer statusCode, String requestURI, Class<? extends Throwable> exceptionType, String source, Throwable ex) {
String rootname = MCRConfiguration.instance().getString("MCR.Frontend.ErrorPage", "mcr_error");
Element root = new Element(rootname);
root.setAttribute("errorServlet", Boolean.TRUE.toString());
root.setAttribute("space", "preserve", Namespace.XML_NAMESPACE);
if (msg != null) {
root.setText(msg);
}
if (statusCode != null) {
root.setAttribute("HttpError", statusCode.toString());
}
if (requestURI != null) {
root.setAttribute("requestURI", requestURI);
}
if (exceptionType != null) {
root.setAttribute("exceptionType", exceptionType.getName());
}
if (source != null) {
root.setAttribute("source", source);
}
while (ex != null) {
Element exception = new Element("exception");
exception.setAttribute("type", ex.getClass().getName());
Element trace = new Element("trace");
Element message = new Element("message");
trace.setText(MCRException.getStackTraceAsString(ex));
message.setText(ex.getMessage());
exception.addContent(message).addContent(trace);
root.addContent(exception);
ex = ex.getCause();
}
return new Document(root, new DocType(rootname));
}
Aggregations