Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

From source file:DataWeb.User.java

License:Open Source License

public User(Element e, Namespace ns) {
    id = e.getAttributeValue("id");
    usuario = e.getChildText("usuario", ns);
    password = e.getChildText("password", ns);
    nombres = e.getChildText("nombres", ns);
    apPaterno = e.getChildText("apPat", ns);
    apMaterno = e.getChildText("apMat", ns);
    category = e.getChildText("category", ns);

    idCurso = new ArrayList<String>();
    for (Element curso : e.getChildren("idCurso", ns))
        idCurso.add(curso.getText());//from w w w . ja  v  a 2  s  .co  m
}

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

License:Open Source License

public RuleSet buildRuleSet(final Element ruleSetElem, final RuleSet parent) throws RulesException {
    final RuleSet ruleSet = new RuleSet(parent);

    final String name = ruleSetElem.getAttributeValue("name");
    if (name != null) {
        ruleSet.setName(name);//ww  w . jav  a 2  s.  c o m
    }

    buildSeverity(ruleSet, ruleSetElem);

    for (final Element subElem : getChildren(ruleSetElem)) {
        final String subElemName = subElem.getName();
        if (subElemName.equals("pattern")) {
            final String patternName = subElem.getAttributeValue("name");
            if (ruleSet.declaresPattern(patternName)) {
                throw new RulesDocumentException(subElem,
                        "Pattern named \"" + patternName + "\" is already defined in this context");
            }

            ruleSet.setPattern(patternName, buildPattern(subElem, ruleSet));
        } else if (subElemName.equals("subset")) {
            if (ruleSet.getSubsetPattern() != null) {
                throw new RulesDocumentException(subElem,
                        "<ruleset> may only contain a single <subset> element");
            }
            ruleSet.setSubsetPattern(buildPattern(subElem, ruleSet));
        } else if (subElemName.equals("access-rule")) {
            ruleSet.addRule(buildAccessRule(subElem, ruleSet));
        } else if (subElemName.equals("var")) {
            ruleSet.addRule(buildVariable(subElem, ruleSet));
        } else if (subElemName.equals("foreach")) {
            ruleSet.addRule(buildForEach(subElem, ruleSet));
        } else if (subElemName.equals("ruleset")) {
            ruleSet.addRule(buildRuleSet(subElem, ruleSet));
        } else if (subElemName.equals("message")) {
            ruleSet.addRule(buildMessage(subElem, ruleSet));
        }
    }

    return ruleSet;
}

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

License:Open Source License

public Pattern buildPattern(final Element patternElem, final RuleSet ruleSet, final boolean isTopElem,
        final Pattern nextPat) throws RulesException {
    // handle options

    final String otherPatName = patternElem.getAttributeValue("pattern");
    final String className = getClassNameAttributeValue(patternElem);
    final String filterName = patternElem.getAttributeValue("filter");

    CompositePatternType patType;//from w ww  . jav  a  2s .  c  o  m
    if (patternElem.getName().equals("include")) {
        patType = CompositePatternType.INCLUDE;
    } else if (patternElem.getName().equals("exclude")) {
        patType = filterName == null ? CompositePatternType.EXCLUDE : CompositePatternType.INCLUDE;
    } else if (isTopElem) {
        patType = CompositePatternType.INCLUDE;
    } else {
        throw new RulesDocumentException(patternElem,
                "Invalid element <" + patternElem.getName() + "> --" + " expected <include> or <exclude>");
    }

    if (otherPatName != null && className != null) {
        throw new RulesDocumentException(patternElem,
                "patterns cannot have both a \"pattern\" and a \"class\" attribute");
    }

    // do the head thing

    Pattern head = null;
    if (className != null) {
        head = new RegexPattern(className);
    } else if (otherPatName != null) {
        head = ruleSet.getPattern(otherPatName);
        if (head == null) {
            throw new UndeclaredPatternException(otherPatName);
        }
    }

    // build up children

    Pattern childrenPat = null;
    final List<Element> children = new ArrayList<Element>(getChildren(patternElem)); // !
    // workaround
    // for
    // bug
    // in
    // JUnit
    // List children = patternElem.getChildren(); // this should work
    // instead when JUnit bug is fixed
    for (final ListIterator<Element> childIter = children.listIterator(children.size()); childIter
            .hasPrevious();) {
        final Element subElem = childIter.previous();
        if (subElem.getName().equals("message")) {
            continue;
        }

        childrenPat = buildPattern(subElem, ruleSet, false, childrenPat);
    }

    // wrap head in a filter if necessary

    if (filterName != null) {
        final Map<String, String> options = new HashMap<String, String>();
        for (final Attribute attr : getAttributes(patternElem)) {
            options.put(attr.getName(), attr.getValue());
        }
        options.remove("name");
        options.remove("pattern");
        options.remove("class");
        options.remove("regex");

        final Filter filter = FilterFinder.findFilter(filterName);
        head = filter.createPattern(ruleSet,
                head == null ? new ArrayList<Pattern>() : Collections.singletonList(head), options);

        if (patternElem.getName().equals("exclude")) {
            head = CompositePattern.create(CompositePatternType.EXCLUDE, head, null, null);
        }
    }

    // pull together composite

    return CompositePattern.create(patType, head, childrenPat, nextPat);
}

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

