Search in sources :

Example 1 with LocatedJDOMFactory

use of org.jdom2.located.LocatedJDOMFactory in project mule-migration-assistant by mulesoft.

the class XmlDslUtils method generateDocument.

/**
 * Return JDOM document from a file path.
 *
 * @param filePath the path of the file
 * @return the jdom document.
 */
public static Document generateDocument(Path filePath) throws JDOMException, IOException {
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setJDOMFactory(new LocatedJDOMFactory());
    return saxBuilder.build(filePath.toFile());
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LocatedJDOMFactory(org.jdom2.located.LocatedJDOMFactory)

Example 2 with LocatedJDOMFactory

use of org.jdom2.located.LocatedJDOMFactory in project qpp-conversion-tool by CMSgov.

the class XmlUtils method parseXmlStream.

/**
 * Parses a stream of XML into a tree of XML elements.
 *
 * @param xmlStream The XML.
 * @return The root element of the XML tree.
 * @throws XmlException When a failure to parse the XML.
 */
public static Element parseXmlStream(InputStream xmlStream) {
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        saxBuilder.setFeature(DISALLOW_DTD, true);
        saxBuilder.setFeature(EXT_GENERAL_ENTITIES, false);
        saxBuilder.setFeature(EXT_PARAM_ENTITIES, false);
        saxBuilder.setJDOMFactory(new LocatedJDOMFactory());
        return saxBuilder.build(xmlStream).getRootElement();
    } catch (JDOMException | IOException e) {
        throw new XmlException("Failed to process XML String into DOM Element", e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LocatedJDOMFactory(org.jdom2.located.LocatedJDOMFactory) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException)

Example 3 with LocatedJDOMFactory

use of org.jdom2.located.LocatedJDOMFactory in project jts by locationtech.

the class TestReader method createTestRun.

public TestRun createTestRun(File testFile, int runIndex) {
    try {
        SAXBuilder builder = new SAXBuilder();
        builder.setJDOMFactory(new LocatedJDOMFactory());
        Document document = builder.build(new FileInputStream(testFile));
        Element runElement = document.getRootElement();
        if (!runElement.getName().equalsIgnoreCase("run")) {
            throw new TestParseException("Expected <run> but encountered <" + runElement.getName() + ">");
        }
        return parseTestRun(runElement, testFile, runIndex);
    } catch (Exception e) {
        parsingProblems.add("An exception occurred while parsing " + testFile + ": " + e.toString());
        return null;
    }
}
Also used : LocatedJDOMFactory(org.jdom2.located.LocatedJDOMFactory) LocatedElement(org.jdom2.located.LocatedElement)

Example 4 with LocatedJDOMFactory

use of org.jdom2.located.LocatedJDOMFactory in project mule-migration-assistant by mulesoft.

the class ReportEntryModel method setElementLocation.

public void setElementLocation() throws Exception {
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        saxBuilder.setJDOMFactory(new LocatedJDOMFactory());
        if (filePath != null) {
            Document document = saxBuilder.build(Paths.get(filePath).toFile());
            setElementLocation(document);
        }
    } catch (Exception ex) {
        throw new MigrationJobException("Failed to obtain new element location.", ex);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LocatedJDOMFactory(org.jdom2.located.LocatedJDOMFactory) MigrationJobException(com.mulesoft.tools.migration.engine.exception.MigrationJobException) Document(org.jdom2.Document) URISyntaxException(java.net.URISyntaxException) MigrationJobException(com.mulesoft.tools.migration.engine.exception.MigrationJobException) IOException(java.io.IOException)

Aggregations

LocatedJDOMFactory (org.jdom2.located.LocatedJDOMFactory)4 SAXBuilder (org.jdom2.input.SAXBuilder)3 IOException (java.io.IOException)2 MigrationJobException (com.mulesoft.tools.migration.engine.exception.MigrationJobException)1 URISyntaxException (java.net.URISyntaxException)1 Document (org.jdom2.Document)1 JDOMException (org.jdom2.JDOMException)1 LocatedElement (org.jdom2.located.LocatedElement)1