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() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

From source file:cz.pecina.retro.cpu.Device.java

License:Open Source License

/**
 * Loads a representation of the {@code Device} from 
 * a JDOM {@code Element}./*from   ww  w  . jav a  2 s .com*/
 * <p>
 * Note: The current implementation ignores devices the computer
 * does not have.  This is a controversial design decision, which
 * may be revised in the future.
 *
 * @param hardware {@code Element} to be loaded
 */
public void unmarshal(final Element hardware) {
    log.fine("Unmarshalling device: " + name);
    for (Element device : hardware.getChildren()) {
        if (device.getAttributeValue("name").equals(name)) {
            preUnmarshal();
            for (Element descriptorTag : device.getChildren()) {
                for (Descriptor descriptor : this) {
                    if (descriptor.getName().equals(descriptorTag.getAttributeValue("name"))) {
                        log.finest("Unmarshalling '" + descriptor.getName() + "'");
                        descriptor.unmarshal(descriptorTag);
                        break;
                    }
                }
            }
            postUnmarshal();
            break;
        }
    }
}

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

License:Open Source License

public AccessRule buildAccessRule(final Element ruleElem, final RuleSet ruleSet) throws RulesException {
    AccessRule prevRule = null, topRule = null;
    for (final Element subElem : getChildren(ruleElem)) {
        final AccessRule accRule = new AccessRule(ruleSet);

        if (subElem.getName().equals("allow")) {
            accRule.setType(AccessRuleType.ALLOW);
        } else if (subElem.getName().equals("deny")) {
            accRule.setType(AccessRuleType.DENY);
        } else if (subElem.getName().equals("from") || subElem.getName().equals("to")
                || subElem.getName().equals("message")) {
            continue;
        } else {/* w  ww  .  j  a va 2  s.  c  o  m*/
            throw new RulesDocumentException(subElem, "Invalid element <" + subElem.getName() + "> --"
                    + " expected an access rule (<deny> or <allow>)");
        }

        final Element fromElem = subElem.getChild("from");
        if (fromElem != null) {
            accRule.setFrom(buildPattern(fromElem, ruleSet));
        }

        final Element toElem = subElem.getChild("to");
        if (toElem != null) {
            accRule.setTo(buildPattern(toElem, ruleSet));
        }

        if (!subElem.getChildren().isEmpty()) {
            accRule.setChild(buildAccessRule(subElem, ruleSet));
        }

        if (topRule == null) {
            topRule = accRule;
        } else {
            prevRule.setNext(accRule);
        }
        prevRule = accRule;
    }
    if (topRule != null) {
        topRule.setMessage(ruleElem.getChildText("message"));
        buildSeverity(topRule, ruleElem);
    }
    return topRule;
}

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

License:Open Source License

private List<Element> getChildren(final Element ruleElem) {
    return ruleElem.getChildren();
}

From source file:de.bund.bfr.knime.pmm.common.ParametricModel.java

License:Open Source License

