List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
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.
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method counts the frequency (amount of appearance) of a keyword in the * main data file. Therefor, pass the index number of the keyword which has to be found. * After that, we iterate the main zkndata file, retrieving the keyword index numbers of * each entry, and then look for the appearance of "pos" (the given index number). Each time * we find that index number in an entry, the counter for the total frequency is increased by one. * * @param pos (the index number of the keyword which you are looking for) * @return (the amount of appearance / frequency of this keyword in the main data file) *//*from w w w .j av a 2 s . co m*/ public int getKeywordFrequency(int pos) { // retrieve the keyword element Element keyword = retrieveElement(keywordFile, pos); // check whether element is null if (null == keyword) { return 0; } else { try { String freq = keyword.getAttributeValue(ATTRIBUTE_FREQUENCIES); if (freq != null) { return Integer.parseInt(freq); } else { return 0; } } catch (NumberFormatException ex) { return 0; } } }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method counts the frequency (amount of appearance) of a keyword in the * main data file. Therefor, pass the index number of the keyword which has to be found. * After that, we iterate the main zkndata file, retrieving the keyword index numbers of * each entry, and then look for the appearance of "pos" (the given index number). Each time * we find that index number in an entry, the counter for the total frequency is increased by one. * * @param pos the index number of the author which you are looking for * @return the amount of appearance / frequency of this author in the main data file *//* w ww.j av a 2 s . c o m*/ public int getAuthorFrequency(int pos) { // retrieve the keyword element Element author = retrieveElement(authorFile, pos); // check whether element is null if (null == author) return 0; else return Integer.parseInt(author.getAttributeValue(ATTRIBUTE_FREQUENCIES)); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the bibkey-string of an author-value. the bibkey-string referres to a * BibTex-entry in a given BibTex-file, so the "formatted" author of the author-value saved * in our authorXml-file can be retrieved via a BibTex-File.<br><br> * This attribute is optional, so {@code null} might be returned.<br><br> * This method does the work for both//from ww w . ja va2 s . c o m * {@link #getAuthorBibKey(java.lang.String) getAuthorBibKey(String)} and * {@link #getAuthorBibKey(int) getAuthorBibKey(int)}. * * @param pos the index number of the author which you are looking for. Remember that this value * has a range from 1 to {@link #getCount(int) getCount(AUCOUNT)}. * @return a string containing the {@code bibkey} string of the author. if no such attribute or no * such author-element exists, {@code null} is returned. if attribute is empty, an empty string * is returned. */ private String getAuthorBibKeyValue(int pos) { // if we have no such author, return null if (-1 == pos || pos > getCount(AUCOUNT)) return null; // retrieve the keyword element Element author = retrieveElement(authorFile, pos); // check whether element is null if (null == author) return null; // else return the attribute-value return author.getAttributeValue(ATTRIBUTE_AUTHOR_BIBKEY); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the number of the next Zettel which is positioned * after the Zettel with the number {@code pos}. This method is needed * for reordering the entries without changing their original number, * i.e. position in the database.<br><br> * This method retrieves the entry-number of the next entry in the * user-defined order, which is stored in the attribute * {@link #ATTRIBUTE_NEXT_ZETTEL} of each {@code zettel} element. * //from w w w . j av a 2 s . c o m * @param pos The number or position of the current entry. * @return The number of the next entry in the entry-order, or {@code -1} * if no such entry or element exists. */ public int getNextZettel(int pos) { // retrieve current zettel-element Element zettel = retrieveZettel(pos); // check for valid value if (zettel != null) { // retrieve attribute String next = zettel.getAttributeValue(ATTRIBUTE_NEXT_ZETTEL); // check whether we have a valid attribute that refers to the // next entry if (next != null && !next.isEmpty()) { try { // retrieve number int nr = Integer.parseInt(next); // check whether number is within bounds if (nr < 1 || nr > getCount(ZKNCOUNT)) { nr = getFirstZettel(); } // return result return nr; } catch (NumberFormatException ex) { } } } return -1; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the number of the previous Zettel which is positioned * before the Zettel with the number {@code pos}. This method is needed * for reordering the entries without changing their original number, * i.e. position in the database.<br><br> * This method retrieves the entry-number of the previous entry in the * user-defined order, which is stored in the attribute * {@link #ATTRIBUTE_PREV_ZETTEL} of each {@code zettel} element. * //from www . j a va 2s.co m * @param pos The number or position of the current entry. * @return The number of the previous entry in the entry-order, or {@code -1} * if no such entry or element exists. */ public int getPrevZettel(int pos) { // retrieve current zettel-element Element zettel = retrieveZettel(pos); // check for valid value if (zettel != null) { // retrieve attribute String next = zettel.getAttributeValue(ATTRIBUTE_PREV_ZETTEL); // check whether we have a valid attribute that refers to the // next entry if (next != null && !next.isEmpty()) { try { // retrieve number int nr = Integer.parseInt(next); // check whether number is within bounds if (nr < 1 || nr > getCount(ZKNCOUNT)) { nr = getLastZettel(); } // return result return nr; } catch (NumberFormatException ex) { } } } return -1; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method retrieves the new unique ID for an entry. * <br><br>//from w ww .j a v a 2s . c om * <b>Caution!</b> The position {@code pos} is a value from <b>1</b> to * {@link #getCount(int) getCount(ZKNCOUNT)} - in contrary * to usual array handling where the range is from 0 to (size-1). * * @param zettel the entry-element which ID shoud be retrieved. * @return the unique ID of an entry as string-value, or {@code null} if no ID was found. */ public String getZettelID(Element zettel) { // check for valid value if (zettel != null) { // now add id to zettel-element String id = zettel.getAttributeValue(ATTRIBUTE_ZETTEL_ID); // check for valid value if (id != null && !id.isEmpty()) { return id; } } return null; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method retrieves the new unique ID for an author-element. * <br><br>//w ww.j a va 2 s .c om * <b>Caution!</b> The position {@code pos} is a value from <b>1</b> to * {@link #getCount(int) getCount(AUCOUNT)} - in contrary * to usual array handling where the range is from 0 to (size-1). * * @param nr the number of the author-element of which ID shoud be retrieved. * the position of the element, ranged from 1 to {@link #getCount(int) getCount(AUCOUNT)} * @return the unique ID of an author-element as string-value, or {@code null} if no ID was found. */ public String getAuthorID(int nr) { // retrieve element Element author = retrieveElement(authorFile, nr); // check for valid value if (author != null) { // now add id to zettel-element String id = author.getAttributeValue(ATTRIBUTE_AUTHOR_ID); // check for valid value if (id != null && !id.isEmpty()) { return id; } } return null; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method retrieves the new unique ID for a keyword-element. * <br><br>/*from w ww . ja v a 2 s . co m*/ * <b>Caution!</b> The position {@code pos} is a value from <b>1</b> to * {@link #getCount(int) getCount(KWCOUNT)} - in contrary * to usual array handling where the range is from 0 to (size-1). * * @param nr the number of the keyword-element of which ID shoud be retrieved. * the position of the element, ranged from 1 to {@link #getCount(int) getCount(KWCOUNT)} * @return the unique ID of a keyword-element as string-value, or {@code null} if no ID was found. */ public String getKeywordID(int nr) { // retrieve element Element keyword = retrieveElement(keywordFile, nr); // check for valid value if (keyword != null) { // now add id to zettel-element String id = keyword.getAttributeValue(ATTRIBUTE_KEYWORD_ID); // check for valid value if (id != null && !id.isEmpty()) { return id; } } return null; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method checks whether the entry with the number {@code nr} has a unique * ID assigned to it or not.//w ww.j a v a2s . c o m * <br><br> * <b>Caution!</b> The position {@code pos} is a value from <b>1</b> to * {@link #getCount(int) getCount(ZKNCOUNT)} - in contrary * to usual array handling where the range is from 0 to (size-1). * * @param nr the number of the entry that shoud be checked for a valid ID. * the position of the element, ranged from 1 to {@link #getCount(int) getCount(ZKNCOUNT)} * @return {@code true} if an ID was found, {@code false} otherwise. */ public boolean hasZettelID(int nr) { // retrieve element Element zettel = retrieveZettel(nr); // check for valid value if (zettel != null) { // now add id to zettel-element String id = zettel.getAttributeValue(ATTRIBUTE_ZETTEL_ID); // check for valid value if (id != null && !id.isEmpty()) { return true; } } return false; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method checks whether an author-element with the number {@code nr} has a unique * ID assigned to it or not.//from www.j a v a2 s . com * <br><br> * <b>Caution!</b> The position {@code pos} is a value from <b>1</b> to * {@link #getCount(int) getCount(AUCouNT)} - in contrary * to usual array handling where the range is from 0 to (size-1). * * @param nr the number of the author-element that shoud be checked for a valid ID. * the position of the element, ranged from 1 to {@link #getCount(int) getCount(AUCOUNT)} * @return {@code true} if an ID was found, {@code false} otherwise. */ public boolean hasAuthorID(int nr) { // retrieve element Element author = retrieveElement(authorFile, nr); // check for valid value if (author != null) { // now add id to author-element String id = author.getAttributeValue(ATTRIBUTE_AUTHOR_ID); // check for valid value if (id != null && !id.isEmpty()) { return true; } } return false; }