Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren(final String cname) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

Usage

From source file:datalab.upo.ladonspark.controller.Loaddata.java

public List<Host> loadXml(String url, String interfaz) throws JDOMException, IOException, InterruptedException {
    System.out.println("\n\ncargando datos xml\n\n");
    List<Host> hostfind = new ArrayList<>();
    String name = "";
    String ip = "";

    String myIp = findMyIp(interfaz);
    boolean type = false;

    FileReader xmlFile = new FileReader(url + "nmapData.xml");
    System.out.println("pasa file");
    SAXBuilder builder = new SAXBuilder();
    Document document = (Document) builder.build(xmlFile);
    Element rootNode = document.getRootElement();
    /*//w  ww.ja v  a 2  s. c  om
    obtain the host list in XML file
    sacamos la lista de Host del fichero XML
     */
    List<Element> hosts = rootNode.getChildren("host");
    // hosts=hosts.get(0).getChildren("host");

    for (int i = 0; i < hosts.size(); i++) {
        Element host = hosts.get(i);
        /*
        Obtain the hostname list in list host and obtain the address list in self list host
                
         */
        List<Element> hostnames = host.getChildren("hostnames");
        List<Element> address = host.getChildren("address");

        if (hostnames.get(0).getChild("hostname") != null) {
            name = hostnames.get(0).getChild("hostname").getAttributeValue("name");
            ip = address.get(0).getAttributeValue("addr");

        } else {
            name = "unamed";
            ip = address.get(0).getAttributeValue("addr");
        }
        if (ip.equals(myIp)) {
            type = true;
        } else {
            type = false;
        }
        hostfind.add(new Host(name, ip, type));
    }
    hostfind.remove(hostfind.get(0));
    this.setHostfind(hostfind);
    return hostfind;
}

From source file:dblp.xml.DBLPParserFirstSchema.java

