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:de.danielluedecke.zettelkasten.database.Settings.java

License:Open Source License

/**
 * Retrieves settings for the header-1-font (the font used for the main-entry's 1st heading-tags).
 * @param what (indicates, which font-characteristic we want to have. use following constants:<br>
 * - FONTNAME<br>/*from w ww. ja  v a 2s. c om*/
 * - FONTSIZE<br>
 * - FONTCOLOR<br>
 * - FONTSTYLE<br>
 * - FONTWEIGHT<br>
 * @return the related font-information as string.
 */
public String getHeaderfont1(int what) {
    Element el = settingsFile.getRootElement().getChild(SETTING_HEADERFONT1);
    String retval = "";
    if (el != null) {
        switch (what) {
        case FONTNAME:
            retval = el.getText();
            break;
        case FONTSIZE:
            retval = el.getAttributeValue("size");
            break;
        case FONTCOLOR:
            retval = el.getAttributeValue("color");
            break;
        case FONTSTYLE:
            retval = el.getAttributeValue("style");
            break;
        case FONTWEIGHT:
            retval = el.getAttributeValue("weight");
            break;
        }
    }
    return retval;
}

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

License:Open Source License

/**
 * Retrieves settings for the header-2-font (the font used for the main-entry's 2nd heading-tags).
 * @param what (indicates, which font-characteristic we want to have. use following constants:<br>
 * - FONTNAME<br>// w w  w. j av  a2  s.c  o  m
 * - FONTSIZE<br>
 * - FONTCOLOR<br>
 * - FONTSTYLE<br>
 * - FONTWEIGHT<br>
 * @return the related font-information as string.
 */
public String getHeaderfont2(int what) {
    Element el = settingsFile.getRootElement().getChild(SETTING_HEADERFONT2);
    String retval = "";
    if (el != null) {
        switch (what) {
        case FONTNAME:
            retval = el.getText();
            break;
        case FONTSIZE:
            retval = el.getAttributeValue("size");
            break;
        case FONTCOLOR:
            retval = el.getAttributeValue("color");
            break;
        case FONTSTYLE:
            retval = el.getAttributeValue("style");
            break;
        case FONTWEIGHT:
            retval = el.getAttributeValue("weight");
            break;
        }
    }
    return retval;
}

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

License:Open Source License

/**
 * Retrieves settings for the header-2-font (the font used for the main-entry's 2nd heading-tags).
 * @param what (indicates, which font-characteristic we want to have. use following constants:<br>
 * - FONTNAME<br>/*from   w ww. j  av a 2s . c  o m*/
 * - FONTSIZE<br>
 * - FONTCOLOR<br>
 * - FONTSTYLE<br>
 * - FONTWEIGHT<br>
 * @return the related font-information as string.
 */
public String getQuoteFont(int what) {
    Element el = settingsFile.getRootElement().getChild(SETTING_QUOTEFONT);
    String retval = "";
    if (el != null) {
        switch (what) {
        case FONTNAME:
            retval = el.getText();
            break;
        case FONTSIZE:
            retval = el.getAttributeValue("size");
            break;
        case FONTCOLOR:
            retval = el.getAttributeValue("color");
            break;
        }
    }
    return retval;
}

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

License:Open Source License

/**
 * Retrieves settings for the header-2-font (the font used for the main-entry's 2nd heading-tags).
 * @param what (indicates, which font-characteristic we want to have. use following constants:<br>
 * - FONTNAME<br>/*  w w  w  .  jav a  2s.  com*/
 * - FONTSIZE<br>
 * - FONTCOLOR<br>
 * - FONTSTYLE<br>
 * - FONTWEIGHT<br>
 * @return the related font-information as string.
 */
public String getEntryHeaderFont(int what) {
    Element el = settingsFile.getRootElement().getChild(SETTING_ENTRYHEADERFONT);
    String retval = "";
    if (el != null) {
        switch (what) {
        case FONTNAME:
            retval = el.getText();
            break;
        case FONTSIZE:
            retval = el.getAttributeValue("size");
            break;
        case FONTCOLOR:
            retval = el.getAttributeValue("color");
            break;
        }
    }
    return retval;
}

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

License:Open Source License

/**
 * Gets a String-pair of steno data, i.e. a string array with 2 fields. first
 * field contains the short steno word, the second field holds the complete
 * version of the word//from   w w  w . j  a  va2  s  .  c  o m
 * @param nr the position of the element we want to retrieve
 * @return a string array containing the steno and the complete word
 */