public ParametricModel(final Element modelElement) {
    this();//from  www. ja  v a2 s .co  m

    m_dbuuid = modelElement.getAttributeValue(ATT_MDBUUID);
    em_dbuuid = modelElement.getAttributeValue(ATT_EMDBUUID);
    modelName = modelElement.getAttributeValue(ATT_MODELNAME);
    if (modelElement.getAttributeValue("FittedModelName") != null
            && !modelElement.getAttributeValue("FittedModelName").isEmpty())
        fittedModelName = modelElement.getAttributeValue("FittedModelName");
    modelClass = XmlHelper.getInt(modelElement, ATT_MODELCLASS);
    level = Integer.valueOf(modelElement.getAttributeValue(ATT_LEVEL));
    modelId = Integer.valueOf(modelElement.getAttributeValue(ATT_MODELID));
    estModelId = Integer.valueOf(modelElement.getAttributeValue(ATT_ESTMODELID));
    if (modelElement.getAttributeValue(ATT_GLOBALMODELID) != null)
        globalModelId = Integer.valueOf(modelElement.getAttributeValue(ATT_GLOBALMODELID));

    if (modelElement.getAttributeValue(ATT_CHECKED) != null
            && !modelElement.getAttributeValue(ATT_CHECKED).isEmpty())
        isChecked = Boolean.valueOf(modelElement.getAttributeValue(ATT_CHECKED));
    if (modelElement.getAttributeValue(ATT_COMMENT) != null
            && !modelElement.getAttributeValue(ATT_COMMENT).isEmpty())
        comment = modelElement.getAttributeValue(ATT_COMMENT);
    if (modelElement.getAttributeValue(ATT_QSCORE) != null
            && !modelElement.getAttributeValue(ATT_QSCORE).isEmpty())
        qualityScore = Integer.valueOf(modelElement.getAttributeValue(ATT_QSCORE));
    if (modelElement.getAttributeValue(ATT_RSS) != null)
        rss = Double.valueOf(modelElement.getAttributeValue(ATT_RSS));
    if (modelElement.getAttributeValue(ATT_RMS) != null)
        rms = Double.valueOf(modelElement.getAttributeValue(ATT_RMS));
    if (modelElement.getAttributeValue(ATT_AIC) != null)
        aic = Double.valueOf(modelElement.getAttributeValue(ATT_AIC));
    if (modelElement.getAttributeValue(ATT_BIC) != null)
        bic = Double.valueOf(modelElement.getAttributeValue(ATT_BIC));
    rsquared = Double.valueOf(modelElement.getAttributeValue(ATT_RSQUARED));
    condId = Integer.valueOf(modelElement.getAttributeValue(ATT_CONDID));

    HashMap<String, String> rMap = new HashMap<>();
    for (Element el : modelElement.getChildren()) {
        if (el.getName().equals(ATT_FORMULA)) {
            formula = el.getText();
        } else if (el.getName().equals(ELEMENT_PARAM)) {
            boolean minNull = el.getAttributeValue(ATT_MINVALUE) == null
                    || el.getAttributeValue(ATT_MINVALUE).equals("null");
            boolean maxNull = el.getAttributeValue(ATT_MAXVALUE) == null
                    || el.getAttributeValue(ATT_MAXVALUE).equals("null");
            boolean valNull = el.getAttributeValue(ATT_VALUE) == null
                    || el.getAttributeValue(ATT_VALUE).equals("null");
            boolean errNull = el.getAttributeValue(ATT_PARAMERR) == null
                    || el.getAttributeValue(ATT_PARAMERR).equals("null");
            boolean categoryNull = el.getAttributeValue("Category") == null
                    || el.getAttributeValue("Category").equals("null");
            boolean unitNull = el.getAttributeValue("Unit") == null
                    || el.getAttributeValue("Unit").equals("null");

            Double min = minNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_MINVALUE));
            Double max = maxNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_MAXVALUE));
            Double val = valNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_VALUE));
            Double err = errNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_PARAMERR));
            String category = categoryNull ? null : el.getAttributeValue("Category");
            String unit = unitNull ? null : el.getAttributeValue("Unit");

            ParamXml px = new ParamXml(el.getAttributeValue(ATT_PARAMNAME),
                    XmlHelper.getBoolean(el, ATT_IS_START), val, err, min, max, null, null, category, unit);
            parameter.add(px);
        } else if (el.getName().equals(ATT_INDEPVAR)) {
            boolean minNull = el.getAttributeValue(ATT_MININDEP) == null
                    || el.getAttributeValue(ATT_MININDEP).equals("null");
            boolean maxNull = el.getAttributeValue(ATT_MAXINDEP) == null
                    || el.getAttributeValue(ATT_MAXINDEP).equals("null");
            boolean categoryNull = el.getAttributeValue("Category") == null
                    || el.getAttributeValue("Category").equals("null");
            boolean unitNull = el.getAttributeValue("Unit") == null
                    || el.getAttributeValue("Unit").equals("null");
            Double min = minNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_MININDEP));
            Double max = maxNull ? Double.NaN : Double.valueOf(el.getAttributeValue(ATT_MAXINDEP));
            String category = categoryNull ? null : el.getAttributeValue("Category");
            String unit = unitNull ? null : el.getAttributeValue("Unit");
            IndepXml ix = new IndepXml(el.getAttributeValue(ATT_PARAMNAME), min, max, category, unit);
            independent.add(ix);
        } else if (el.getName().equals(ATT_RMAP)) {
            rMap.put(el.getAttributeValue("NEW"), el.getAttributeValue("OLD"));
        } else if (el.getName().equals(ATT_DEPVAR)) {
            depXml = new DepXml(el.getAttributeValue(ATT_PARAMNAME), el.getAttributeValue("Category"),
                    el.getAttributeValue("Unit"));
        } else if (el.getName().equals(ATT_MLIT)) {
            try {
                modelLit = new PmmXmlDoc(el.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (el.getName().equals(ATT_EMLIT)) {
            try {
                estLit = new PmmXmlDoc(el.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (el.getName().equals(ATT_INDEP)) {
            try {
                independent = new PmmXmlDoc(el.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (el.getName().equals(ATT_DEP)) {
            try {
                PmmXmlDoc dep = new PmmXmlDoc(el.getText());
                if (dep.size() > 0)
                    depXml = (DepXml) dep.get(0);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (el.getName().equals(ATT_PARAM)) {
            try {
                parameter = new PmmXmlDoc(el.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            assert false;
        }
    }
    for (String name : rMap.keySet()) {
        String origName = rMap.get(name);
        if (depXml.getOrigName().equals(origName)) {
            depXml.setName(name);
        } else {
            for (PmmXmlElementConvertable el : parameter.getElementSet()) {
                if (el instanceof ParamXml) {
                    ParamXml px = (ParamXml) el;
                    if (px.getOrigName().equals(origName)) {
                        px.setName(name);
                        break;
                    }
                }
            }
            for (PmmXmlElementConvertable el : independent.getElementSet()) {
                if (el instanceof IndepXml) {
                    IndepXml ix = (IndepXml) el;
                    if (ix.getOrigName().equals(origName)) {
                        ix.setName(name);
                        break;
                    }
                }
            }
        }
    }
}

From source file:de.bund.bfr.knime.pmm.common.ParamXml.java

License:Open Source License

public ParamXml(Element el) {
    this(XmlHelper.getString(el, ATT_NAME), XmlHelper.getString(el, ATT_ORIGNAME),
            XmlHelper.getBoolean(el, ATT_IS_START), XmlHelper.getDouble(el, ATT_VALUE),
            XmlHelper.getDouble(el, ATT_ERROR), XmlHelper.getDouble(el, ATT_MIN),
            XmlHelper.getDouble(el, ATT_MAX), XmlHelper.getDouble(el, ATT_P), XmlHelper.getDouble(el, ATT_T),
            XmlHelper.getDouble(el, ATT_MINGUESS), XmlHelper.getDouble(el, ATT_MAXGUESS),
            XmlHelper.getString(el, ATT_CATEGORY), XmlHelper.getString(el, ATT_UNIT),
            XmlHelper.getString(el, ATT_DESCRIPTION), new HashMap<String, Double>());

    for (Element e : el.getChildren()) {
        if (e.getName().equals(ATT_CORRELATION)) {
            String n = e.getAttributeValue(ATT_ORIGNAME);
            Double d = XmlHelper.getDouble(e, ATT_VALUE);

            correlations.put(n, d);/*from   w  w  w. jav a 2  s  . co m*/
        }
    }
}

From source file:de.bund.bfr.knime.pmm.common.PmmTimeSeries.java

License:Open Source License

public PmmTimeSeries(Element xmlElement) {
    super(new TimeSeriesSchema());
    try {//w  w w  .  j a v  a2 s.  c  o m
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_CONDID) != null)
            setCondId(Integer.parseInt(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_CONDID)));
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_COMBASEID) != null)
            setCombaseId(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_COMBASEID));
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MATRIX) != null)
            setValue(TimeSeriesSchema.ATT_MATRIX,
                    new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MATRIX)));
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_AGENT) != null)
            setValue(TimeSeriesSchema.ATT_AGENT,
                    new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_AGENT)));
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MISC) != null)
            setValue(TimeSeriesSchema.ATT_MISC,
                    new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MISC)));
        for (Element el : xmlElement.getChildren()) {
            if (el.getName().equals(ELEMENT_TSXML)) {
                if (el.getText() != null) {
                    PmmXmlDoc timeSeriesXmlDoc = new PmmXmlDoc(el.getText());
                    this.setValue(TimeSeriesSchema.ATT_TIMESERIES, timeSeriesXmlDoc);
                }
            } else if (el.getName().equals(ELEMENT_MDINFO)) {
                if (el.getText() != null) {
                    PmmXmlDoc mdInfoXmlDoc = new PmmXmlDoc(el.getText());
                    this.setValue(TimeSeriesSchema.ATT_MDINFO, mdInfoXmlDoc);
                }
            } else if (el.getName().equals(ELEMENT_LITMD)) {
                if (el.getText() != null) {
                    PmmXmlDoc litMdDoc = new PmmXmlDoc(el.getText());
                    this.setValue(TimeSeriesSchema.ATT_LITMD, litMdDoc);
                }
            }
        }
        if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_DBUUID) != null)
            setValue(TimeSeriesSchema.ATT_DBUUID, xmlElement.getAttributeValue(TimeSeriesSchema.ATT_DBUUID));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.bund.bfr.knime.pmm.common.PmmXmlDoc.java

