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:odml.core.Reader.java

License:Open Source License

/**
 * Parses the xml file and creates the DOM representation of it.
 * @param stream - an {@link java.io.InputStream}
 * @return Document - returns the Document (dom) representation of the xml-file or null if an error occurred.
 *//*  w ww .  j  a v a 2  s . c o  m*/
private Document parseXML(InputStream stream) {
    if (stream == null) {
        return null;
    }
    try {
        SAXBuilder builder = new SAXBuilder();
        return builder.build(stream);
    } catch (IOException ioe) {
        System.out.println("Parsing failed! " + ioe.getMessage());
        return null;
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return null;
    }
}

From source file:odml.core.Reader.java

License:Open Source License

/**
 * Validates the the metadata xml-file against a schema and returns true if the file is valid or false if validation
 * fails.//from  ww  w. j a va2 s. co  m
 * @param stream - the input stream.
 * @return - boolean true or false if validation succeeded or failed, respectively.
 */
private boolean validateXML(InputStream stream) {
    for (URL schemaLocation : schemaLocations) {
        try {
            File xsdfile = new File("schema.xsd");
            XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(xsdfile);
            SAXBuilder builder = new SAXBuilder(schemafac);
            Document validdoc = builder.build(stream);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }
    }
    return true;
}

From source file:open.dolphin.adm10.rest.AbstractResource.java

/**
* OpenDolphin? textPane ?//w  w  w.  j  ava 2s .c  o m
* @param sb  content??????StringBuilder
* @param xml textPane 
*/
protected void renderPane(StringBuilder sb, String xml) {

    debug(xml);

    SAXBuilder docBuilder = new SAXBuilder();

    try {
        StringReader sr = new StringReader(xml);
        Document doc = docBuilder.build(new BufferedReader(sr));
        Element root = doc.getRootElement();

        writeChildren(sb, root);

    } catch (JDOMException e) {
        e.printStackTrace(System.err);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:open.dolphin.impl.mml.MMLHelper23.java

/**
 * soaSpec ?? pSpec? xhtml ?????/*  w w  w.  j ava 2s. co  m*/
 */
private void parse(String spec) {

    try {
        BufferedReader reader = new BufferedReader(new StringReader(spec));
        SAXBuilder docBuilder = new SAXBuilder();
        Document doc = docBuilder.build(reader);
        Element root = doc.getRootElement();
        debug(root.toString());
        parseChildren(root);
        reader.close();

    } catch (JDOMException | IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:open.dolphin.message.MMLHelper.java

/**
 * soaSpec ?? pSpec? xhtml ?????/*  w w w  .  ja v  a  2 s  .  co  m*/
 */
private void parse(String spec) {

    try {
        try (BufferedReader reader = new BufferedReader(new StringReader(spec))) {
            SAXBuilder docBuilder = new SAXBuilder();
            Document doc = docBuilder.build(reader);
            Element root = doc.getRootElement();
            debug(root.toString());
            parseChildren(root);
        }

    } catch (IOException | JDOMException e) {
        e.printStackTrace(System.err);
    }
}

From source file:open.dolphin.msg.MMLHelper.java

/**
 * soaSpec ?? pSpec? xhtml ?????//from  w w  w . jav a2  s. c o m
 */
private void parse(String spec) {

    try {
        BufferedReader reader = new BufferedReader(new StringReader(spec));
        SAXBuilder docBuilder = new SAXBuilder();
        Document doc = docBuilder.build(reader);
        Element root = doc.getRootElement();
        debug(root.toString());
        parseChildren(root);
        reader.close();

    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:org.ambientdynamix.contextplugins.foaf.FoafPluginRuntime.java

License:Apache License

public static void updateFoafFile() {
    String foafurl = settings.get(Constants.FOAFURL);
    foafurl = "http://galileo1.zapto.org/tvluke.rdf";
    final SAXBuilder builder = new SAXBuilder();
    try {/*from   www  . j  av  a2  s.co  m*/
        Document doc = builder.build(foafurl);
        Element root = doc.getRootElement();
        List<Element> children = root.getChildren();
        Iterator<Element> childrenIterator = children.iterator();
        while (childrenIterator.hasNext()) {
            Element child = childrenIterator.next();
            List<Element> grandchildren = child.getChildren();
            Iterator<Element> grandchildrenIterator = grandchildren.iterator();
            while (grandchildrenIterator.hasNext()) {
                Element grandchild = grandchildrenIterator.next();
                if (grandchild.getName().equals("foaf:name")) {
                    foafname = grandchild.getText();
                }
            }
        }
    } catch (Exception e) {

    }
}