List of usage examples for org.jdom2 Element getName
public String getName()
From source file:de.bund.bfr.knime.pmm.common.ParamXml.java
License:Open Source License
public ParamXml(Element el) { this(XmlHelper.getString(el, ATT_NAME), XmlHelper.getString(el, ATT_ORIGNAME), XmlHelper.getBoolean(el, ATT_IS_START), XmlHelper.getDouble(el, ATT_VALUE), XmlHelper.getDouble(el, ATT_ERROR), XmlHelper.getDouble(el, ATT_MIN), XmlHelper.getDouble(el, ATT_MAX), XmlHelper.getDouble(el, ATT_P), XmlHelper.getDouble(el, ATT_T), XmlHelper.getDouble(el, ATT_MINGUESS), XmlHelper.getDouble(el, ATT_MAXGUESS), XmlHelper.getString(el, ATT_CATEGORY), XmlHelper.getString(el, ATT_UNIT), XmlHelper.getString(el, ATT_DESCRIPTION), new HashMap<String, Double>()); for (Element e : el.getChildren()) { if (e.getName().equals(ATT_CORRELATION)) { String n = e.getAttributeValue(ATT_ORIGNAME); Double d = XmlHelper.getDouble(e, ATT_VALUE); correlations.put(n, d);// ww w . j a va 2s. co m } } }
From source file:de.bund.bfr.knime.pmm.common.PmmTimeSeries.java
License:Open Source License
public PmmTimeSeries(Element xmlElement) { super(new TimeSeriesSchema()); try {/*from w w w .j a v a2 s . c o m*/ if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_CONDID) != null) setCondId(Integer.parseInt(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_CONDID))); if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_COMBASEID) != null) setCombaseId(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_COMBASEID)); if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MATRIX) != null) setValue(TimeSeriesSchema.ATT_MATRIX, new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MATRIX))); if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_AGENT) != null) setValue(TimeSeriesSchema.ATT_AGENT, new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_AGENT))); if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MISC) != null) setValue(TimeSeriesSchema.ATT_MISC, new PmmXmlDoc(xmlElement.getAttributeValue(TimeSeriesSchema.ATT_MISC))); for (Element el : xmlElement.getChildren()) { if (el.getName().equals(ELEMENT_TSXML)) { if (el.getText() != null) { PmmXmlDoc timeSeriesXmlDoc = new PmmXmlDoc(el.getText()); this.setValue(TimeSeriesSchema.ATT_TIMESERIES, timeSeriesXmlDoc); } } else if (el.getName().equals(ELEMENT_MDINFO)) { if (el.getText() != null) { PmmXmlDoc mdInfoXmlDoc = new PmmXmlDoc(el.getText()); this.setValue(TimeSeriesSchema.ATT_MDINFO, mdInfoXmlDoc); } } else if (el.getName().equals(ELEMENT_LITMD)) { if (el.getText() != null) { PmmXmlDoc litMdDoc = new PmmXmlDoc(el.getText()); this.setValue(TimeSeriesSchema.ATT_LITMD, litMdDoc); } } } if (xmlElement.getAttributeValue(TimeSeriesSchema.ATT_DBUUID) != null) setValue(TimeSeriesSchema.ATT_DBUUID, xmlElement.getAttributeValue(TimeSeriesSchema.ATT_DBUUID)); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.bund.bfr.knime.pmm.common.PmmXmlDoc.java
License:Open Source License
private void parseElement(Element rootElement) { for (Element el : rootElement.getChildren()) { /*/*from w w w. j a v a 2 s . c o m*/ * if (el instanceof PmmXmlElementConvertable) { elementSet.add(new * ParametricModel(el)); } */ switch (el.getName()) { case ParametricModel.ELEMENT_PARAMETRICMODEL: elementSet.add(new ParametricModel(el)); break; case MiscXml.ELEMENT_MISC: elementSet.add(new MiscXml(el)); break; case ParamXml.ELEMENT_PARAM: elementSet.add(new ParamXml(el)); break; case IndepXml.ELEMENT_INDEP: elementSet.add(new IndepXml(el)); break; case DepXml.ELEMENT_DEPENDENT: elementSet.add(new DepXml(el)); break; case TimeSeriesXml.ELEMENT_TIMESERIES: elementSet.add(new TimeSeriesXml(el)); break; case MdInfoXml.ELEMENT_MDINFO: elementSet.add(new MdInfoXml(el)); break; case LiteratureItem.ELEMENT_LITERATURE: elementSet.add(new LiteratureItem(el)); break; case MLiteratureItem.ELEMENT_LITERATURE: elementSet.add(new MLiteratureItem(el)); break; case MDLiteratureItem.ELEMENT_LITERATURE: elementSet.add(new MDLiteratureItem(el)); break; case EMLiteratureItem.ELEMENT_LITERATURE: elementSet.add(new EMLiteratureItem(el)); break; case CatalogModelXml.ELEMENT_CATALOGMODEL: elementSet.add(new CatalogModelXml(el)); break; case EstModelXml.ELEMENT_ESTMODEL: elementSet.add(new EstModelXml(el)); break; case AgentXml.ELEMENT_AGENT: elementSet.add(new AgentXml(el)); break; case MDAgentXml.ELEMENT_AGENT: elementSet.add(new MDAgentXml(el)); break; case Model1AgentXml.ELEMENT_AGENT: elementSet.add(new Model1AgentXml(el)); break; case Model2AgentXml.ELEMENT_AGENT: elementSet.add(new Model2AgentXml(el)); break; case MatrixXml.ELEMENT_MATRIX: elementSet.add(new MatrixXml(el)); break; case MDMatrixXml.ELEMENT_MATRIX: elementSet.add(new MDMatrixXml(el)); break; case Model1MatrixXml.ELEMENT_MATRIX: elementSet.add(new Model1MatrixXml(el)); break; case Model2MatrixXml.ELEMENT_MATRIX: elementSet.add(new Model2MatrixXml(el)); break; case PmmTimeSeries.ELEMENT_TIMESERIES: elementSet.add(new PmmTimeSeries(el)); break; } } }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method is called from the {@link #checkForDoubleEntry(int, int) checkForDoubleEntry(int, int)} method * and used to recursivly scan all elements of a desktop. If an entry-element which id-attribute matches * the parameter {@code entrynumber} was found, this element is returned, else {@code null} is returned. * * @param e the element where we start scanning. for the first call, use {@link #getDesktopElement(int) getDesktopElement(int)} * to retrieve the root-element for starting the recursive scan. * @param entrynumber the number of the entry we are looking for. if any element's id-attribut matches this * parameter, the element is return, else null * @return an element which id-attribute matches the parameter {@code entrynumber}, or null if no element * was found//from ww w .j ava 2s. c om */ private LinkedList<Element> findElements(Element e, String entrynumber, LinkedList<Element> foundelements) { // if we don't have any element, return null if (e == null) return foundelements; // 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(); // else check whether we have child-elements - if so, re-call method if (hasChildren(e)) foundelements = findElements(e, entrynumber, foundelements); // check whether we have an entry-element that matched the requested id-number if (e != null && e.getName().equals(ELEMENT_ENTRY)) { // check whether attribute exists String att = e.getAttributeValue("id"); // if so, and it machtes the requested id-number, add element to list if (att != null && att.equals(entrynumber)) foundelements.add(e); } } return foundelements; }
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();// w ww.jav 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 recursivly scans all elements of a desktop. If an entry-element which id-attribute matches * the parameter {@code entrynumber} was found, this method returns {@code true}. * * @param e the element where we start scanning. for the first call, use {@link #getDesktopElement(int) getDesktopElement(int)} * to retrieve the root-element for starting the recursive scan. * @param entrynumber the number of the entry we are looking for. if any element's id-attribut matches this * parameter, the element is return, else null * @param found the initial value, should be {@code false} when initially called * @return {@code true} when the entry with the number {@code entrynumber} was found, {@code false} otherwise. *//*www. j av a 2 s. c o m*/ public boolean desktopHasElement(Element e, String entrynumber, boolean found) { // if we don't have any element, return null if (e == null) return false; // 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(); // else check whether we have child-elements - if so, re-call method if (hasChildren(e)) found = desktopHasElement(e, entrynumber, found); // check whether an entry was found in children if (found) return true; // check whether we have an entry-element that matched the requested id-number if (e != null && e.getName().equals(ELEMENT_ENTRY)) { // check whether attribute exists String att = e.getAttributeValue("id"); // if so, and it machtes the requested id-number, add element to list if (att != null && att.equals(entrynumber)) { // save element foundDesktopElement = e; return true; } } } return found; }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method adds a new entry (child-node) to the xml-document. * /*from w w w . j a v a 2s .com*/ * @param timestamp the timestamp of the element, where the entry "nr" should be inserted as new child * @param nr the entry-number of the entry that should be added * @param insertpos the position where the new entry should be inserted. necessary when we have already * more children and the entry should be inserted in between, at the beginning or end of the children-list. * @return the timestamp of the added entry-element as {@code String} or {@code null} if an error * occured. */ public String addEntry(String timestamp, String nr, int insertpos) { // find the bullet that is described in the treepath Element b = findEntryElementFromTimestamp(getCurrentDesktopElement(), timestamp); // if we have a valid bullet, add the new enry to the xml-file if (b != null) { // check whether element is a bullet, if not, retrieve its parent element if (!b.getName().equals(ELEMENT_BULLET)) b = b.getParentElement(); // create a new element Element e = new Element(ELEMENT_ENTRY); try { e.setAttribute("id", nr); // create timestamp String ts = Tools.getTimeStampWithMilliseconds(); // check whether timestamp already exists. this is particulary the // case when a user adds several entries at once. while (timeStampExists(ts)) ts = Tools.getTimeStampWithMilliseconds(); // add timestamp to entry element e.setAttribute(ATTR_TIMESTAMP, ts); // add new enry to the bullet at insert-position+1 (because at first // position in the bullet is always the comment) b.addContent(insertpos, e); // change modified state setModified(true); // return timestamp return ts; } catch (IllegalNameException ex) { Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage()); } catch (IllegalDataException ex) { Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage()); } catch (IllegalAddException ex) { Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage()); } } return null; }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * Sets the comment of the selected entry in the jTree in the CDesktop-frame. This method * traverses the xml-datafile, looking in each "depth-level" for the element that is * given in the linked list parameter <i>tp</i>. This parameter contains the treepath to * the selected element.//from w w w .j a v a 2s . co m * * @param timestamp * @param comment a string containing the comment * @return {@code true} if comment was successfully set, {@code false} if an error occured. */ public boolean setComment(String timestamp, String comment) { // retrieve element that matches the timestamp Element e = findEntryElementFromTimestamp(getCurrentDesktopElement(), timestamp); // check whether an entry was found or not if (e != null) { try { // 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. e.getChild(ATTR_COMMENT).setText(comment); } else { // set comment for entry e.setText(comment); } // change modified state setModified(true); } catch (IllegalDataException ex) { Constants.zknlogger.log(Level.WARNING, ex.getLocalizedMessage()); return false; } } return true; }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * /*from w w w . j av a2 s.c o m*/ * @param e */ private void retrieveDesktopEntries(Element e) { // 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(ATTR_COMMENT)) { // check whether we have no bullet, just an entry if (!e.getName().equals(ELEMENT_BULLET)) { // retrieve id-attribute String att = e.getAttributeValue("id"); // check for valid value if (att != null) { // get entry-number int enr = Integer.parseInt(att); // sort list so we can search whether entry-number already exists Collections.sort(retrieveList); // search for double entries if (Collections.binarySearch(retrieveList, enr) < 0) { // now we know we have an entry. so get the entry number... retrieveList.add(enr); } } } // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (hasChildren(e)) { retrieveDesktopEntries(e); } } } }
From source file:de.danielluedecke.zettelkasten.database.DesktopData.java
License:Open Source License
/** * This method retrieves all entries' timestamps of the element {@code e} and all its * child-element. Thus, {@code e} could either be a root-(desktop-)element or a bullet-element. * * @param e the starting-element from where we want to have all entries' timestamps, including * all children of {@code e}.//from w w w. j a v a2 s .c o m */ private void retrieveDesktopEntriesTimestamps(Element e) { // 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(ATTR_COMMENT)) { // check whether we have no bullet, just an entry if (!e.getName().equals(ELEMENT_BULLET)) { // get timestamp-attribute String att = e.getAttributeValue(ATTR_TIMESTAMP); // and add its timestamp to the list if (att != null) timestampList.add(att); } // when the new element also has children, call this method again, // so we go through the strucuture recursively... if (hasChildren(e)) { retrieveDesktopEntriesTimestamps(e); } } } }