License:Open Source License

private void parseElement(Element rootElement) {
    for (Element el : rootElement.getChildren()) {
        /*/*from   w ww  .  ja  v  a 2s . c  o m*/
         * if (el instanceof PmmXmlElementConvertable) { elementSet.add(new
         * ParametricModel(el)); }
         */
        switch (el.getName()) {
        case ParametricModel.ELEMENT_PARAMETRICMODEL:
            elementSet.add(new ParametricModel(el));
            break;
        case MiscXml.ELEMENT_MISC:
            elementSet.add(new MiscXml(el));
            break;
        case ParamXml.ELEMENT_PARAM:
            elementSet.add(new ParamXml(el));
            break;
        case IndepXml.ELEMENT_INDEP:
            elementSet.add(new IndepXml(el));
            break;
        case DepXml.ELEMENT_DEPENDENT:
            elementSet.add(new DepXml(el));
            break;
        case TimeSeriesXml.ELEMENT_TIMESERIES:
            elementSet.add(new TimeSeriesXml(el));
            break;
        case MdInfoXml.ELEMENT_MDINFO:
            elementSet.add(new MdInfoXml(el));
            break;
        case LiteratureItem.ELEMENT_LITERATURE:
            elementSet.add(new LiteratureItem(el));
            break;
        case MLiteratureItem.ELEMENT_LITERATURE:
            elementSet.add(new MLiteratureItem(el));
            break;
        case MDLiteratureItem.ELEMENT_LITERATURE:
            elementSet.add(new MDLiteratureItem(el));
            break;
        case EMLiteratureItem.ELEMENT_LITERATURE:
            elementSet.add(new EMLiteratureItem(el));
            break;
        case CatalogModelXml.ELEMENT_CATALOGMODEL:
            elementSet.add(new CatalogModelXml(el));
            break;
        case EstModelXml.ELEMENT_ESTMODEL:
            elementSet.add(new EstModelXml(el));
            break;
        case AgentXml.ELEMENT_AGENT:
            elementSet.add(new AgentXml(el));
            break;
        case MDAgentXml.ELEMENT_AGENT:
            elementSet.add(new MDAgentXml(el));
            break;
        case Model1AgentXml.ELEMENT_AGENT:
            elementSet.add(new Model1AgentXml(el));
            break;
        case Model2AgentXml.ELEMENT_AGENT:
            elementSet.add(new Model2AgentXml(el));
            break;
        case MatrixXml.ELEMENT_MATRIX:
            elementSet.add(new MatrixXml(el));
            break;
        case MDMatrixXml.ELEMENT_MATRIX:
            elementSet.add(new MDMatrixXml(el));
            break;
        case Model1MatrixXml.ELEMENT_MATRIX:
            elementSet.add(new Model1MatrixXml(el));
            break;
        case Model2MatrixXml.ELEMENT_MATRIX:
            elementSet.add(new Model2MatrixXml(el));
            break;
        case PmmTimeSeries.ELEMENT_TIMESERIES:
            elementSet.add(new PmmTimeSeries(el));
            break;
        }
    }
}

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

