List of usage examples for org.jdom2 Element getText
public String getText()
From source file:de.danielluedecke.zettelkasten.database.Settings.java
License:Open Source License
/** * //from w w w.jav a2 s . c o m * @return */ public boolean getLatexExportRemoveNonStandardTags() { Element el = settingsFile.getRootElement().getChild(SETTING_LATEXEXPORTREMOVENONSTANDARDTAGS); if (el != null) return el.getText().equals("1"); return false; }
From source file:de.danielluedecke.zettelkasten.database.Settings.java
License:Open Source License
/** * //from ww w . ja v a 2 s . c o m * @return */ public boolean getLatexExportStatisticTableStyle() { Element el = settingsFile.getRootElement().getChild(SETTING_LATEXEXPORTTABLESTATSTYLE); if (el != null) return el.getText().equals("1"); return false; }
From source file:de.danielluedecke.zettelkasten.database.Settings.java
License:Open Source License
/** * /*from w ww . j a v a 2 s .co m*/ * @return */ public String getLatexExportAuthorValue() { Element el = settingsFile.getRootElement().getChild(SETTING_LATEXEXPORTAUTHORVALUE); if (el != null) return el.getText(); return ""; }
From source file:de.danielluedecke.zettelkasten.database.Settings.java
License:Open Source License
/** * //from w w w . j a v a 2s.c o m * @return */ public String getLatexExportMailValue() { Element el = settingsFile.getRootElement().getChild(SETTING_LATEXEXPORTMAILVALUE); if (el != null) return el.getText(); return ""; }
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 ww w . j av a2s.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
/** * // w w w . java 2s . co 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.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 ww. j av a 2s . 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.NewEntryFrame.java
License:Open Source License
/** * This method is called when the user wants to edit an entry. Here we fill all the * components (textareas, litviews) with the related texts/list-items. *//*from ww w . j a v a2 s . c om*/ private void initFields() { // get the title and fill textfield jTextFieldTitle.setText(dataObj.getZettelTitle(entryNumber)); // get the content of that entry String text = dataObj.getZettelContent(entryNumber); // add new lines after each bullet-point, so they are display in a better overview. // usually, to avoid <br>-tags within <ul> and <li>-tags when the entry is converted // to html, an entered list will be converted to a single line, removing all new lines. // but for editing and display, it is better to have them in single lines each. text = text.replace(Constants.FORMAT_LIST_OPEN, Constants.FORMAT_LIST_OPEN + System.getProperty("line.separator")); text = text.replace(Constants.FORMAT_LIST_CLOSE, Constants.FORMAT_LIST_CLOSE + System.getProperty("line.separator")); text = text.replace(Constants.FORMAT_NUMBEREDLIST_OPEN, Constants.FORMAT_NUMBEREDLIST_OPEN + System.getProperty("line.separator")); text = text.replace(Constants.FORMAT_NUMBEREDLIST_CLOSE, Constants.FORMAT_NUMBEREDLIST_CLOSE + System.getProperty("line.separator")); text = text.replace(Constants.FORMAT_LISTITEM_CLOSE, Constants.FORMAT_LISTITEM_CLOSE + System.getProperty("line.separator")); // and set the text to the textarea jTextAreaEntry.setText(Tools.replaceUbbToUnicode(text)); // get the authors and set them to the textarea String[] authors = dataObj.getAuthors(entryNumber); // stringbuffer for temporatily saving the authors StringBuilder sb = new StringBuilder(""); // if we have any authors, go on and build author list if (authors != null) { // iterate array and add each author to the buffer, and append a new line // after each author. we use a temporary stringbuffer here, so we can // delete the last newline ("\n") which is not needed... for (String au : authors) { sb.append(au); sb.append(System.getProperty("line.separator")); } } // delete last newline-symbol if (sb.length() > 0) sb.setLength(sb.length() - (System.getProperty("line.separator").length())); // and set the string to the textarea jTextAreaAuthor.setText(sb.toString()); // retrieve the current keywords String[] kws = dataObj.getKeywords(entryNumber); // prepare the JList which will display the keywords keywordListModel.clear(); // check whether any keywords have been found if (kws != null) { // sort keywords if (kws.length > 0) Arrays.sort(kws); // iterate the string array and add its content to the list model for (String kw : kws) keywordListModel.addElement(kw); } // get the remarks of that entry text = dataObj.getRemarks(entryNumber); // and set the text to the textarea jTextAreaRemarks.setText(Tools.replaceUbbToUnicode(text)); // empty the JList with hyperlinks linkListModel.clear(); // now retrieve the (hyper-)links of an entry hyperlinks = dataObj.getAttachments(entryNumber); // if we have (hyper-)links, continue if (hyperlinks != null && hyperlinks.size() > 0) { // iterare the child elements of the hyperlinks. these were // passed as parameter as a List-type Iterator<?> iterator = hyperlinks.iterator(); while (iterator.hasNext()) { // first, copy the element of the list to an own variable Element link = (Element) iterator.next(); // if it's not an empty element, add it to the JListView if (!link.getText().isEmpty()) linkListModel.addElement(link.getText()); } } // finally, change title setTitle(resourceMap.getString("frametitleEdit") + " (" + String.valueOf(entryNumber) + ")"); // if we have editmode, enable apply-button setTextfieldFilled(!jTextAreaEntry.getText().isEmpty()); }
From source file:de.danielluedecke.zettelkasten.tasks.export.ExportToCsvTask.java
License:Open Source License
@Override protected Object doInBackground() { // Your Task's code here. This method runs // on a background thread, so don't reference // the Swing GUI from here. // prevent task from processing when the file path is incorrect // if no file exists, exit task if (null == filepath) { showOkMessage = false;/*www . ja v a 2s . c o m*/ return null; } // check whether file already exists if (filepath.exists()) { // file exists, ask user to overwrite it... int optionDocExists = JOptionPane.showConfirmDialog(null, resourceMap.getString("askForOverwriteFileMsg", "", filepath.getName()), resourceMap.getString("askForOverwriteFileTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE); // if the user does *not* choose to overwrite, quit... if (optionDocExists != JOptionPane.YES_OPTION) { // don't show "export was OK" message in main frame showOkMessage = false; return null; } } int contentsize; int counter; // yet everything is ok... exportOk = true; // create csv-writer and export the data try { // CSVWriter writer = new CSVWriter(new FileWriter(filepath), csvseparator); CSVWriter writer = new CSVWriter(new OutputStreamWriter(new FileOutputStream(filepath), "UTF-8"), csvseparator); // get the size of the export data, used for progressbar contentsize = exportentries.size(); // create linked list which will hold all values of one comma-separated line LinkedList<String> csvline = new LinkedList<String>(); // first of all, create a "header"-line that contains the headers/description for the parts of an entry // that should be exported if ((exportparts & Constants.EXPORT_TITLE) != 0) { csvline.add(resourceMap.getString("csvHeaderTitle")); } if ((exportparts & Constants.EXPORT_CONTENT) != 0) { csvline.add(resourceMap.getString("csvHeaderContent")); } if ((exportparts & Constants.EXPORT_AUTHOR) != 0) { csvline.add(resourceMap.getString("csvHeaderAuthor")); } if ((exportparts & Constants.EXPORT_KEYWORDS) != 0) { csvline.add(resourceMap.getString("csvHeaderKeywords")); } if ((exportparts & Constants.EXPORT_MANLINKS) != 0) { csvline.add(resourceMap.getString("csvHeaderManLinks")); } if ((exportparts & Constants.EXPORT_LUHMANN) != 0) { csvline.add(resourceMap.getString("csvHeaderLuhmann")); } if ((exportparts & Constants.EXPORT_LINKS) != 0) { csvline.add(resourceMap.getString("csvHeaderLinks")); } if ((exportparts & Constants.EXPORT_REMARKS) != 0) { csvline.add(resourceMap.getString("csvHeaderRemarks")); } if ((exportparts & Constants.EXPORT_TIMESTAMP) != 0) { csvline.add(resourceMap.getString("csvHeaderTimestamp")); } // copy linked list to string array String[] finalline = csvline.toArray(new String[csvline.size()]); // write array to csv-file writer.writeNext(finalline); // go through all elements of the data file for (counter = 0; counter < exportentries.size(); counter++) { try { // retrieve zettelnumber int zettelnummer = Integer.parseInt(exportentries.get(counter).toString()); // get the zettel-element Element zettel = dataObj.retrieveZettel(zettelnummer); // clear data-line csvline.clear(); // see whether the bit "EXPORT_TITLE" is set // in the exportparts-variabe. if so, export title if ((exportparts & Constants.EXPORT_TITLE) != 0) { csvline.add(zettel.getChild("title").getText()); } // see whether the bit "EXPORT_CONTENT" is set // in the exportparts-variabe. if so, export content if ((exportparts & Constants.EXPORT_CONTENT) != 0) { csvline.add((removeformattags) ? dataObj.getCleanZettelContent(zettelnummer) : dataObj.getZettelContent(zettelnummer)); } // see whether the bit "EXPORT_AUTHOR" is set // in the exportparts-variabe. if so, export author if ((exportparts & Constants.EXPORT_AUTHOR) != 0) { // get author strings String[] aus = dataObj.getAuthors(zettelnummer); // if we have any author, go on if (aus != null && aus.length > 0) { // create string builder for author values StringBuilder sbauthor = new StringBuilder(""); // iterate array of authors for (String a : aus) { // append author to stringbuilder sbauthor.append(a); // and add a new line sbauthor.append(System.getProperty("line.separator")); } // if we have any values in the stringbuilder, truncate last line separator if (sbauthor.length() > 1) { sbauthor.setLength( (sbauthor.length() - System.getProperty("line.separator").length())); } // finally, add author values to the csv-line csvline.add(sbauthor.toString()); } else { // else set empty string csvline.add(""); } } // see whether the bit "EXPORT_KEYWORDS" is set // in the exportparts-variabe. if so, export keywords if ((exportparts & Constants.EXPORT_KEYWORDS) != 0) { // get keywords-trings String[] kws = dataObj.getKeywords(zettelnummer, true); // if we have any author, go on if (kws != null && kws.length > 0) { // create string builder for author values StringBuilder sbkeywords = new StringBuilder(""); // iterate array of authors for (String k : kws) { // append author to stringbuilder sbkeywords.append(k); // and add a new line sbkeywords.append(System.getProperty("line.separator")); } // if we have any values in the stringbuilder, truncate last line separator if (sbkeywords.length() > 1) { sbkeywords.setLength( (sbkeywords.length() - System.getProperty("line.separator").length())); } // finally, add author values to the csv-line csvline.add(sbkeywords.toString()); } else { // else set empty string csvline.add(""); } } // see whether the bit "EXPORT_MANLINKS" is set // in the exportparts-variabe. if so, export manual links if ((exportparts & Constants.EXPORT_MANLINKS) != 0) { csvline.add(zettel.getChild(Daten.ELEMENT_MANLINKS).getText()); } // see whether the bit "EXPORT_MANLINKS" is set // in the exportparts-variabe. if so, export manual links if ((exportparts & Constants.EXPORT_LUHMANN) != 0) { csvline.add(zettel.getChild("luhmann").getText()); } // see whether the bit "EXPORT_LINKS" is set // in the exportparts-variabe. if so, export links if ((exportparts & Constants.EXPORT_LINKS) != 0) { // add the content from the data-file. we cannot use settext here, // because we might have several sub-children // get the list of all sub-children List<Element> l = dataObj.getAttachments(zettelnummer); // create an iterator Iterator<Element> i = l.iterator(); // create string builder for csv-value StringBuilder links = new StringBuilder(""); // go through loop and add all children while (i.hasNext()) { // get the child-element from the list Element el_dummy = i.next(); // and set the text to our created child element links.append(el_dummy.getText()); links.append(System.getProperty("line.separator")); } // if we have any values in the stringbuilder, truncate last line separator if (links.length() > 1) { links.setLength((links.length() - System.getProperty("line.separator").length())); } // finally, add author values to the csv-line csvline.add(links.toString()); } // see whether the bit "EXPORT_REMARKS" is set // in the exportparts-variabe. if so, export remarks if ((exportparts & Constants.EXPORT_REMARKS) != 0) { csvline.add(zettel.getChild(Daten.ELEMENT_REMARKS).getText()); } // see whether the bit "EXPORT_TIMESTAMP" is set // in the exportparts-variabe. if so, export timestamp if ((exportparts & Constants.EXPORT_TIMESTAMP) != 0) { // add timestamp to csv csvline.add(dataObj.getTimestampCreated(zettel) + ";" + dataObj.getTimestampEdited(zettel)); } // copy linked list to string array finalline = csvline.toArray(new String[csvline.size()]); // write array to csv-file writer.writeNext(finalline); // update progress bar setProgress(counter, 0, contentsize); } catch (NumberFormatException e) { // write headline to csv-file writer.writeNext(new String[] { exportentries.get(counter).toString().substring(2) }); // update progress bar setProgress(counter, 0, contentsize); } } // close outputstream writer.close(); } catch (IOException e) { // log error-message Constants.zknlogger.log(Level.SEVERE, e.getLocalizedMessage()); // and change indicator exportOk = false; } // if the user requested a bibtex-export, do this now if (exportbibtex) { // show status text msgLabel.setText(resourceMap.getString("msgBibtextExport")); // write bibtex file ExportTools.writeBibTexFile(dataObj, bibtexObj, exportentries, filepath, resourceMap); } return null; // return your result }
From source file:de.danielluedecke.zettelkasten.tasks.export.ExportToXmlTask.java
License:Open Source License
/** * // www . j ava 2 s. co m * @param counter * @return */ private Element exportEntries(int counter) { try { // retrieve zettelnumber int zettelnummer = Integer.parseInt(exportentries.get(counter).toString()); // get the zettel-element Element zettel = dataObj.retrieveZettel(zettelnummer); // create new zettel-element for our final export file Element el_zettel = new Element(Daten.ELEMENT_ZETTEL); // see whether the bit "EXPORT_TITLE" is set // in the exportparts-variabe. if so, export title if ((exportparts & Constants.EXPORT_TITLE) != 0) { // create new title element Element el = new Element(Daten.ELEMENT_TITLE); // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_TITLE).getText()); // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_CONTENT" is set // in the exportparts-variabe. if so, export content if ((exportparts & Constants.EXPORT_CONTENT) != 0) { // create new content element Element el = new Element(Daten.ELEMENT_CONTENT); // set the text from the data-file el.setText((removeformattags) ? dataObj.getCleanZettelContent(zettelnummer) : zettel.getChild(Daten.ELEMENT_CONTENT).getText()); // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_AUTHOR" is set // in the exportparts-variabe. if so, export author if ((exportparts & Constants.EXPORT_AUTHOR) != 0) { // create new content element Element el = new Element(Daten.ELEMENT_AUTHORS); // if the user wants all data in one file, get the // author string and replace the index-number with the string value if (allinone) { // first check, whether we have any keywords at all if (zettel.getChild(Daten.ELEMENT_AUTHOR).getText().isEmpty()) { // if not, set empty string el.setText(""); } else { // get the author string String[] aus = zettel.getChild(Daten.ELEMENT_AUTHOR).getText().split(","); // if we have any author, go on if (aus != null && aus.length > 0) { // iterate array for (String a : aus) { // create new child-element Element au = new Element(Daten.ELEMENT_AUTHOR); // set the text from the data-file au.setText(dataObj.getAuthor(Integer.parseInt(a))); // add child-element el.addContent(au); } } else { // else set empty string el.setText(""); } } } else { // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_AUTHOR).getText()); } // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_KEYWORDS" is set // in the exportparts-variabe. if so, export keywords if ((exportparts & Constants.EXPORT_KEYWORDS) != 0) { // create new content element Element el = new Element(Daten.ELEMENT_KEYWORD); // if the user wants all data in one file, get the // keyword string and replace the index-number with the string value if (allinone) { // first check, whether we have any keywords at all if (zettel.getChild(Daten.ELEMENT_KEYWORD).getText().isEmpty()) { // if not, set empty string el.setText(""); } else { // get the index numbers. we now have all keyword-index-numbers // as a string array. these numbers reference to the keyword-string-values // in the keyword-xml-file String[] nrs = zettel.getChild(Daten.ELEMENT_KEYWORD).getText().split(","); // if we have any author, go on if (nrs != null && nrs.length > 0) { // iterate the array for (String n : nrs) { // create new child element Element kw = new Element("keyword"); // now get the keyword string from the keyword-xml-file kw.setText(dataObj.getKeyword(Integer.parseInt(n))); // and add this subchild el.addContent(kw); } } else { // else set empty string el.setText(""); } } } else { // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_KEYWORD).getText()); } // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_MANLINKS" is set // in the exportparts-variabe. if so, export manual links if ((exportparts & Constants.EXPORT_MANLINKS) != 0) { // create new manlinks element Element el = new Element(Daten.ELEMENT_MANLINKS); // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_MANLINKS).getText()); // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_MANLINKS" is set // in the exportparts-variabe. if so, export manual links if ((exportparts & Constants.EXPORT_LUHMANN) != 0) { // create new manlinks element Element el = new Element(Daten.ELEMENT_TRAILS); // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_TRAILS).getText()); // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_LINKS" is set // in the exportparts-variabe. if so, export links if ((exportparts & Constants.EXPORT_LINKS) != 0) { // create new link element Element el = new Element(Daten.ELEMENT_ATTACHMENTS); // add the content from the data-file. we cannot use settext here, // because we might have several sub-children // get the list of all sub-children List<Element> l = zettel.getChild(Daten.ELEMENT_ATTACHMENTS).getChildren(); // create an iterator Iterator<Element> i = l.iterator(); // go through loop and add all children while (i.hasNext()) { // create child-element for our parent-element Element el_link = new Element(Daten.ELEMENT_ATTCHILD); // get the child-element from the list Element el_dummy = i.next(); // and set the text to our created child element el_link.setText(el_dummy.getText()); // add the child-element to our parent el.addContent(el_link); } // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_REMARKS" is set // in the exportparts-variabe. if so, export remarks if ((exportparts & Constants.EXPORT_REMARKS) != 0) { // create new remarks element Element el = new Element(Daten.ELEMENT_REMARKS); // set the text from the data-file el.setText(zettel.getChild(Daten.ELEMENT_REMARKS).getText()); // and add it to our final document el_zettel.addContent(el); } // see whether the bit "EXPORT_TIMESTAMP" is set // in the exportparts-variabe. if so, export timestamp if ((exportparts & Constants.EXPORT_TIMESTAMP) != 0) { // set timestamp for export element dataObj.setTimestamp(el_zettel, dataObj.getTimestampCreated(zettel), dataObj.getTimestampEdited(zettel)); } return el_zettel; } catch (NumberFormatException e) { // create new headline element Element headline = new Element("headline"); // add headline-text to it. headline.setText(exportentries.get(counter).toString().substring(2)); return headline; } }