Example usage for org.jdom2.input SAXBuilder build

List of usage examples for org.jdom2.input SAXBuilder build

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder build.

Prototype

@Override
public Document build(final String systemId) throws JDOMException, IOException 

Source Link

Document

This builds a document from the supplied URI.

Usage

From source file:com.tactfactory.harmony.utils.XMLUtils.java

License:Open Source License

/**
 * Open an XML file.//from   ww w .ja v  a2  s  .  co  m
 * @param fileName The name of the file.
 * @return The openened Document object. Or null if nothing found.
 */
public static Document openXMLFile(final String fileName) {
    Document doc = null;

    // Make engine
    final SAXBuilder builder = new SAXBuilder();
    final File xmlFile = TactFileUtils.makeFile(fileName);

    try {
        // Load XML File
        doc = builder.build(xmlFile);

    } catch (JDOMException e) {
        ConsoleUtils.displayError(e);
    } catch (IOException e) {
        ConsoleUtils.displayError(e);
    }

    return doc;
}

From source file:com.tactfactory.harmony.utils.XMLUtils.java

License:Open Source License

/**
 * Open an XML file.//from  www.j av  a2s.co m
 * @param fileName The name of the file.
 * @return The openened Document object. Or null if nothing found.
 */
public static Document openXML(final String fileName) {
    Document doc = null;

    try {
        // Make engine
        final SAXBuilder builder = new SAXBuilder();
        final File xmlFile = new File(fileName);

        if (!xmlFile.exists()) {
            doc = new Document();
        } else {
            // Load XML File
            doc = builder.build(xmlFile);
        }

    } catch (JDOMException e) {
        ConsoleUtils.displayError(e);
    } catch (IOException e) {
        ConsoleUtils.displayError(e);
    }

    return doc;
}

From source file:com.tactfactory.harmony.utils.XMLUtils.java

License:Open Source License

/**
 * Open a remote XML file.//from   w ww . j  a  v  a2s . c  om
 * @param url The url of the xml file.
 * @return The Element corresponding to the XML.
 */
public static Document getRemoteXML(final String url) {
    Document result = null;
    try {
        SAXBuilder builder = new SAXBuilder();
        result = builder.build(new URL(url));
    } catch (MalformedURLException e) {
        ConsoleUtils.displayError(e);
    } catch (JDOMException e) {
        ConsoleUtils.displayError(e);
    } catch (IOException e) {
        ConsoleUtils.displayError(e);
    }

    return result;
}

From source file:com.thoughtworks.go.config.GoConfigMigration.java

License:Apache License

private int getCurrentSchemaVersion(String content) {
    try {/*  w  w w  .j  av a  2s  . co  m*/
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
        Element root = document.getRootElement();

        String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0"
                : root.getAttributeValue(schemaVersion);
        return Integer.parseInt(currentVersion);
    } catch (Exception e) {
        throw bomb(e);
    }
}

From source file:com.thoughtworks.go.domain.materials.mercurial.HgModificationSplitter.java

License:Apache License

public List<Modification> modifications() {
    try {//from  w w  w  .  j ava 2  s . c  o  m
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new StringReader(output));
        return parseDOMTree(document);
    } catch (Exception e) {
        throw ExceptionUtils.bomb("Unable to parse hg log output: " + result.replaceSecretInfo(output),
                result.smudgedException(e));
    }
}

From source file:com.thoughtworks.go.util.SvnLogXmlParser.java

License:Apache License

public List<Modification> parse(String svnLogOutput, String path, SAXBuilder builder) {
    try {/*from   w  ww .  ja  v a  2 s  .  c o m*/
        Document document = builder.build(new StringReader(svnLogOutput));
        return parseDOMTree(document, path);
    } catch (Exception e) {
        throw bomb("Unable to parse svn log output: " + svnLogOutput, e);
    }
}

From source file:com.thoughtworks.go.util.SvnLogXmlParser.java

License:Apache License

public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) {
    HashMap<String, String> uidToUrlMap = new HashMap<>();
    try {//from  w w w .  j  a  v  a  2s .  com
        Document document = builder.build(new StringReader(output));
        Element root = document.getRootElement();
        List<Element> entries = root.getChildren("entry");
        for (Element entry : entries) {
            uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return uidToUrlMap;
}

From source file:com.thoughtworks.go.util.XmlUtils.java

License:Apache License

private static Document buildXmlDocument(InputStream inputStream, SAXBuilder builder)
        throws JDOMException, IOException {
    XsdErrorTranslator errorHandler = new XsdErrorTranslator();
    builder.setErrorHandler(errorHandler);

    Document cruiseRoot = builder.build(inputStream);
    if (errorHandler.hasValidationError()) {
        throw new XsdValidationException(errorHandler.translate());
    }//  w  w  w  . j a va  2s .com
    return cruiseRoot;
}

From source file:com.thoughtworks.xstream.io.xml.JDom2Driver.java

License:Open Source License

public HierarchicalStreamReader createReader(Reader reader) {
    try {/*from  w  w  w  . ja  v  a  2  s. c  om*/
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(reader);
        return new JDom2Reader(document, getNameCoder());
    } catch (IOException e) {
        throw new StreamException(e);
    } catch (JDOMException e) {
        throw new StreamException(e);
    }
}

From source file:com.thoughtworks.xstream.io.xml.JDom2Driver.java

License:Open Source License

public HierarchicalStreamReader createReader(InputStream in) {
    try {/*w ww  .  j a v  a 2 s . co m*/
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(in);
        return new JDom2Reader(document, getNameCoder());
    } catch (IOException e) {
        throw new StreamException(e);
    } catch (JDOMException e) {
        throw new StreamException(e);
    }
}