License:Open Source License

/**
 * This method is called from the {@link #checkForDoubleEntry(int, int) checkForDoubleEntry(int, int)} method
 * and used to recursivly scan all elements of a desktop. If an entry-element which id-attribute matches
 * the parameter {@code entrynumber} was found, this element is returned, else {@code null} is returned.
 *
 * @param e the element where we start scanning. for the first call, use {@link #getDesktopElement(int) getDesktopElement(int)}
 * to retrieve the root-element for starting the recursive scan.
 * @param entrynumber the number of the entry we are looking for. if any element's id-attribut matches this
 * parameter, the element is return, else null
 * @return an element which id-attribute matches the parameter {@code entrynumber}, or null if no element
 * was found//from  w w  w .  j a  va  2s .  co m
 */
private LinkedList<Element> findElements(Element e, String entrynumber, LinkedList<Element> foundelements) {
    // if we don't have any element, return null
    if (e == null)
        return foundelements;
    // get a list with all children of the element
    List<Element> children = e.getChildren();
    // create an iterator
    Iterator<Element> it = children.iterator();
    // go through all children
    while (it.hasNext()) {
        // get the child
        e = it.next();
        // else check whether we have child-elements - if so, re-call method
        if (hasChildren(e))
            foundelements = findElements(e, entrynumber, foundelements);
        // check whether we have an entry-element that matched the requested id-number
        if (e != null && e.getName().equals(ELEMENT_ENTRY)) {
            // check whether attribute exists
            String att = e.getAttributeValue("id");
            // if so, and it machtes the requested id-number, add element to list
            if (att != null && att.equals(entrynumber))
                foundelements.add(e);
        }
    }
    return foundelements;
}

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