License:Open Source License

public Variable buildVariable(final Element forEachElem, final RuleSet parent) throws RulesException {
    final String varName = forEachElem.getAttributeValue("name");
    if (varName == null) {
        throw new RulesDocumentException(forEachElem, "<var> is missing the \"name\" attribute");
    }//  w w w.  j  a  v  a 2  s.  com

    final String value = forEachElem.getAttributeValue("value");
    if (value == null) {
        throw new RulesDocumentException(forEachElem, "<var> is missing the \"value\" attribute");
    }

    return new Variable(parent, varName, value);
}

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

License:Open Source License

public ForEach buildForEach(final Element forEachElem, final RuleSet parent) throws RulesException {
    final String varName = forEachElem.getAttributeValue("var");
    if (varName == null) {
        throw new RulesDocumentException(forEachElem, "<foreach> is missing the \"var\" attribute");
    }//w w w.j  a  va2 s.co  m

    final String className = getClassNameAttributeValue(forEachElem);
    if (className == null) {
        throw new RulesDocumentException(forEachElem, "<foreach> is missing the \"class\" attribute");
    }

    final ForEach forEach = new ForEach(parent);
    forEach.setVariableName(varName);
    forEach.setRegex(className);
    forEach.setRuleSet(buildRuleSet(forEachElem, parent));
    return forEach;
}

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

License:Open Source License

public void buildSeverity(final Rule rule, final Element elem) throws RulesDocumentException {
    final String severityS = elem.getAttributeValue("severity");
    if (severityS != null && !"".equals(severityS)) {
        RuleSeverity severity;//from   ww w.j  a va 2 s . c  o  m
        try {
            severity = RuleSeverity.fromName(severityS);
        } catch (final IllegalArgumentException iae) {
            throw new RulesDocumentException(elem, iae.getMessage());
        }
        rule.setSeverity(severity);
    }
}

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

License:Open Source License

private String getClassNameAttributeValue(final Element elem) {
    String value = elem.getAttributeValue("class");
    if (value == null) {
        value = elem.getAttributeValue("regex");
        if (value != null) {
            System.err.println(//w  ww  .  j  av  a2  s.  c  o m
                    "WARNING: The \"regex\" attribute is deprecated, and will be removed in v1.0.  Use \"class\" instead");
        }
    }
    return value;
}

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

License:Open Source License

public ParametricModel(final Element modelElement) {
    this();//w w  w.  j av  a 2s . c o  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  ww. j av a 2  s  .  c o  m
        }
    }
}

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

License:Open Source License

public PmmTimeSeries(Element xmlElement) {
    super(new TimeSeriesSchema());
    try {// ww w . ja  v  a 2s  .  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();
    }
}