List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the index numbers of an entry's keywords as an integer array * This method is used for creating the links (connection between entries based on * matching keywords), which are displayed in a table on the JTabbedPane of the main window * // w w w . j a v a 2s .c o m * @param pos (the entry's number) * @return an array of integer values (the keyword index numbers of the requested entry), or * null if no keywords exist... */ public int[] getKeywordIndexNumbers(int pos) { // first retrieve the current "zettel" element Element dummy = retrieveElement(zknFile, pos); // if no element found, return failed value if (null == dummy) return null; // if no keyword index numbers exist, return failed value if (dummy.getChild(ELEMENT_KEYWORD).getText().isEmpty()) return null; // then get the keyword indexnumbers String[] kwa = dummy.getChild(ELEMENT_KEYWORD).getText().split(","); // create a new string array return value, which will contain the keyword strings int[] retval = new int[kwa.length]; // iterate the array // convert each keyword index number into an integer value // and get the related keyword string from the keyword data file // (this is achieved by the getKeyword-Method) for (int cnt = 0; cnt < kwa.length; cnt++) retval[cnt] = Integer.parseInt(kwa[cnt]); return retval; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method sets the index numbers of an entry's keywords or authors, * the entry's reference to keyword or author values will be set. * <br><br>/* w w w .j a v a 2 s.c o m*/ * This method does neither affect the keyword- nor the author-xml-file. * * @param attr the attribut of which element should be changed. use either * {@link #ELEMENT_AUTHOR} or {@link #ELEMENT_KEYWORD}. * @param pos the entry-number of the entry, which authors/keywords should be changed * @param values a string with the keyword/author-index-numbers, separated by commas */ private void setIndexNumbers(String attr, int pos, String values) { // first retrieve the current "zettel" element Element dummy = retrieveElement(zknFile, pos); // if no element found, return failed value if (null == dummy) return; // set new keyword-index-numbers dummy.getChild(attr).setText(values); // change modified state setModified(true); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the index-numbers of an entry's authors as an integer value * //from www.java2 s . c o m * @param pos (the entry's number) * @return an integer array (the index numbers of the requested entry's authors), or null * if no author index numbers exist */ public int[] getAuthorIndexNumbers(int pos) { // first retrieve the current "zettel" element Element dummy = retrieveElement(zknFile, pos); // if no element found, return failed value if (null == dummy) return null; // if no author index numbers exist, return failed value if (dummy.getChild(ELEMENT_AUTHOR).getText().isEmpty()) return null; // then get the autors indexnumbers String[] aun = dummy.getChild(ELEMENT_AUTHOR).getText().split(","); // create a new string array return value, which will contain the authors strings int[] retval = new int[aun.length]; // iterate the array // convert each author index number into an integer value for (int cnt = 0; cnt < aun.length; cnt++) retval[cnt] = Integer.parseInt(aun[cnt]); return retval; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the title of a certain entry * /*from w w w. j a v a 2s. c o m*/ * @param pos the index number of the entry which title is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @return the title of the requested entry as a string, or an empty string if an error occured */ public String getZettelTitle(int pos) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_TITLE)) return ""; // else return title return el.getChild(ELEMENT_TITLE).getText(); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the title of a certain entry * //from w w w . j a va 2s .com * @param pos the index number of the entry which title is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @param title */ public void setZettelTitle(int pos, String title) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_TITLE)) return; try { // else change title el.getChild(ELEMENT_TITLE).setText(title); // reset title-list setTitlelistUpToDate(false); // change modified state setModified(true); } catch (IllegalDataException ex) { Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage()); } }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the content of a certain entry, i.e. * the main entry text (text excerpt or whatever). The content * is returned as it is stored in the XML-datafile. So we have * the "plain text" here, <i>with</i> format-tags, but <i>not</i> prepared * for HTML-display.<br><br> * Use {@link #getEntryAsHtml(int, java.lang.String[]) getEntryAsHtml()} * if you need the HTML-formatted entry instead.<br><br> * Use {@link #getCleanZettelContent(int) getCleanZettelContent()} if you need * the plain text entry <i>without</i> format-tags. * * @param pos the index number of the entry which content is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @return the plain, non-html-converted content of the requested entry as a string * or an empty string if no entry was found or the requested entry does not exist *//* w w w . jav a2s.c o m*/ public String getZettelContent(int pos) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_CONTENT)) return ""; // else return title return el.getChild(ELEMENT_CONTENT).getText(); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the content of a certain entry, i.e. * the main entry text (text excerpt or whatever). The content * is returned in HTML-format.<br><br> * Use {@link #getCleanZettelContent(int) getCleanZettelContent()} if you need * the plain text entry <i>without</i> format-tags. * * @param pos the index number of the entry which content is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @return the html-converted content of the requested entry as a string * or an empty string if no entry was found or the requested entry does not exist *///w ww .j a v a 2s . c o m public String getZettelContentAsHtml(int pos) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_CONTENT)) return ""; // else return entry as html return HtmlUbbUtil.convertUbbToHtml(settings, this, bibtexObj, el.getChild(ELEMENT_CONTENT).getText(), Constants.FRAME_MAIN, false, false); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the content of a certain entry, i.e. * the main entry text (text excerpt or whatever). The content * is returned as it is stored in the XML-datafile. So we have * the "plain text" here, <i>with</i> format-tags, but <i>not</i> prepared * for HTML-display.<br><br> * However, you can encode Unicode chars into its equivalent HTML entities * nby setting the parameter {@code encodeUTF} to {@code true}. This is * necessary when exporting entries to HTML or PDF. * <br><br>/*from w w w . j a va 2 s. c om*/ * Use {@link #getEntryAsHtml(int, java.lang.String[]) getEntryAsHtml()} * if you need the HTML-formatted entry instead.<br><br> * Use {@link #getCleanZettelContent(int) getCleanZettelContent()} if you need * the plain text entry <i>without</i> format-tags. * * @param pos the index number of the entry which content is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @param encodeUTF if {@code true}, unicode characters are encoded to the equivalent * HTML entities. * @return the plain, non-html-converted content of the requested entry as a string * or an empty string if no entry was found or the requested entry does not exist */ public String getZettelContent(int pos, boolean encodeUTF) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_CONTENT)) return ""; // retrieve entry's content String preparestring = el.getChild(ELEMENT_CONTENT).getText(); // create dummy-string-builder StringBuilder buf = new StringBuilder(""); // iterate each char of the string for (int i = 0; i < preparestring.length(); i++) { // retrieve char char c = preparestring.charAt(i); // if it's a normal char, append it... if ((int) c < 160) { buf.append(c); } else { // else append entity of unicode-char buf.append("&#").append((int) c).append(";"); } } // return converted string return buf.toString(); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method sets the content of a certain entry, i.e. * the main entry text (text excerpt or whatever). * * @param pos the index number of the entry which content is requested. Must be a number from 1 * to {@link #getCount(int) getCount(CDaten.ZKNCOUNT)}. * @param content the new content of the entry * @param changetimestamp {@code true} if the entry's modified-timestamp should be updated * @return {@code true} if content was successfully changed, false otherwise *///from w w w .j a v a 2 s . c o m public boolean setZettelContent(int pos, String content, boolean changetimestamp) { // retrieve the element from the main xml-file Element el = retrieveElement(zknFile, pos); // if element or child element is null, return empty string if (null == el || null == el.getChild(ELEMENT_CONTENT)) return false; // else set new content el.getChild(ELEMENT_CONTENT).setText(content); // and change timestamp if (changetimestamp) changeEditTimeStamp(pos); // change modified state setModified(true); // and tell about success... return true; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method is used in the {@link de.danielluedecke.zettelkasten.tasks.export.ExportToZknTask} class * to prepare the entries that should be exported. This method converts entry-number-references * into the related entry-IDs using the {@link #getZettelID(int) getZettelID(int)} method. * /*from www. j av a2s .c o m*/ * @param entrynumbers * @return */ public boolean createExportEntries(ArrayList<Integer> entrynumbers) { // check for valid parameter if (entrynumbers != null && entrynumbers.size() > 0) { // create "empty" XML JDom objects zknFileExport = new Document(new Element(DOCUMENT_ZETTELKASTEN)); for (Integer entrynumber : entrynumbers) { // create new zettel element // and clone content from requested zettel to our element Element zettel = (Element) retrieveZettel(entrynumber).clone(); // retrieve content of entry and convert all author footnotes, which // contain author-index-numbers, into the related author-IDs. String content = zettel.getChild(ELEMENT_CONTENT).getText(); // check for footnotes int pos = 0; while (pos != -1) { // find the html-tag for the footnote pos = content.indexOf(Constants.FORMAT_FOOTNOTE_OPEN, pos); // if we found something... if (pos != -1) { // find the closing quotes int end = content.indexOf("]", pos + 2); // if we found that as well... if (end != -1) { try { // extract footnote-number String fn = content.substring(pos + 4, end); // retrieve author ID from related footnote number try { String authorID = getAuthorID(Integer.parseInt(fn)); // replace author number with author ID inside footnote content = content.substring(0, pos + 4) + authorID + content.substring(end); } catch (NumberFormatException ex) { // log error Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage()); Constants.zknlogger.log(Level.WARNING, "Could not convert author number into author ID!"); } } catch (IndexOutOfBoundsException ex) { } // and add it to the linked list, if it doesn't already exist // set pos to new position pos = end; } else pos = pos + 4; } } // check for manual links pos = 0; while (pos != -1) { // find the html-tag for the manual link pos = content.indexOf(Constants.FORMAT_MANLINK_OPEN, pos); // if we found something... if (pos != -1) { // find the closing quotes int end = content.indexOf("]", pos + 2); // if we found that as well... if (end != -1) { try { // extract manual-link-number String ml = content.substring(pos + 3, end); // retrieve author ID from related footnote number try { String zetID = getZettelID(Integer.parseInt(ml)); // replace manual link number with entry ID content = content.substring(0, pos + 3) + zetID + content.substring(end); } catch (NumberFormatException ex) { // log error Constants.zknlogger.log(Level.WARNING, "Could not convert manual link number into related entry ID!"); } } catch (IndexOutOfBoundsException ex) { } // and add it to the linked list, if it doesn't already exist // set pos to new position pos = end; } else pos = pos + 3; } } // set back changes zettel.getChild(ELEMENT_CONTENT).setText(content); // // here we change the entry's luhmann-numbers (trailing entries) and the // entry's manual links with the unique IDs // replaceAttributeNrWithID(zettel); // add each entry-element to the export-document zknFileExport.getRootElement().addContent(zettel); } // set first and last zettel zknFileExport.getRootElement().setAttribute(ATTRIBUTE_FIRST_ZETTEL, ""); zknFileExport.getRootElement().setAttribute(ATTRIBUTE_LAST_ZETTEL, ""); return true; } return false; }