List of usage examples for org.jdom2 Element getName
public String getName()
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method updates the timestamp-attributes when the datafile is being updated due to * a newer file-version.<br><br> * This method is called when updating a file with version number 3.0 or 3.1 to 3.2 and higher. * * @param e the initial element, where the updating should start. usually, use something * like {@link #getDesktopElement(int) getDesktopElement(int)}. *//*from w w w . j a va 2 s. com*/ private void updateTimestamps(Element e) { // get a list with all children of the element List<Element> children = e.getChildren(); // create an iterator Iterator<Element> it = children.iterator(); DecimalFormat df = new DecimalFormat("00000"); // go through all children while (it.hasNext()) { // get the child e = it.next(); try { if (e.getName().equals(ELEMENT_ENTRY)) { String timestamp = e.getAttributeValue(ATTR_TIMESTAMP); if (timestamp != null) e.setAttribute(ATTR_TIMESTAMP, timestamp.concat(df.format(timestampid++))); } if (e.getName().equals(ELEMENT_BULLET)) { e.setAttribute(ATTR_TIMESTAMP, Tools.getTimeStamp() + df.format(timestampid++)); e.setAttribute("treefold", TREE_FOLDING_EXPANDED); } } catch (IllegalNameException ex) { Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage()); } catch (IllegalDataException ex) { Constants.zknlogger.log(Level.SEVERE, ex.getLocalizedMessage()); } // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (hasChildren(e)) { updateTimestamps(e); } } }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method retrieves the comment of an entry-element which <i>timestamp</i>-attribute * matches the parameter {@code t}.//from ww w . j a va2s.co m * * @param e the initial element where the search starts. usually, use * {@link #getCurrentDesktopElement() getCurrentDesktopElement()} fo this. * @param t the timestamp which should match the timestamp-attribute of the entry-element * @param c the comment as string. when initially calling this method, pass an empty string * as parameter * @return the comment as string, or an emtpy string if no comment was found */ private String findEntryComment(Element e, String t, String c) { // check for valid string if (null == c) return ""; // check for valid comment. if we already found a comment, // return it if (!c.isEmpty()) return c; // 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(); // check whether element has a timestamp value at all, and if it matches the parameter "t". if (e.getAttributeValue(ATTR_TIMESTAMP) != null && e.getAttributeValue(ATTR_TIMESTAMP).equals(t)) { // 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); return (comel != null) ? comel.getText() : ""; } else { // else return the element's text return e.getText(); } } // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (hasChildren(e)) { c = findEntryComment(e, t, c); } } return c; }
From source file:de.danielluedecke.zettelkasten.DesktopFrame.java
License:Open Source License
/** * This method updates the jTreeView. Each time an update for the treevuew is needed, this * method is called. It then recursevly traverses all XML-Elements of the currently activated * desktop-element, where the starting desktop-element is passed in the parameter {@code e}. * <br><br>//from ww w .j a v a 2s. c o m * The method retrieves each element, checks whether the element is an entry- or a bullet-element, * than either, in case of a bullet point, uses the name-attribute as node-name and appends the * timestamp-attribute as ID; or it retrieves the entry's title from the entry-number that is stored * in each entry-element, and appends the entry's timestamp-attribute as ID. * <br><br> * After that, the node is inserted in the jTree. * * @param e * @param n * @param dtm */ private void fillChildren(Element e, DefaultMutableTreeNode n, DefaultTreeModel dtm) { // 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(); // create a new node DefaultMutableTreeNode node; // we have to ignore the comment-tags here. comments are no tags that will // be displayed in the jtree, but that store comments which will be displayed // in the jeditorpane (see "updateDisplay" method for further details) if (!e.getName().equals("comment")) { // if the child is a bullet... if (e.getName().equals("bullet")) { // create new stringbuilder StringBuilder sb = new StringBuilder(""); // append name of bullet point sb.append(e.getAttributeValue("name")); // // and append unique id, which is the element's timestamp // sb.append(" [id#").append(e.getAttributeValue("timestamp")).append("]"); // // create a node with the element's name-attribute // node = new DefaultMutableTreeNode(sb.toString()); // create a node with the element's name-attribute node = new DefaultMutableTreeNode( new TreeUserObject(sb.toString(), e.getAttributeValue("timestamp"), "")); // and tell node to have children node.setAllowsChildren(true); } else { // now we know we have an entry. so get the entry number... int nr = Integer.parseInt(e.getAttributeValue("id")); // get the zettel title String title = TreeUtil.retrieveNodeTitle(dataObj, settingsObj.getShowDesktopEntryNumber(), String.valueOf(nr)); // create a new node node = new DefaultMutableTreeNode( new TreeUserObject(title, e.getAttributeValue("timestamp"), String.valueOf(nr))); // and tell node not to have children node.setAllowsChildren(false); } // add new node to treeview dtm.insertNodeInto(node, n, n.getChildCount()); // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (desktopObj.hasChildren(e)) { fillChildren(e, node, dtm); } } } }
From source file:de.danielluedecke.zettelkasten.DesktopFrame.java
License:Open Source License
/** * This method retrieves all entries on the desktop and adds their number to the * list {@code liste}. This array of entry-numbers is needed in the export-dialog. * * @param e the starting point for the jTree-enumeration, either the root elementor a bullet (if only * a bullet should be exported, see {@link #exportDesktopBullet() exportDesktopBullet()}). * @param liste an array-object that will hold the found entry-nubers *//* w w w. java 2 s. c o m*/ private void createExportEntries(Element e, ArrayList<Object> liste) { // if we have no element, return. if (null == e) return; // 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(); // we have to ignore the comment-tags here. comments are no tags that will // be displayed in the jtree, but that store comments which will be displayed // in the jeditorpane (see "updateDisplay" method for further details) if (!e.getName().equals("comment")) { // if the child is a bullet... if (e.getName().equals("bullet")) { // first, we want to retrieve the header-level int headerlevel = 1; // get bullet's parent Element f = e.getParentElement(); // as long as we have not reached the root, get further parent-elements // and increase counter for header-level while (!f.isRootElement()) { f = f.getParentElement(); headerlevel++; } // add the element's name-attribute. since headers might consist of only numbers, // we add a char here. this is necessary, since the export-methods distinguish // between headers and entry-numbers simply by parsing integer-values. if the parsing // succeeds, we have an entry, if a NumberFormatException is thrown, we have a headline. // to treat headline with numbers only as headlines, we add a char to be sure that every // headline will throw an exception when parsing the array's elements to integer. liste.add("h" + String.valueOf(headerlevel) + e.getAttributeValue("name")); } else { // now we know we have an entry. so get the entry number... int nr = Integer.parseInt(e.getAttributeValue("id")); liste.add(nr); } // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (desktopObj.hasChildren(e)) { createExportEntries(e, liste); } } } }
From source file:de.danielluedecke.zettelkasten.util.Tools.java
License:Open Source License
/** * This method prepares a message that tells the user which entries already appear in the desktop, and * at which position. the complete message is returned as string. * * @param list a linked list which contains the multiple-entry-data. see * {@link #retrieveDoubleEntries(zettelkasten.CDesktopData, java.util.LinkedList) retrieveDoubleEntries(zettelkasten.CDesktopData, java.util.LinkedList)} * for more details on how this parameter is created. use the return result of this method as this parameter * @return a string with the message which entries are at which position in the desktop-data, or {@code null} * if no occurences appear.// w w w . j a v a 2s .co m */ public static String prepareDoubleEntriesMessage(List<Object[]> list) { // retrieve system's line-separator String lineseparator = System.getProperty("line.separator"); // get an iterator for the multiple entries and check // whether we have any multiple occurences at all. if yes, // tell the user about that Iterator<Object[]> i = list.iterator(); // prepare a string builder that will contain the information-message in case // we have any multiple occurences of entries... StringBuilder multipleOccurencesMessage = new StringBuilder(""); // go through all entries of the linked list and check // whether we have found anything while (i.hasNext()) { // get element Object[] desktopdata = i.next(); // if second element in array is not null, we have a match. now retrieve // the entry's data, so we can inform the user about the // entry's details... if (desktopdata[1] != null) { // retrieve desktop name String dn = resourceMap.getString("multipleOccurencesDesktop") + " " + (String) desktopdata[0]; StringBuilder dnsl = new StringBuilder(""); // now we add a separator line, so check length of string for (int dnl = 0; dnl < dn.length(); dnl++) dnsl.append("-"); // first, append desktop-name multipleOccurencesMessage.append(dn).append(lineseparator); multipleOccurencesMessage.append(dnsl.toString()).append(lineseparator); // now retrieve the elements... List<Element> elements = (ArrayList<Element>) desktopdata[1]; // create iterator for each found element Iterator<Element> entryIterator = elements.iterator(); // go through the found entries in that desktop while (entryIterator.hasNext()) { // get each found entry as element Element entry = entryIterator.next(); // get the timestamp of the found entry String timestamp = entry.getAttributeValue("timestamp"); // get the entrynumber of the found entry String id = entry.getAttributeValue("id"); // create a linked list that will hold the path to the desktop List<String> path = new ArrayList<String>(); // as long as the found element has parents, we have path-elements/information // to add... while (entry.getParentElement() != null) { // retrieve parent-element entry = entry.getParentElement(); // if it's a bullet, add the path-name to our path-list if (entry.getName().equals("bullet")) { path.add(0, entry.getAttributeValue("name")); } } // now we can prepare the output string... multipleOccurencesMessage.append( resourceMap.getString("multipleOccurencesMsg", id, getProperDate(timestamp, false))); multipleOccurencesMessage.append(lineseparator) .append(resourceMap.getString("multipleOccurencesLevel")).append(" "); // go through the path-list and append all path-elements, so the user // knows where to find the entry for (int cnt = 0; cnt < path.size(); cnt++) { // add path multipleOccurencesMessage.append(path.get(cnt)); // as long as we have a path-element left, append a separating comma if (cnt < path.size() - 1) { multipleOccurencesMessage.append(" >>> "); } } // append two line-separators for the next element... multipleOccurencesMessage.append(lineseparator).append(lineseparator); } } } // delete the last two trailing lineseparators if (multipleOccurencesMessage.length() > 0) { multipleOccurencesMessage.setLength(multipleOccurencesMessage.length() - 2 * lineseparator.length()); } // if we have any content, return string. else return null return (multipleOccurencesMessage.length() > 0) ? multipleOccurencesMessage.toString() : null; }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
License:Apache License
private void propagateNamespace(Element element) { List children = element.getChildren(); for (Object o : children) { Element child = (Element) o; if (child.getName().equals("raise")) { child.setNamespace(Namespace.getNamespace("ca", "http://www.dfki.de/mmds/scxml/customaction")); } else {//from w ww .j a v a 2 s . c o m child.setNamespace(element.getNamespace()); } propagateNamespace(child); } }
From source file:de.hbrs.oryx.yawl.converter.handler.oryx.OryxDecompositionHandler.java
License:Open Source License
private Hashtable<String, String> convertParameterAttributes(final JSONObject jsonParam) throws ConversionException, JSONException { Hashtable<String, String> hashTable = new Hashtable<String, String>(); if (jsonParam.has("attributes") && !jsonParam.getString("attributes").isEmpty()) { Document attributes = YAWLUtils.parseToElement(jsonParam.getString("attributes")); for (Object obj : attributes.getContent()) { if (obj instanceof Element) { Element element = (Element) obj; hashTable.put(element.getName(), element.getText()); } else { getContext().addConversionWarnings("Attribute is not a JDOM Element", null); }/*from w w w .j a v a 2s . co m*/ } } return hashTable; }
From source file:de.herm_detlef.java.application.io.Import.java
License:Apache License
private static void createNode(Element child) { List<Element> children = child.getChildren(); if (children.isEmpty()) { switch (TAG.getValueOf(child.getName())) { case ID:/*w w w.j a va 2 s . c om*/ exerciseItem.setItemId(Integer.parseInt(child.getTextTrim())); break; case TEXT: { final String str = child.getTextTrim(); if (isQuestionPart) { exerciseItem.addQuestionText(str); } else if (isAnswerPart) { Attribute mark = child .getAttribute(ApplicationConstants.NAME_OF_XML_ATTRIBUTE_ANSWER_TEXT_MARK); if (mark != null) { try { exerciseItem.addAnswerText(str, mark.getBooleanValue()); } catch (DataConversionException e) { Utilities.showErrorMessage(e.getClass().getSimpleName(), e.getMessage()); assert false : String.format("DataConversionException: %s", mark.toString()); // TODO exerciseItem.addAnswerText(str, false); } } else { exerciseItem.addAnswerText(str, false); } } else if (isSolutionPart) { exerciseItem.addSolutionText(str); } break; } case CODE: if (isQuestionPart) { exerciseItem.addQuestionCode(child.getTextTrim()); } break; case TEXT2: if (isQuestionPart) { exerciseItem.addQuestionText2(child.getTextTrim()); } break; case CATALOG: // TODO empty catalog file break; default: assert false : String.format("%s", TAG.getValueOf(child.getName()).name()); // TODO } return; } for (Element aChild : children) { switch (TAG.getValueOf(aChild.getName())) { case ITEM: exerciseItem = new ExerciseItem(); exerciseItemList.add(exerciseItem); break; case QUESTION: signalQuestion(); break; case SINGLE_CHOICE_ANSWER: signalSingleChoiceAnswer(); exerciseItem.createSingleChoiceModel(); break; case MULTIPLE_CHOICE_ANSWER: signalMultipleChoiceAnswer(); exerciseItem.createMultipleChoiceModel(); break; case SOLUTION: signalSolution(); break; case ID: case TEXT: case CODE: case TEXT2: break; default: assert false : String.format("%s", TAG.getValueOf(aChild.getName()).name()); // TODO } createNode(aChild); } }
From source file:de.ing_poetter.binview.BinaryFormat.java
License:Open Source License
public static BinaryFormat loadFromFile(final File f) { final SAXBuilder builder = new SAXBuilder(); Document doc;//w w w . j a v a 2s.co m try { doc = builder.build(f); Element root = null; root = doc.getRootElement(); if (false == ROOT_ELEMENT_NAME.equalsIgnoreCase(root.getName())) { System.err.println("Format has invalid root Element of " + root.getName()); return null; } final BinaryFormat res = new BinaryFormat(); final List<Element> vars = root.getChildren(); for (int i = 0; i < vars.size(); i++) { final Element curVar = vars.get(i); final Variable v = VariableFactory.createVariableFrom(curVar); res.addVariable(v); } return res; } catch (final JDOMException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } return null; }
From source file:de.ing_poetter.binview.variables.VariableFactory.java
License:Open Source License
public static Variable createVariableFrom(final Element curVar) { if (null == curVar) { return null; }/*from w w w. ja v a 2 s . co m*/ final String type = curVar.getName(); if (true == "bool".equals(type)) { return new BooleanVariable(curVar); } else if (true == "int".equals(type)) { return new IntegerVariable(curVar); } else { return null; } }