Search in sources :

Example 61 with SAXBuilder

use of org.jdom.input.SAXBuilder in project beast-mcmc by beast-dev.

the class AbstractPolygon2D method readKMLFile.

public static List<AbstractPolygon2D> readKMLFile(String fileName) {
    List<AbstractPolygon2D> polygons = new ArrayList<AbstractPolygon2D>();
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.setValidation(false);
        builder.setIgnoringElementContentWhitespace(true);
        Document doc = builder.build(new File(fileName));
        Element root = doc.getRootElement();
        if (!root.getName().equalsIgnoreCase("KML"))
            throw new RuntimeException("Not a KML file");
        readKMLElement(root, polygons);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JDOMException e) {
        e.printStackTrace();
    }
    return polygons;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 62 with SAXBuilder

use of org.jdom.input.SAXBuilder in project cas by apereo.

the class AbstractSamlObjectBuilder method constructDocumentFromXml.

/**
 * Construct document from xml string.
 *
 * @param xmlString the xml string
 * @return the document
 */
public static Document constructDocumentFromXml(final String xmlString) {
    try {
        final SAXBuilder builder = new SAXBuilder();
        builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        return builder.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
    } catch (final Exception e) {
        return null;
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 63 with SAXBuilder

use of org.jdom.input.SAXBuilder in project vcell by virtualcell.

the class XmlUtil method readXML.

public static Document readXML(File file) throws RuntimeException {
    SAXBuilder builder = new SAXBuilder(false);
    Document sDoc = null;
    GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
    builder.setErrorHandler(errorHandler);
    try {
        sDoc = builder.build(file);
        // Element root = null;
        // root = sDoc.getRootElement();
        // flush/replace previous error log with every read.
        String errorHandlerLog = errorHandler.getErrorLog();
        if (errorHandlerLog.length() > 0) {
            System.out.println(errorHandlerLog);
            XmlUtil.errorLog = errorHandlerLog;
        } else {
            XmlUtil.errorLog = "";
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new RuntimeException("source document is not well-formed\n" + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unable to read source document\n" + e.getMessage());
    }
    return sDoc;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 64 with SAXBuilder

use of org.jdom.input.SAXBuilder in project vcell by virtualcell.

the class XmlUtil method readXML.

// useful for the translators.
public static Document readXML(Reader reader, String schemaLocation, String parserClass, String schemaLocationPropName) throws RuntimeException {
    SAXBuilder builder = null;
    Document sDoc = null;
    GenericXMLErrorHandler errorHandler = new GenericXMLErrorHandler();
    try {
        if (schemaLocation != null && schemaLocation.length() > 0) {
            // ignores the parserClass, since xerces is the only validating parser we have
            builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
            builder.setFeature("http://xml.org/sax/features/validation", true);
            builder.setFeature("http://apache.org/xml/features/validation/schema", true);
            builder.setErrorHandler(errorHandler);
            builder.setProperty(schemaLocationPropName, schemaLocation);
        } else {
            // ignore schemaLocationPropName
            if (parserClass == null) {
                // not necessarily 'xerces'
                builder = new SAXBuilder(false);
            } else {
                builder = new SAXBuilder(parserClass, false);
            }
            builder.setErrorHandler(errorHandler);
        }
        sDoc = builder.build(reader);
        // ----- Element root = null;
        // ----- root = sDoc.getRootElement();
        // flush/replace previous error log with every read.
        String errorHandlerLog = errorHandler.getErrorLog();
        if (errorHandlerLog.length() > 0) {
            System.out.println(errorHandlerLog);
            XmlUtil.errorLog = errorHandlerLog;
        } else {
            XmlUtil.errorLog = "";
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new RuntimeException("source document is not well-formed\n" + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unable to read source document\n" + e.getMessage());
    }
    return sDoc;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 65 with SAXBuilder

use of org.jdom.input.SAXBuilder in project vcell by virtualcell.

the class SBMLUtils method readXML.

public static Element readXML(Reader reader) throws IOException, SbmlException {
    try {
        SAXBuilder builder = new SAXBuilder(false);
        Document sDoc = builder.build(reader);
        Element root = sDoc.getRootElement();
        return root;
    } catch (JDOMException e) {
        e.printStackTrace(System.out);
        throw new SbmlException(e.getMessage());
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)68 Document (org.jdom.Document)51 Element (org.jdom.Element)47 IOException (java.io.IOException)27 JDOMException (org.jdom.JDOMException)24 InputStream (java.io.InputStream)18 StringReader (java.io.StringReader)13 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XPath (org.jdom.xpath.XPath)9 File (java.io.File)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 XMLOutputter (org.jdom.output.XMLOutputter)5 Nullable (org.jetbrains.annotations.Nullable)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PostMethod (org.apache.commons.httpclient.methods.PostMethod)4 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)4 Format (org.jdom.output.Format)4 NotNull (org.jetbrains.annotations.NotNull)4 Logger (com.intellij.openapi.diagnostic.Logger)3