Search in sources :

Example 31 with DocType

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));
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Aggregations

Document (org.jdom2.Document)26 DocType (org.jdom2.DocType)25 Element (org.jdom2.Element)21 SAXBuilder (org.jdom2.input.SAXBuilder)6 File (java.io.File)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 ParseException (java.text.ParseException)2 Vector (java.util.Vector)2 JLabel (javax.swing.JLabel)2 ProgDebugger (jmri.progdebugger.ProgDebugger)2 lombok.val (lombok.val)2 XMLFilter (plugin.overland.gui.XMLFilter)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 List (java.util.List)1 DataConversionException (org.jdom2.DataConversionException)1