List of usage examples for org.jdom2 Element getText
public String getText()
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This methods returns the author of a given position in the <b>author-datafile</b>.<br><br> * This method is used for creating the literatur list which is displayed in a * table on the JTabbedPane of the main window.<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). * //from w ww.j a v a 2s . c o m * @param pos a valid position of an element, ranged from 1 to {@link #getCount(int) getCount(AUCOUNT)} * @return the author string or an empty string if nothing was found */ public String getAuthor(int pos) { // retrieve the author element Element author = retrieveElement(authorFile, pos); // return the matching string value of the author element String retval; // check whether the element is null if (null == author) retval = ""; else retval = author.getText(); return retval; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the links of an entry. since we can have more than just one * link/hyperlink per entry, the return-value is of the type {@code List<Element>}, i.e. * we return a list of xml-elements which contain the links of an entry. * /* w ww .ja va2 s .co m*/ * @param pos the entry from which we want to retrieve the hyperlinks * @return a List of xml-Elements, or null if no links are available */ public List<Element> getAttachments(int pos) { // retrieve the entry Element entry = retrieveElement(zknFile, pos); // if no element exists, return empty array if (null == entry) return null; // retrieve list of attachments List<Element> dummy = entry.getChild(ELEMENT_ATTACHMENTS).getChildren(); List<Element> attachments = new LinkedList<Element>(); // we have to manually copy all elements from one list to the other, // so we don't change the original content. Iterator<Element> it = dummy.iterator(); // go through list while (it.hasNext()) { // retrieve element Element att = it.next(); // change separator chars String attstring = Tools.convertSeparatorChars(att.getText(), settings); // add element if (!attstring.isEmpty()) { // create new element Element e = new Element(ELEMENT_ATTCHILD); // set text e.setText(attstring); // add element to return-list attachments.add(e); } } // else return the child-elements of the links-element return attachments; }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method returns the links of an entry. since we can have more than just one * link/hyperlink per entry, the return-value is string-arra y which contain the * links of an entry.//from w ww. j a v a 2 s. c om * * @param pos the entry from which we want to retrieve the hyperlinks * @param makeLinkToAttachment {@code true} if the attachment should be linked, in case the attachment * isan existing file on the hard disk. in this case, the attachment is surrounded by "file://" references. * @return a string-array of links/attachments, or null if no links are available */ public String[] getAttachmentsAsString(int pos, boolean makeLinkToAttachment) { // retrieve the entry Element entry = retrieveElement(zknFile, pos); // if no element exists, return empty array if (null == entry) return null; // get the child-elements of the links-element List<Element> links = entry.getChild(ELEMENT_ATTACHMENTS).getChildren(); // create iterator and copy all elements to a linked list Iterator<Element> i = links.iterator(); ArrayList<String> list = new ArrayList<String>(); // copy list to array while (i.hasNext()) { // get each link-element Element e = i.next(); // get link String link = e.getText(); if (!link.isEmpty()) { // convert separator chars link = Tools.convertSeparatorChars(link, settings); // if the attachment should be linked, check whether it is an existing file // if (makeLinkToAttachment) { // TODO hier noch weitermachen? Anhnge automatsch verlinken // if (!CCommonMethods.isHyperlink(link)) { // File linkfile = CCommonMethods.getLinkFile(settings, link); // // convert all file-attachments to hyperlinks // String file = "file://"; // if (System.getProperty("os.name").toLowerCase().startsWith("windows")) file = File.separatorChar+file; // link = "<a href=\""+file+linkfile.toString()+"\">"+link+"</a>"; // } // } list.add(link); } } return list.toArray(new String[list.size()]); }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method changes attachment-values of an entry. * * @param oldAttachment the old attachment-value of the entry {@code entrynr} before it was changed * @param newAttachment the new value that should replace {@code oldAttachment} * @param entrynr the number of the entry which attachment should be changed *///from w w w. ja v a 2 s .c o m public void changeAttachment(String oldAttachment, String newAttachment, int entrynr) { // get links of entry List<Element> oldlinks = getAttachments(entrynr); // if we have any, we can go on... if (oldlinks != null && oldAttachment != null && newAttachment != null) { // create linked list that will contain the updated attachments List<String> attachments = new ArrayList<String>(); // iterator for current attachments of the entry Iterator<Element> i = oldlinks.iterator(); // go... while (i.hasNext()) { // retrieve each attachment as element Element e = i.next(); // get attachment-value String currentattachment = e.getText(); // if attachment-value equals the old value, replace it with the new value if (currentattachment.equals(oldAttachment)) currentattachment = newAttachment; // add attachment to linked list attachments.add(currentattachment); } // set links back to the entry setAttachments(entrynr, attachments.toArray(new String[attachments.size()])); } }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method deletes an attachment-value of an entry. * * @param value the attachment-value that should be removed from the entry {@code entrynr} * @param entrynr the number of the entry which attachment should be changed */// w w w . java2 s . c o m public void deleteAttachment(String value, int entrynr) { // get links of entry List<Element> oldlinks = getAttachments(entrynr); // if we have any, we can go on... if (oldlinks != null) { // create linked list that will contain the updated attachments List<String> attachments = new ArrayList<String>(); // iterator for current attachments of the entry Iterator<Element> i = oldlinks.iterator(); // go... while (i.hasNext()) { // retrieve each attachment as element Element e = i.next(); // get attachment-value String currentattachment = e.getText(); // if attachment-value does not equals the delete-value, add attachment-value to list if (!currentattachment.equals(value)) attachments.add(currentattachment); } // set links back to the entry setAttachments(entrynr, attachments.toArray(new String[attachments.size()])); // change up-to-date-value setAttachmentlistUpToDate(false); } }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method removes wrong placed edit-tags in the xml-file. this error occured in the * {@link #changeEditTimeStamp(int) changeEditTimeStamp()} method, where the edit-element, * child-element of the timestamp-element, was set as child of the zettel-element (and not its * child "timestamp"). This method tries to fix this error... *//*from w w w . ja va2 s . com*/ public void fixWrongEditTags() { // iterate all elements for (int cnt = 1; cnt <= getCount(ZKNCOUNT); cnt++) { // retrieve element Element zettel = retrieveZettel(cnt); // check for valid value if (zettel != null) { // check whether element has a child named "edited". if so, it either // has to be moved as sub-child to the child-element timestamp, or removed // if "timestamp" already has an edit-element Element edited = zettel.getChild("edited"); // only proceed, if wrong placed edited element exists if (edited != null) { // retrieve timestamp-element Element timestamp = zettel.getChild("timestamp"); // check for valid value if (timestamp != null) { // retrieve edited-timestamp Element timestampedit = timestamp.getChild("edited"); // check whether edited-element exists if (null == timestampedit) { // if timestampedit is null, the element has no edited-element // so we add the content of the wrong placed element as new edited-element // create new edited element Element ed = new Element("edited"); // add to timestamp timestamp.addContent(ed); // set content ed.setText(edited.getText()); } else { // now we know that an edited-element already exists // we now want to check whether the existing editing-timestamp // is older than the value in the wrong placed edited-element, // and if so, update the timestamp if (timestamp.getText().compareTo(edited.getText()) < 0) timestampedit.setText(edited.getText()); } } // and remove wrong edited element zettel.removeChild("edited"); } } } }
From source file:de.danielluedecke.zettelkasten.database.Daten.java
License:Open Source License
/** * This method updates the timestamp-attributes in the data base. The former * XML-elements (timestamp) with the children "created" and "edited" are from database * version 3.4 on simply stored as attribute of each element. *//*from w w w .j av a 2 s .c om*/ public void db_updateTimestampAttributes() { // iterate all elements for (int cnt = 1; cnt <= getCount(ZKNCOUNT); cnt++) { // retrieve element Element zettel = retrieveZettel(cnt); // check for valid value if (zettel != null) { // init strings with default values String created = Tools.getTimeStamp(); String edited = ""; // retrieve created-timestamp Element el = zettel.getChild("timestamp").getChild("created"); if (el != null) created = el.getText(); // retrieve edited-timestamp el = zettel.getChild("timestamp").getChild("edited"); if (el != null) edited = el.getText(); // remove old values zettel.removeChild("timestamp"); // and set timestamp as attributes setTimestamp(zettel, created, edited); } } }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
public int getCommentCount(Element e, int commentcount) { // if we don't have any element, return null if (e == null) return commentcount; // get a list with all children of the element List<Element> children = e.getChildren(); // create an iterator Iterator<Element> it = children.iterator(); // go through all children while (it.hasNext()) { // get the child e = it.next();//from w ww .j a v a 2s. c o m // else check whether we have child-elements - if so, re-call method if (hasChildren(e)) commentcount = getCommentCount(e, commentcount); // check whether we have an entry-element that matched the requested id-number if (e != null) { // check whether we have a bullet-point if (e.getName().equals(ELEMENT_BULLET)) { // if we have a bullet, return the text of it's comment-child. Element comel = e.getChild(ATTR_COMMENT); if (comel != null && !comel.getText().isEmpty()) commentcount++; } else { // else return the element's text if (!e.getText().isEmpty()) commentcount++; } } } return commentcount; }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method retrieves the content of a modified entry. the modified entries' content is stored * in a separated XML-Document (see {@link #modifiedEntries modifiedEntries}. each element of this * document has a timestamp-attribute that equals the timestamp-attribute of an entry in the * {@link #desktop desktop}-Document./*from ww w . j a v a2 s . c om*/ * <br><br> * So, by passing a {@code timestamp} value, this method searches whether we have any modified entry * that has the same timestamp-attribut, and if so, it returns the content of that element, which was * modified (and thus differs from an entry's content as it is stored in the original database). * * @param timestamp the timestamp which should match the requested entry's timestamp-attribute * @return the content of the modified entry, or {@code null} if no entry was found. */ public String retrieveModifiedEntryContentFromTimestamp(String timestamp) { // retrieve element Element retval = retrieveModifiedEntryElementFromTimestamp(timestamp); // check for content if (retval != null) return retval.getText(); // else return null return null; }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method retrieves the content of an entry (original content, not the modifications!). * <br><br>//from w w w .j a v a 2 s . co m * By passing a {@code timestamp} value, this method searches whether we have any entry * that has the same timestamp-attribut, and if so, it returns the original content of that element. * * @param timestamp the timestamp which should match the requested entry's timestamp-attribute * @return the content of the entry, or {@code null} if no entry was found. */ public String retrieveOriginalEntryContentFromTimestamp(String timestamp) { // retrieve element Element retval = findEntryElementFromTimestamp(getCurrentDesktopElement(), timestamp); // check for content if (retval != null) return retval.getText(); // else return null return null; }