private void extractElements(Element root, final String type) {
    try {/*w w  w .  jav a2s  . c o  m*/
        //            System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
        List<Element> nList = root.getChildren(type);
        //        System.out.println(nList);
        System.out.println(type + " " + nList.size());
        int index = 0;
        int ignore = 0;
        final Map<Integer, String> filteredConfs = readNodeFile(conf_filter_path);
        Set<String> filteredConfsSet = new HashSet<>();
        filteredConfsSet.addAll(filteredConfs.values());
        for (Element eElement : nList) {
            String booktitle = eElement.getChild("booktitle").getText();
            //TODO: should comment out, now it doesn't filter conferences
            if (!filteredConfsSet.contains(booktitle)) {
                ignore++;
                continue;
            }
            String year = eElement.getChild("year").getText();
            int year_int = Integer.parseInt(year.trim());
            if (year_int < year_threshold) {
                ignore++;
                continue;
            }
            index++;
            if (index % 100 == 0) {
                System.out.println("Node#: " + index + " Ignore#:" + ignore);
            }
            String title = eElement.getChild("title").getText();
            if (titleSet.contains(title)) {
                ignore++;
                continue;
            }
            titleSet.add(title);
            int titleId = titlesCollection.get(title);
            int yearId = yearsCollection.get(year);
            int confId = confsCollection.get(booktitle);
            title_conf_writer.write(titleId + " " + confId + "\n");
            title_year_writer.write(titleId + " " + yearId + "\n");
            final List<Element> authors = eElement.getChildren("author");
            for (Element author : authors) {
                String author_str = author.getText();
                int authorId = authorsCollection.get(author_str);
                title_author_writer.write(titleId + " " + authorId + "\n");
            }

        }
        title_author_writer.close();
        title_conf_writer.close();
        title_year_writer.close();
    } catch (IOException ex) {
        Logger.getLogger(DBLPParserFirstSchema.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:dblp.xml.DBLPParserSecondSchema.java

private void extractElements(Element root, final String type) {
    try {/*  w  ww  . j av  a 2 s . c o m*/
        List<Element> nList = root.getChildren(type);

        System.out.println(type + " " + nList.size());
        int index = 0;
        int ignore = 0;
        final Map<Integer, String> filteredConfs = readNodeFile(conf_filter_path);
        Set<String> filteredConfsSet = new HashSet<>();
        filteredConfsSet.addAll(filteredConfs.values());
        for (Element eElement : nList) {
            String booktitle = eElement.getChild("booktitle").getText();
            if (!filteredConfsSet.contains(booktitle)) {
                ignore++;
                continue;
            }
            String year = eElement.getChild("year").getText();
            int year_int = Integer.parseInt(year.trim());
            if (year_int < year_threshold) {
                ignore++;
                continue;
            }
            index++;
            if (index % 100 == 0) {
                System.out.println("Node#: " + index + " Ignore#:" + ignore);
            }
            String title = eElement.getChild("title").getText();
            int titleId = titlesCollection.get(title);
            int confId = confsCollection.get(booktitle);
            String yearConf = year + " " + booktitle;
            int yearConfId = yearConfsCollection.get(yearConf);
            conf_year_writer.write(confId + " " + yearConfId + "\n");
            title_year_writer.write(titleId + " " + yearConfId + "\n");
            final List<Element> authors = eElement.getChildren("author");
            for (Element author : authors) {
                String author_str = author.getText();
                int authorId = authorsCollection.get(author_str);
                title_author_writer.write(titleId + " " + authorId + "\n");
                author_conf_writer.write(authorId + " " + confId + "\n");
            }

        }
        title_author_writer.close();
        author_conf_writer.close();
        title_year_writer.close();
        conf_year_writer.close();
    } catch (IOException ex) {
        Logger.getLogger(DBLPParserSecondSchema.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:dblp.xml.DBLPParserThirdSchema.java

private void extractElements(Element root, final String type) {
    try {/*from  ww  w.  j  a  va  2  s. c o  m*/

        //            System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
        List<Element> nList = root.getChildren(type);
        //        System.out.println(nList);
        System.out.println(type + " " + nList.size());
        int index = 0;
        int ignore = 0;
        final Map<Integer, String> filteredConfs = readNodeFile(conf_filter_path);
        Set<String> filteredConfsSet = new HashSet<>();
        filteredConfsSet.addAll(filteredConfs.values());
        for (Element eElement : nList) {
            String booktitle = eElement.getChild("booktitle").getText();
            if (!filteredConfsSet.contains(booktitle)) {
                ignore++;
                continue;
            }
            String year = eElement.getChild("year").getText();
            int year_int = Integer.parseInt(year.trim());
            if (year_int < year_threshold) {
                ignore++;
                continue;
            }
            index++;
            if (index % 100 == 0) {
                System.out.println("Node#: " + index + " Ignore#:" + ignore);
            }
            String title = eElement.getChild("title").getText();
            int titleId = titlesCollection.get(title);
            int confId = confsCollection.get(booktitle);
            String yearConf = year + " " + booktitle;
            int yearConfId = yearConfsCollection.get(yearConf);
            title_conf_writer.write(titleId + " " + confId + "\n");
            conf_year_writer.write(confId + " " + yearConfId + "\n");
            final List<Element> authors = eElement.getChildren("author");
            for (Element author : authors) {
                String author_str = author.getText();
                int authorId = authorsCollection.get(author_str);
                title_author_writer.write(titleId + " " + authorId + "\n");
            }
        }
        title_author_writer.close();
        title_conf_writer.close();
        conf_year_writer.close();
    } catch (IOException ex) {
        Logger.getLogger(DBLPParserThirdSchema.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.andrena.tools.macker.rule.RuleSetBuilder.java

License:Open Source License

private Collection<Element> getChildren(final Element elem, final String tagName) {
    return elem.getChildren(tagName);
}

From source file:de.bund.bfr.knime.pmm.extendedtable.Model1Metadata.java

License:Open Source License

private void parseElement(Element rootElement) {

    Element agentElement = rootElement.getChild(Model1AgentXml.ELEMENT_AGENT);
    if (agentElement != null) {
        agentXml = new Model1AgentXml(agentElement);
    }/*from   w  w  w .  j ava 2 s  .  com*/

    Element matrixElement = rootElement.getChild(Model1MatrixXml.ELEMENT_MATRIX);
    if (matrixElement != null) {
        matrixXml = new Model1MatrixXml(matrixElement);
    }

    for (Element literatureElement : rootElement.getChildren(MLiteratureItem.ELEMENT_LITERATURE)) {
        modelLiteratureItems.add(new MLiteratureItem(literatureElement));
    }

    for (Element literatureElement : rootElement.getChildren(EMLiteratureItem.ELEMENT_LITERATURE)) {
        estimatedModelLiteratureItems.add(new EMLiteratureItem(literatureElement));
    }
}

From source file:de.bund.bfr.knime.pmm.extendedtable.Model2Metadata.java

License:Open Source License

private void parseElement(Element rootElement) {

    Element agentElement = rootElement.getChild(Model2AgentXml.ELEMENT_AGENT);
    if (agentElement != null) {
        agentXml = new Model2AgentXml(agentElement);
    }/*from ww  w . j a  v a 2  s . c o m*/

    Element matrixElement = rootElement.getChild(Model2MatrixXml.ELEMENT_MATRIX);
    if (matrixElement != null) {
        matrixXml = new Model2MatrixXml(matrixElement);
    }

    for (Element literatureElement : rootElement.getChildren(MLiteratureItem.ELEMENT_LITERATURE)) {
        modelLiteratureItems.add(new MLiteratureItem(literatureElement));
    }

    for (Element literatureElement : rootElement.getChildren(EMLiteratureItem.ELEMENT_LITERATURE)) {
        estimatedModelLiteratureItems.add(new EMLiteratureItem(literatureElement));
    }
}

From source file:de.bund.bfr.knime.pmm.extendedtable.TimeSeriesMetadata.java

License:Open Source License

private void parseElement(Element rootElement) {

    Element agentElement = rootElement.getChild(AgentXml.ELEMENT_AGENT);
    if (agentElement != null) {
        agentXml = new MDAgentXml(agentElement);
    }// w  w  w .  ja v  a  2s . com

    Element matrixElement = rootElement.getChild(MatrixXml.ELEMENT_MATRIX);
    if (matrixElement != null) {
        matrixXml = new MDMatrixXml(matrixElement);
    }

    for (Element literatureElement : rootElement.getChildren(MDLiteratureItem.ELEMENT_LITERATURE)) {
        literatureItems.add(new MDLiteratureItem(literatureElement));
    }
}

From source file:de.bund.bfr.pmfml.file.PMFMetadataNode.java

License:Open Source License

public PMFMetadataNode(final Element node) {
    this.node = node;

    modelType = ModelType.valueOf(node.getChildText(MODEL_TYPE_TAG));
    final List<Element> masterFileElements = node.getChildren(MASTER_FILE_TAG);
    masterFiles = masterFileElements.stream().map(Element::getText).collect(Collectors.toSet());
}

From source file:de.danielluedecke.zettelkasten.database.DesktopData.java

License:Open Source License

/**
 * This methods checks whether a given desktop "nr" has any child-elements (i.e. bullets)
 * or not./*from  w w  w.  ja  va2 s .c o m*/
 * 
 * @param nr the desktop which should be checked for children/bullets
 * @return {@code true} if the desktop has any bullets (children, elements), false otherwise
 */
public boolean desktopHasBullets(int nr) {
    // get the requested desktop
    Element e = getDesktopElement(nr);
    if (e != null) {
        // retrieve the list of all bullet-children
        List<Element> l = e.getChildren(ELEMENT_BULLET);
        // return true if we have any bullets...
        return (!l.isEmpty());
    }
    return false;
}