Example usage for org.jdom2 DocType DocType

List of usage examples for org.jdom2 DocType DocType

Introduction

In this page you can find the example usage for org.jdom2 DocType DocType.

Prototype

public DocType(String elementName) 

Source Link

Document

This will create the DocType with the specified element name

Usage

From source file:org.mycore.frontend.servlets.MCRErrorServlet.java

License:Open Source License

/**
 * Builds a jdom document containing the error parameter.
 * /*from   www  .j a v a  2 s  .  co m*/
 * @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));
}

From source file:org.mycore.frontend.servlets.MCRServlet.java

License:Open Source License

/**
 * @deprecated use {@link HttpServletResponse#sendError(int, String)} instead or throw Exception
 */// w  w w .j ava  2  s .  c  o  m
@Deprecated()
protected void generateErrorPage(HttpServletRequest request, HttpServletResponse response, int error,
        String msg, Exception ex, boolean xmlstyle) throws IOException, TransformerException, SAXException {
    LOGGER.error(
            getClass().getName() + ": Error " + error + " occured. The following message was given: " + msg,
            ex);

    String rootname = "mcr_error";
    String style = getProperty(request, "XSL.Style");
    if (style == null || !style.equals("xml")) {
        style = "default";
    }
    Element root = new Element(rootname);
    root.setAttribute("HttpError", Integer.toString(error)).setText(msg);

    Document errorDoc = new Document(root, new DocType(rootname));

    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);

        if (ex instanceof MCRException) {
            if (ex.getCause() instanceof Exception) {
                ex = (Exception) ex.getCause();
            }
        } else {
            ex = null;
        }
    }

    request.setAttribute("XSL.Style", style);

    final String requestAttr = "MCRServlet.generateErrorPage";
    if (!response.isCommitted() && request.getAttribute(requestAttr) == null) {
        response.setStatus(error);
        request.setAttribute(requestAttr, msg);
        LAYOUT_SERVICE.doLayout(request, response, new MCRJDOMContent(errorDoc));
        return;
    } else {
        if (request.getAttribute(requestAttr) != null) {
            LOGGER.warn("Could not send error page. Generating error page failed. The original message:\n"
                    + request.getAttribute(requestAttr));
        } else {
            LOGGER.warn(
                    "Could not send error page. Response allready commited. The following message was given:\n"
                            + msg);
        }
    }
}

From source file:org.olanto.myterm.export.ExportTBXFromDB.java

License:Open Source License

public static void doIt(JTextArea _logArea, String _outFileName, String _resourceName, boolean show) {
    resourceName = _resourceName;//  w w w  .  ja  v  a2s .  co m
    outFileName = _outFileName;
    logArea = _logArea;
    //        init("C:\\MYTERM\\prog\\CoreDBTerm\\src\\org\\olanto\\myterm\\export\\export.properties");
    msg("File Generation TBX\n");
    msg("TBX version: " + dtdName);
    msg("rootName: " + rootName);
    msg("exported file: " + outFileName + "\n");
    initRoot(rootName);
    racine = getRacine();
    DocType doctype = new DocType("TBXBasiccoreStructV02.dtd");
    document = new Document(racine, doctype);
    resource = Queries.getResourceID(resourceName, TermEnum.AutoCreate.NO);
    JdomUtilities.msg("start exporting :");
    racine.addContent(GenerateTBXHeader.setHeader(dtdName, rootName));
    racine.addContent(GenerateEntries.getTermsFromDB());

    if (show)
        showXML(document);
    saveXML(document, outFileName);
    msg("\n end of export");

}