List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:de.bund.bfr.knime.pmm.common.XmlHelper.java
License:Open Source License
public static String getString(Element el, String attr) { if (el == null || el.getAttributeValue(attr) == null || el.getAttributeValue(attr).isEmpty()) { return null; }// w w w .j a va2 s .c o m return el.getAttributeValue(attr); }
From source file:de.bund.bfr.knime.pmm.common.XmlHelper.java
License:Open Source License
public static Integer getInt(Element el, String attr) { if (el == null || el.getAttributeValue(attr) == null || el.getAttributeValue(attr).isEmpty()) { return null; }/*from www . j a va2s. c om*/ try { return Integer.valueOf(el.getAttributeValue(attr)); } catch (NumberFormatException e) { return null; } }
From source file:de.bund.bfr.knime.pmm.common.XmlHelper.java
License:Open Source License
public static Double getDouble(Element el, String attr) { if (el == null || el.getAttributeValue(attr) == null || el.getAttributeValue(attr).isEmpty()) { return null; }/*from ww w . ja va2s. co m*/ try { return Double.valueOf(el.getAttributeValue(attr)); } catch (NumberFormatException e) { return null; } }
From source file:de.bund.bfr.knime.pmm.common.XmlHelper.java
License:Open Source License
public static Boolean getBoolean(Element el, String attr) { if (el == null || el.getAttributeValue(attr) == null || el.getAttributeValue(attr).isEmpty()) { return null; }//from w w w .ja v a2 s .c o m return Boolean.valueOf(el.getAttributeValue(attr)); }
From source file:de.bund.bfr.knime.pmm.xml2table.XML2TableNodeModel.java
License:Open Source License
/** * {@inheritDoc}/*w ww . jav a 2 s . com*/ */ @Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { BufferedDataTable table = inData[0]; DataTableSpec inSpec = table.getSpec(); int columnIndex = inSpec.findColumnIndex(set.getColumn()); int n = 0; for (DataRow row : table) { PmmXmlDoc xml = createXml(row.getCell(columnIndex)); if (xml != null) { n = Math.max(n, xml.size()); } } DataTableSpec outSpec = createSpec(inSpec, n, Arrays.asList(set.getXmlElements())); BufferedDataContainer container = exec.createDataContainer(outSpec); int index = 0; for (DataRow row : table) { DataCell[] cells = new DataCell[outSpec.getNumColumns()]; for (String column : inSpec.getColumnNames()) { cells[outSpec.findColumnIndex(column)] = row.getCell(inSpec.findColumnIndex(column)); } PmmXmlDoc xml = createXml(row.getCell(columnIndex)); for (int i = 0; i < n; i++) { Element e = null; if (xml != null && i < xml.size()) { e = xml.getElementSet().get(i).toXmlElement(); } for (String element : set.getXmlElements()) { String column = createColumnName(element, i, n); if (e != null) { cells[outSpec.findColumnIndex(column)] = new StringCell(e.getAttributeValue(element)); } else { cells[outSpec.findColumnIndex(column)] = DataType.getMissingCell(); } } } exec.checkCanceled(); exec.setProgress((double) index / (double) table.size()); container.addRowToTable(new DefaultRow(row.getKey(), cells)); } container.close(); return new BufferedDataTable[] { container.getTable() }; }
From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java
License:Open Source License
/** * This methods returns the accelerator key of a given position in the xml-file * Following constants should be used as parameters:<br> * MAINKEYS<br>/*from w w w . j ava 2 s . c o m*/ * NEWENTRYKEYS<br> * DESKTOPKEYS<br> * SEARCHRESULTSKEYS<br> * * @param what uses constants, see global field definition at top of source * @param pos a valid position of an element * @return the string containing the accelerator key or an empty string if nothing was found */ public String getAcceleratorAction(int what, int pos) { // retrieve the element Element acckey = retrieveElement(what, pos); // return the matching string value of the element String retval; // if the element was not found, return an empty string if (null == acckey) { retval = ""; } // else the value (i.e. the accelerator key string) else { retval = acckey.getAttributeValue("action"); } return retval; }
From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java
License:Open Source License
/** * This method sets an accelerator key of an related action. To change an accelerator key, * provide the action's name and the keystroke-value as string parameters. furthermore, we * have to tell the method, to which file the changes should be applied (param what). * //ww w. j a v a 2 s.c o m * Following constants should be used as parameters:<br> * MAINKEYS<br> * NEWENTRYKEYS<br> * DESKTOPKEYS<br> * SEARCHRESULTSKEYS<br> * * @param what (uses constants, see global field definition at top of source) * @param action (the action's name, as string, e.g. "newEntry") * @param keystroke (the keystroke, e.g. "ctrl N" (win/linux) or "meta O" (mac) */ public void setAccelerator(int what, String action, String keystroke) { // create a list of all elements from the xml file try { List<?> elementList = getDocument(what).getRootElement().getContent(); // and an iterator for the loop below Iterator<?> iterator = elementList.iterator(); // counter for the return value if a found element attribute matches the parameter int cnt = 1; // iterate loop while (iterator.hasNext()) { // retrieve each single element Element acckey = (Element) iterator.next(); // if action-attribute matches the parameter string... if (action.equals(acckey.getAttributeValue("action"))) { // ...set the new keystroke acckey.setText(keystroke); // and leave method return; } // else increase counter cnt++; } } catch (IllegalStateException e) { Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage()); } }
From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java
License:Open Source License
/** * This method looks for the occurence of the attribute "attr". All elements of * an xml-file are searched for the given attribute. If an element contains that * atrtribut, the method returns true, false otherwise. * //from w w w .j a v a 2 s.c o m * @param doc (the xml-document where to look for the attribute) * @param attr (the attribute we want to find) * @return {@code true} if we have an element that contains that attribute, false otherwise */ private boolean findElement(int what, String attr) { // create a list of all elements from the acceleratorkeys xml file try { List<?> elementList = getDocument(what).getRootElement().getContent(); // if we have any elements at all, go on if (elementList.size() > 0) { // and an iterator for the loop below Iterator<?> iterator = elementList.iterator(); // iterate loop while (iterator.hasNext()) { // retrieve each single element Element entry = (Element) iterator.next(); // try to get the requested element String sv = entry.getAttributeValue("action"); // if it exists, return true if (sv != null && sv.equals(attr)) { return true; } } // if no attribute was found, return false return false; } else { return false; } } catch (IllegalStateException e) { return false; } }
From source file:de.danielluedecke.zettelkasten.database.AcceleratorKeys.java
License:Open Source License
/** * This method looks for the occurence of the attribute "attr". All elements of * an xml-file are searched for the given attribute. If an element contains that * atrtribut, it is returned.//from w ww . j av a2 s.c o m * * @param doc the xml-document where to look for the attribute * @param attr the attribute (i.e. the action's name) we want to find * @return the element which matches the given action-name {@code attr} inside the document {@code doc}, * or null if no match was found */ private Element retrieveElement(int what, String attr) { // create a list of all elements from the acceleratorkeys xml file try { List<?> elementList = getDocument(what).getRootElement().getContent(); // if we have any elements at all, go on if (elementList.size() > 0) { // and an iterator for the loop below Iterator<?> iterator = elementList.iterator(); // iterate loop while (iterator.hasNext()) { // retrieve each single element Element entry = (Element) iterator.next(); // try to get the requested element String sv = entry.getAttributeValue("action"); // if it exists, return true if (sv != null && sv.equals(attr)) { return entry; } } } return null; } catch (IllegalStateException e) { return null; } }
From source file:de.danielluedecke.zettelkasten.database.AutoKorrektur.java
License:Open Source License
/** * Checks whether the value passed by the parameter "e" already exists in the * data. Therefore, each element's id-attribute is compared to the parameter "e". * @param e the string we want to look for if it exists * @return {@code true} if we found it, false if it doesn't exist *///from w w w .java 2 s. c o m public boolean exists(String e) { // get all elements List<Element> all = autokorrektur.getRootElement().getChildren(); // create an iterator Iterator<Element> i = all.iterator(); // go through list while (i.hasNext()) { // get element Element el = i.next(); // get attribute String att = el.getAttributeValue("id"); // if the element's id equals the requestes string "e", return true // i.e. the string e already exists as element if (att != null && att.equalsIgnoreCase(e)) { return true; } } // nothing found... return false; }