org.jdom2.DocType Java Examples

The following examples show how to use org.jdom2.DocType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCRErrorServlet.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 = MCRConfiguration2.getString("MCR.Frontend.ErrorPage").orElse("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));
}
 
Example #2
Source File: MCRXMLHelper.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
public static boolean equivalent(DocType d1, DocType d2) {
    boolean equals = d1.getPublicID().equals(d2.getPublicID()) && d1.getSystemID().equals(d2.getSystemID());
    if (!equals && LOGGER.isDebugEnabled()) {
        LOGGER.debug("DocType differs \"{}\"!=\"{}\"", d1, d2);
    }
    return equals;
}
 
Example #3
Source File: MCRXMLHelper.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
public static boolean equivalentContent(List<Content> l1, List<Content> l2) {
    if (l1.size() != l2.size()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Number of content list elements differ {}!={}", l1.size(), l2.size());
        }
        return false;
    }
    boolean result = true;
    Iterator<Content> i1 = l1.iterator();
    Iterator<Content> i2 = l2.iterator();
    while (result && i1.hasNext() && i2.hasNext()) {
        Object o1 = i1.next();
        Object o2 = i2.next();
        if (o1 instanceof Element && o2 instanceof Element) {
            result = equivalent((Element) o1, (Element) o2);
        } else if (o1 instanceof Text && o2 instanceof Text) {
            result = equivalent((Text) o1, (Text) o2);
        } else if (o1 instanceof Comment && o2 instanceof Comment) {
            result = equivalent((Comment) o1, (Comment) o2);
        } else if (o1 instanceof ProcessingInstruction && o2 instanceof ProcessingInstruction) {
            result = equivalent((ProcessingInstruction) o1, (ProcessingInstruction) o2);
        } else if (o1 instanceof DocType && o2 instanceof DocType) {
            result = equivalent((DocType) o1, (DocType) o2);
        } else {
            result = false;
        }
    }
    return result;
}
 
Example #4
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void loadData(File path)
{
	if (path.isDirectory())
	{
		File[] dataFiles = path.listFiles(new XMLFilter());
		SAXBuilder builder = new SAXBuilder();
		GeneratorDtdResolver resolver = new GeneratorDtdResolver(path);
		builder.setEntityResolver(resolver);

		for (File dataFile : dataFiles)
		{
			try
			{
				URL url = dataFile.toURI().toURL();
				Document nameSet = builder.build(url);
				DocType dt = nameSet.getDocType();

				if (dt.getElementName().equals("GENERATOR"))
				{
					loadFromDocument(nameSet);
				}
			}
			catch (Exception e)
			{
				Logging.errorPrint(e.getMessage(), e);
				JOptionPane.showMessageDialog(this, "XML Error with file " + dataFile.getName());
			}
		}

		loadDropdowns();
	}
	else
	{
		JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath());
	}
}
 
Example #5
Source File: NameGenPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void loadData(File path)
{
	if (path.isDirectory())
	{
		File[] dataFiles = path.listFiles(new XMLFilter());
		SAXBuilder builder = new SAXBuilder();
		GeneratorDtdResolver resolver = new GeneratorDtdResolver(path);
		builder.setEntityResolver(resolver);

		for (File dataFile : dataFiles)
		{
			try
			{
				URL url = dataFile.toURI().toURL();
				Document nameSet = builder.build(url);
				DocType dt = nameSet.getDocType();

				if (dt.getElementName().equals("GENERATOR"))
				{
					loadFromDocument(nameSet);
				}
			}
			catch (Exception e)
			{
				Logging.errorPrint(e.getMessage(), e);
				JOptionPane.showMessageDialog(this, "XML Error with file " + dataFile.getName());
			}
		}

		loadDropdowns();
	}
	else
	{
		JOptionPane.showMessageDialog(this, "No data files in directory " + path.getPath());
	}
}
 
Example #6
Source File: RSS091NetscapeParser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isMyType(final Document document) {

    final Element rssRoot = document.getRootElement();
    final String name = rssRoot.getName();
    final Attribute version = rssRoot.getAttribute("version");
    final DocType docType = document.getDocType();

    return name.equals(ELEMENT_NAME) && version != null && version.getValue().equals(getRSSVersion()) && docType != null
            && ELEMENT_NAME.equals(docType.getElementName()) && PUBLIC_ID.equals(docType.getPublicID()) && SYSTEM_ID.equals(docType.getSystemID());

}
 
Example #7
Source File: RSS091NetscapeGenerator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected Document createDocument(final Element root) {
    final Document doc = new Document(root);
    final DocType docType = new DocType(RSS091NetscapeParser.ELEMENT_NAME, RSS091NetscapeParser.PUBLIC_ID, RSS091NetscapeParser.SYSTEM_ID);
    doc.setDocType(docType);
    return doc;
}
 
Example #8
Source File: MyCoReWebPageProvider.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
public MyCoReWebPageProvider() {
    this.xml = new Document();
    this.xml.setDocType(new DocType(XML_MYCORE_WEBPAGE));
    this.xml.setRootElement(new Element(XML_MYCORE_WEBPAGE));
}