List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * This method retrieves the searchterms for a given search-request. * /*from w ww . j ava 2s . c o m*/ * @param nr The number of the search request * @return the searchterms as string array, or null if an error occured */ public String[] getSearchTerms(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, go on... if (el != null) { // retrieve a list with all search terms List<?> terms = el.getChild("searchterms").getChildren(); // if we have no elements, return null if ((terms.isEmpty()) || (terms.size() < 1)) { return null; } // create linked list for return results LinkedList<String> st = new LinkedList<String>(); // create iterator Iterator<?> i = terms.iterator(); // go through all search terms while (i.hasNext()) { // get each search-term-element Element e = (Element) i.next(); // if it has text, add it to linked list if (!e.getText().isEmpty()) { st.add(e.getText()); } } // when we searched for entries whithout authors or keywords e.g., the // searchterms are emptry. in this case, return null if (st.isEmpty()) { return null; } // copy all children to an array String[] retval = st.toArray(new String[st.size()]); // return results return retval; } return null; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * This method retrieves the searchterms for a given search-request. * * @param nr The number of the search request * @return {@code true} if the search was a synonym-search, false otherweise *///from w w w . ja va 2 s . co m public boolean isSynonymSearch(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, return "true" if (el != null) { // retrieve synonyms-child-element el = el.getChild("synonyms"); // if we have any element, return value if (el != null) { return (el.getText().equalsIgnoreCase("true")); } } return false; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * This method retrieves the reg-ex-state, i.e. whether a search contained regular expressions * as search terms or "normal" search terms * * @param nr The number of the search request * @return {@code true} if the search was a regular-expression-search, false otherweise *//*from www .j a va 2 s. co m*/ public boolean isRegExSearch(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, return "true" if (el != null) { // retrieve synonyms-child-element el = el.getChild("regex"); // if we have any element, return value if (el != null) { return (el.getText().equalsIgnoreCase("true")); } } return false; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * This method returns the searcresults (i.e. the entry-numbers of the found entries) * of a certain search-request./* w ww . j a v a2s .com*/ * * @param nr the number of the search request which results we want to have * @return the search-results (i.e. the entry-numbers of the found entries) as int-array, or {@code null} * if an error occured */ public int[] getSearchResults(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, go on... if (el != null) { // get all results and split them into an array String[] r = el.getChild("results").getText().split(","); // create integer array int[] retval = new int[r.length]; try { // go through string-array and convert each string to integer for (int cnt = 0; cnt < r.length; cnt++) { retval[cnt] = Integer.parseInt(r[cnt]); } return retval; } catch (NumberFormatException ex) { // log error Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage()); Constants.zknlogger.log(Level.WARNING, "Saved search result contained illegal entry numbers!"); // return null return null; } } return null; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * This method returns the searcresults (i.e. the entry-numbers of the found entries) * of a certain search-request.//from w ww .ja va 2s. co m * * @param nr the number of the searchrequest where we want to set the new results * @param results the new results for the searchrequest {@code nr} * @return */ public boolean setSearchResults(int nr, int[] results) { // get the element Element el = retrieveElement(nr); // if we found an element, go on... if ((el != null) && (results != null)) { // create string builder StringBuilder sb = new StringBuilder(""); // go through all results for (int r : results) { // append them to stringbuilder sb.append(String.valueOf(r)); sb.append(","); } // delete last comma if (sb.length() > 1) { sb.setLength(sb.length() - 1); } // get all results and split them into an array el.getChild("results").setText(sb.toString()); // change modified state setModified(true); // everything is ok return true; } // error occurred return false; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * Gets the short description of a certain search-request. * The position is a value from 0 to (size of xml file - 1) * /* ww w . ja v a 2 s . c o m*/ * @param nr the number of the search-requests which label/description we want to retrieve. * @return the description of the search-request as string */ public String getShortDescription(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, go on... if (el != null) { String retval = el.getChild(Daten.ELEMEMT_DESCRIPTION).getText(); return retval; } return ""; }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * Sets the short description of a certain search-request. * The position {@code nr} is a value from 0 to (size of xml file - 1) * * @param nr the number of the search-requests which label/description we want to change. * @param desc the description of the search-request as string *//*from w ww . ja v a 2 s . c o m*/ public void setShortDescription(int nr, String desc) { // get the element Element el = retrieveElement(nr); // if we found an element, change description if (el != null) { el.getChild(Daten.ELEMEMT_DESCRIPTION).setText(desc); } }
From source file:de.danielluedecke.zettelkasten.database.SearchRequests.java
License:Open Source License
/** * Gets the short description of a certain search-request. * //from ww w. jav a 2s. c o m * @param nr the number of the search-requests which label/description we want to retrieve. * @return the description of the search-request as string */ public String getLongDescription(int nr) { // get the element Element el = retrieveElement(nr); // if we found an element, go on... if (el != null) { String retval = el.getChild("longdesc").getText(); return retval; } return ""; }
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;//w w w . j a v a 2 s . c om 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
/** * //from ww w . jav a 2s .c o 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; } }