License:Open Source License

public int getCommentCount(Element e, int commentcount) {
    // if we don't have any element, return null
    if (e == null)
        return commentcount;
    // get a list with all children of the element
    List<Element> children = e.getChildren();
    // create an iterator
    Iterator<Element> it = children.iterator();
    // go through all children
    while (it.hasNext()) {
        // get the child
        e = it.next();//from   www  .  jav  a  2s .c  o m
        // else check whether we have child-elements - if so, re-call method
        if (hasChildren(e))
            commentcount = getCommentCount(e, commentcount);
        // check whether we have an entry-element that matched the requested id-number
        if (e != null) {
            // check whether we have a bullet-point
            if (e.getName().equals(ELEMENT_BULLET)) {
                // if we have a bullet, return the text of it's comment-child.
                Element comel = e.getChild(ATTR_COMMENT);
                if (comel != null && !comel.getText().isEmpty())
                    commentcount++;
            } else {
                // else return the element's text
                if (!e.getText().isEmpty())
                    commentcount++;
            }
        }
    }
    return commentcount;
}

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

License:Open Source License

/**
 * This method recursivly scans all elements of a desktop. If an entry-element which id-attribute matches
 * the parameter {@code entrynumber} was found, this method returns {@code true}.
 *
 * @param e the element where we start scanning. for the first call, use {@link #getDesktopElement(int) getDesktopElement(int)}
 * to retrieve the root-element for starting the recursive scan.
 * @param entrynumber the number of the entry we are looking for. if any element's id-attribut matches this
 * parameter, the element is return, else null
 * @param found the initial value, should be {@code false} when initially called
 * @return {@code true} when the entry with the number {@code entrynumber} was found, {@code false} otherwise.
 *///from  w w w.j a va2  s .  co  m
public boolean desktopHasElement(Element e, String entrynumber, boolean found) {
    // if we don't have any element, return null
    if (e == null)
        return false;
    // get a list with all children of the element
    List<Element> children = e.getChildren();
    // create an iterator
    Iterator<Element> it = children.iterator();
    // go through all children
    while (it.hasNext()) {
        // get the child
        e = it.next();
        // else check whether we have child-elements - if so, re-call method
        if (hasChildren(e))
            found = desktopHasElement(e, entrynumber, found);
        // check whether an entry was found in children
        if (found)
            return true;
        // check whether we have an entry-element that matched the requested id-number
        if (e != null && e.getName().equals(ELEMENT_ENTRY)) {
            // check whether attribute exists
            String att = e.getAttributeValue("id");
            // if so, and it machtes the requested id-number, add element to list
            if (att != null && att.equals(entrynumber)) {
                // save element
                foundDesktopElement = e;
                return true;
            }
        }
    }
    return found;
}