List of usage examples for org.jdom2 Element isAncestor
public boolean isAncestor(final Element element)
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); }