public String[] getElement(int nr) {
    // get all elements
    List<Element> all = steno.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.StenoData.java

License:Open Source License

/**
 * //from w w  w  .ja v  a2 s .c  o  m
 * @param abbr
 * @return 
 */
public String getStenoWord(String abbr) {
    // get all elements
    List<Element> all = steno.getRootElement().getChildren();
    // create an iterator
    Iterator<Element> i = all.iterator();
    // go through list
    while (i.hasNext()) {
        // get element
        Element el = i.next();
        // get spell-check-word
        String correct = el.getAttributeValue("id");
        // check for existing value
        if (null == correct) {
            return null;
        }
        // if the element's id equals the requestes string "e", return true
        // i.e. the string e already exists as element
        if (correct.equals(abbr)) {
            return el.getText();
        }
    }
    return null;
}

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

License:Open Source License

/**
 * Checks whether the value passed by the parameter "e" already exists in the
 * data. Therefore, each element's id-attribute is compared to the parameter "e".
 * @param abbr the string we want to look for if it exists
 * @return {@code true} if we found it, false if it doesn't exist
 *//*from  www .  ja  v a 2 s. c o m*/
public boolean exists(String abbr) {
    // get all elements
    List<Element> all = steno.getRootElement().getChildren();
    // create an iterator
    Iterator<Element> i = all.iterator();
    // go through list
    while (i.hasNext()) {
        // get element
        Element el = i.next();
        // get attribute
        String att = el.getAttributeValue("id");
        // if the element's id equals the requestes string "e", return true
        // i.e. the string e already exists as element
        if (att != null && att.equals(abbr)) {
            return true;
        }
    }
    // nothing found...
    return false;

}

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

License:Open Source License

public String[] getSynonymLine(Document doc, int nr, boolean matchcase) {
    // get element
    Element syn = retrieveElement(doc, nr);
    // init return value
    String[] retval = null;//from w  w  w .  java 2  s .  c  om
    // if we have a valid element, go on
    if (syn != null) {
        // get list of child-element with synonyms
        List l = syn.getChildren();
        // create array
        retval = new String[l.size() + 1];
        // first element of the array is the index word
        if (matchcase) {
            // retrieve indexword-attribute
            String attr = syn.getAttributeValue("indexword");
            // check whether value ok
            if (attr != null) {
                // then use it for array
                retval[0] = attr;
            } else {
                // else log error message, telling the number of the corrupted synonym-data
                Constants.zknlogger.log(Level.WARNING, "No index word for synonym {0} found.",
                        String.valueOf(nr));
                // and return null
                return null;
            }
        } else {
            // retrieve indexword-attribute
            String attr = syn.getAttributeValue("indexword");
            // check whether value ok
            if (attr != null) {
                // then use it for array
                retval[0] = attr.toLowerCase();
            } else {
                // else log error message, telling the number of the corrupted synonym-data
                Constants.zknlogger.log(Level.WARNING, "No index word for synonym {0} found.",
                        String.valueOf(nr));
                // and return null
                return null;
            }
        }
        // following elements are the synonyms. therefore, copy the children's text to the array
        for (int cnt = 0; cnt < l.size(); cnt++) {
            // get the element
            Element e = (Element) l.get(cnt);
            // get the element's text
            if (matchcase) {
                retval[cnt + 1] = e.getText();
            } else {
                retval[cnt + 1] = e.getText().toLowerCase();
            }
        }
    }
    return retval;
}

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

License:Open Source License

/**
 * This method returns the position of a synonym (original or index word) in the XML file
 * if the synonym doesn't exist, the return value is -1.
 * <br><br>//from  ww  w . j ava2 s .  co m
 * 
 * @param indexword string-value of the synonym (original- or index-word) which is searched for in the list
 * @return the position of the synonym or -1 if no match was found
 */
public int getSynonymPosition(String indexword) {
    // trim spaces
    indexword = indexword.trim();
    // create a list of all author elements from the author xml file
    try {
        List<?> synList = synonymsFile.getRootElement().getContent();
        // and an iterator for the loop below
        Iterator<?> iterator = synList.iterator();
        // counter for the return value if a found synonym matches the parameter
        int cnt = 0;

        while (iterator.hasNext()) {
            Element syn = (Element) iterator.next();
            // if synonym-index-word matches the parameter string, return the position
            if (indexword.equalsIgnoreCase(syn.getAttributeValue("indexword"))) {
                return cnt;
            }
            // else increase counter
            cnt++;
        }
        // if no author was found, return -1
        return -1;
    } catch (IllegalStateException e) {
        Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
        return -1;
    }
}

From source file:de.danielluedecke.zettelkasten.DesktopFrame.java

License:Open Source License

/**
 * This method updates the treeview after each change made to the desktop. The changes are only
 * applied to the desktop-data-file (the xml-file managed in the {@link #desktopObj CDesktop-Class}).
 * This method retrieves the structure from this xml-document and copies it to the treeview.<br><br>
 * Updating the treeview does <b>not</b> update the display of the entries as well, since many display-updates
 * take much time. Rather the action {@link #updateView() updateView} is enabled, which updates the display.
 *//* ww  w  . j  a  va 2  s  .  c o m*/
private void updateTreeView() {
    // get the treemodel
    DefaultTreeModel dtm = (DefaultTreeModel) jTreeDesktop.getModel();
    // and first of all, clear the jTree
    dtm.setRoot(null);
    // create a new root element from the current desktop name and set it as root
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TreeUserObject(
            desktopObj.getDesktopName(jComboBoxDesktop.getSelectedIndex()), Constants.ROOT_ID_NAME, ""));
    dtm.setRoot(root);
    // get current desktop-element
    Element d = desktopObj.getCurrentDesktopElement();
    // check whether the current desktop has any children at all
    if (desktopObj.hasChildren(d)) {
        // create treeview-content
        fillChildren(d, root, dtm);
    }
    // finally, expand the whole tree
    //        expandAllTrees(true, jTreeDesktop);
    expandAllTrees();
    // check whether a certain entry should be selected or not
    if (displayentrynr != -1) {
        // check whether entry exists in current desktop
        if (desktopObj.isEntryInCurrentDesktop(displayentrynr)) {
            // if yes, retrieve element
            Element en = desktopObj.getFoundDesktopElement();
            // check for valid value
            if (en != null) {
                // get timestamp of entry
                String timestamp = en.getAttributeValue("timestamp");
                // select entry in treeview
                selectTreePath(timestamp);
            }
        }
        // reset display entry nr
        displayentrynr = -1;
    }
    // display needs to be updated...
    setNeedsUpdate(true);
}