Example usage for org.jdom2 Element isAncestor

List of usage examples for org.jdom2 Element isAncestor

Introduction

In this page you can find the example usage for org.jdom2 Element isAncestor.

Prototype

public boolean isAncestor(final Element element) 

Source Link

Document

Determines if this element is the ancestor of another element.

Usage

From source file:odml.core.Reader.java

License:Open Source License

/**
 * Converts the DOM representation of the metadata-file to the tree like odML structure.
 * //from  www  . ja  v a  2s  .  c  om
 * @param dom - {@link Document}: the document to parse
 */
public void createTree(Document dom) {
    root = new Section();
    if (dom == null) {
        return;
    }
    Element rootElement = dom.getRootElement();
    String odmlVersion = rootElement.getAttribute("version").getValue();
    if (Float.parseFloat(odmlVersion) != 1.0) {
        System.out.println("Can not handle odmlVersion: " + odmlVersion + " stopping further processing!");
        return;
    }

    String author = rootElement.getChildText("author");
    root.setDocumentAuthor(author);
    Date date;
    String temp = rootElement.getChildText("date");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    try {
        date = sdf.parse(temp);
    } catch (Exception e) {
        date = null;
    }
    root.setDocumentDate(date);
    String version = rootElement.getChildText("version");
    root.setDocumentVersion(version);
    URL url = null;
    temp = rootElement.getChildText("repository");
    if (temp != null && !temp.isEmpty()) {
        try {
            url = new URL(temp);
        } catch (Exception e) {
            System.out.println("Reader.parseSection.repository: " + e);
        }
    }
    root.setRepository(url);
    root.setFileUrl(this.fileUrl);

    for (Element domSection : rootElement.getChildren("section")) {
        if (rootElement.isAncestor(domSection)) {
            root.add(parseSection(domSection));
        }
    }
    confirmLinks(root);
}