Search in sources :

Example 71 with JDOMException

use of org.jdom.JDOMException 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 72 with JDOMException

use of org.jdom.JDOMException 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

JDOMException (org.jdom.JDOMException)72 IOException (java.io.IOException)59 Element (org.jdom.Element)46 Document (org.jdom.Document)27 SAXBuilder (org.jdom.input.SAXBuilder)20 File (java.io.File)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 StringReader (java.io.StringReader)9 THashMap (gnu.trove.THashMap)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 InvalidDataException (com.intellij.openapi.util.InvalidDataException)5 Path (java.nio.file.Path)4 Logger (com.intellij.openapi.diagnostic.Logger)3 Project (com.intellij.openapi.project.Project)3 StringWriter (java.io.StringWriter)3 Format (org.jdom.output.Format)3 XMLOutputter (org.jdom.output.XMLOutputter)3