Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

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

License:Open Source License

public Message buildMessage(final Element messageElem, final RuleSet parent) throws RulesException {
    final Message message = new Message(parent, messageElem.getText());
    buildSeverity(message, messageElem);
    return message;
}

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

License:Open Source License

public ParametricModel(final Element modelElement) {
    this();/*from   ww w .ja v a  2 s .c om*/

    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.PmmTimeSeries.java

License:Open Source License

public PmmTimeSeries(Element xmlElement) {
    super(new TimeSeriesSchema());
    try {//ww w  .  java2 s  .  co  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.danielluedecke.zettelkasten.database.AcceleratorKeys.java

License:Open Source License

/**
 * This methods returns the accelerator key of a given position in the xml-file
 * Following constants should be used as parameters:<br>
 * MAINKEYS<br>/*from w  w  w  .  j av a2 s . c o m*/
 * NEWENTRYKEYS<br>
 * DESKTOPKEYS<br>
 * SEARCHRESULTSKEYS<br>
 * 
 * @param what (uses constants, see global field definition at top of source)
 * @param pos (a valid position of an element)
 * @return the string containing the accelerator key or an empty string if nothing was found
 */
public String getAcceleratorKey(int what, int pos) {
    // retrieve the element
    Element acckey = retrieveElement(what, pos);
    // if the element was not found, return an empty string
    if (null == acckey) {
        return "";
    }
    // else the value (i.e. the accelerator key string)
    return acckey.getText();
}

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

License:Open Source License

/**
 * This methods returns the accelerator key of a given position in the xml-file
 * Following constants should be used as parameters:<br>
 * MAINKEYS<br>//from w w w.  j  a  va 2  s  .c  om
 * NEWENTRYKEYS<br>
 * DESKTOPKEYS<br>
 * SEARCHRESULTSKEYS<br>
 *
 * @param what uses constants, see global field definition at top of source
 * @param actionname the attribute (i.e. the action's name) we want to find
 * @return the string containing the accelerator key or null if nothing was found
 */
public String getAcceleratorKey(int what, String actionname) {
    // retrieve the element
    Element acckey = retrieveElement(what, actionname);
    // if the element was not found, return an empty string
    if (null == acckey) {
        return null;
    }
    // else the value (i.e. the accelerator key string)
    return acckey.getText();
}

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

License:Open Source License

/**
 * Gets a String-pair of auto-correct data, i.e. a string array with 2 fields. first
 * field contains the wrong/mispelled writing, the second field holds the correct
 * version of the word/*from   w w w  .  j a  v  a 2  s. c o m*/
 * @param nr the position of the element we want to retrieve
 * @return a string array containing the wrong and right spelling
 */
public String[] getElement(int nr) {
    // get all elements
    List<Element> all = autokorrektur.getRootElement().getChildren();
    // get the requested element
    Element el = all.get(nr);
    // new string array
    String[] retval = null;
    // if we found an element, return its content
    if (el != null) {
        retval = new String[2];
        retval[0] = el.getAttributeValue("id");
        retval[1] = el.getText();
    }

    return retval;
}

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

License:Open Source License

/**
 *
 * @param wrong//from w w w .  j av  a  2s .  c  o  m
 * @return the correct spelling of the word {@code wrong} or {@code null}, if no spellcorrection was found
 */
public String getCorrectSpelling(String wrong) {
    // get all elements
    List<Element> all = autokorrektur.getRootElement().getChildren();
    // create an iterator
    Iterator<Element> i = all.iterator();
    // go through list
    while (i.hasNext()) {
        // get element
        Element el = i.next();
        // get attribute value
        String att = el.getAttributeValue("id");
        // check for existing attribute
        if (null == att) {
            return null;
        }
        // get spell-check-word
        String correct = att.toLowerCase();
        // get lower-case word of mistyped wrong word...
        String retval = wrong.toLowerCase();
        // if the element's id equals the requestes string "e", return true
        // i.e. the string e already exists as element
        if (correct.equalsIgnoreCase(wrong)) {
            // now that we found the correct word, we want to see whether
            // the word starts with an upper case letter - and if so, convert
            // the first letter of the return value to upper case as well
            String firstLetter = wrong.substring(0, 1);
            String firstBigLetter = wrong.substring(0, 1).toUpperCase();
            // get return value
            retval = el.getText();
            // if both matches, we have upper case initial letter
            // convert first letter to uppercase
            if (firstLetter.equals(firstBigLetter)) {
                retval = retval.substring(0, 1).toUpperCase() + retval.substring(1);
            }
            return retval;
        }
        // when the misspelled phrase starts with an asterisk, we know that we should check the
        // end of or in between the typed word "wrong".
        if (correct.startsWith("*")) {
            // first we remove the asterisk
            correct = correct.substring(1);
            // if the misspelled phrase also ends with an asterisk, we have to check
            // for the phrase in between - that means, "wrong" is not allowed to end or start
            // with "correct"
            if (correct.endsWith(("*"))) {
                // remove trailing asterisk
                correct = correct.substring(0, correct.length() - 1);
                // if the mistyped word "wrong" does not start and end with "correct", we know
                // that we have a correction in between
                if (retval.contains(correct)) {
                    // return correct word for wrong spelling
                    return correctWithCase(retval, correct, el.getText(), wrong);
                }
            }
            // if the mistyped word "wrong" does not end with "correct", we know
            // that
            else if (retval.endsWith(correct) && retval.contains(correct)) {
                // return correct word for wrong spelling
                return correctWithCase(retval, correct, el.getText(), wrong);
            }
        } else if (correct.endsWith("*")) {
            // get lower-case word of mistyped wrong word...
            retval = wrong.toLowerCase();
            // if the mistyped word "wrong" does not end with "correct", we know
            // that we have the correction at thr word beginning
            if (retval.startsWith(correct) && retval.contains(correct)) {
                // return correct word for wrong spelling
                return correctWithCase(retval, correct, el.getText(), wrong);
            }
        }
    }
    // return null, no correct word found
    return null;
}

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

License:Open Source License

/**
 * This method returns a complete bookmark at the position {@code nr}, i.e.
 * the bookmarked entry-index-number, the category name and the bookmark's comment
 * are return as an string-array./*from   w w w  .j  a va2s .  co  m*/
 * <br><br>
 * The counterpart of this method is "addBookmark", which adds a new complete
 * bookmark including comment and category.
 * 
 * @param nr the bookmark which should be retrieved
 * @return an array with all bookmark-information:<br>
 * - String[0]: entry-number<br>
 * - String[1]: category-name and<br>
 * - String[2]: comment
 * or {@code null} if no bookmark-element was found
 */
public String[] getCompleteBookmark(int nr) {
    // retrieve the bookmark-element
    Element bm = retrieveBookmarkElement(nr);
    // if it does not exist, leave method
    if (null == bm) {
        return null;
    }
    // else create return value
    String[] retval = new String[3];
    // retrieve the entry-number, which is bookmarked
    String entry_id = bm.getAttributeValue("id");
    // check for valid attribute-value
    if (entry_id != null) {
        // valid attribute, so store entry-id
        retval[0] = entry_id;
    } else {
        // else return null
        return null;
    }
    // get the category-string
    String category = bm.getAttributeValue("cat");
    // check for valid value
    if (category != null) {
        // save category
        try {
            retval[1] = getCategory(Integer.parseInt(category));
        } catch (NumberFormatException ex) {
            Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage());
            return null;
        }
    } else {
        // else return null
        return null;
    }
    // get the bookmarks comment
    retval[2] = bm.getText();

    return retval;
}

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

License:Open Source License

/**
 * This method returns the comment of a given bookmark {@code nr}.
 * // www  .  jav a  2s . c  om
 * @param nr the bookmark-number of which comment should be retrieved
 * @return a string with the comment, or an empty string if no entry or comment existed.
 */
public String getComment(int nr) {
    // retrieve the bookmark-element
    Element bm = retrieveBookmarkElement(nr);
    // if it does not exist, leave method
    if (null == bm) {
        return "";
    }
    // else return comment, if we have any...
    return bm.getText();
}

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

License:Open Source License

/**
 * This method returns the name of the category at position {@code pos}
 * /* ww w .ja v  a2 s.c o  m*/
 * @param pos the position of the requested category
 * @return the name of the requested category, or an empty string if no category was found
 */
public String getCategory(int pos) {
    // retrieve category element
    Element cat = retrieveCategoryElement(pos);
    // if it does not exist, return empty string
    if (null == cat) {
        return "";
    }
    // else return category name
    return cat.getText();
}