List of usage examples for org.jdom2 Element hasAttributes
public boolean hasAttributes()
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Find the activity named "name"//from w ww .ja v a 2s .co m * @param name The name * @param namespace The namespace * @return The found activity. null if none found. */ private Element findActivityNamed(String name, Namespace namespace) { Element result = null; List<Element> activities = this.getActivities(); for (final Element activity : activities) { // Load attribute value if (activity.hasAttributes() && activity.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, namespace).equals(name)) { result = activity; break; } } return result; }
From source file:com.tactfactory.harmony.utils.XMLUtils.java
License:Open Source License
/** * Find a node in the given node.//from ww w. java2 s. c o m * @param baseNode The node in whom to search. * @param newNode The node to search. * @param id The attribute name used for the comparison * @return The found node or null if the node doesn't exists */ public static Element findNode(final Element baseNode, final Element newNode, final String id) { Element result = null; final List<Element> nodes = baseNode.getChildren(newNode.getName()); // Look in the children nodes if one node // has the corresponding key/value couple for (final Element node : nodes) { if (node.hasAttributes() && node.getAttributeValue(id).equals(newNode.getAttributeValue(id))) { result = node; } } return result; }
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
License:Open Source License
public Map<String, Object> extractCaseParametersMapFromElement(Element element) { Map<String, Object> valuesByColumnName = new TreeMap<>(); String elementName = element.getName(); if (element.getAttribute("name") != null) { elementName = elementName + "." + element.getAttributeValue("name"); }/* ww w. ja v a2s . c o m*/ if (elementName.equals(CASE_ROOT_ELEMENT_NAME)) { for (Attribute attribute : element.getAttributes()) { String name = CaseStudyXML.CASE_ROOT_ELEMENT_NAME + "." + attribute.getName(); String value = attribute.getValue(); valuesByColumnName.put(name, value); } } if (elementName.equals(RelevanceCriteriaXML.ELEMENT_NAME)) { double threshold = RelevanceCriteriaXML.getRelevanceCriteria(element).getThreshold().doubleValue(); valuesByColumnName.put(RelevanceCriteriaXML.ELEMENT_NAME, threshold); } else if (element.getChildren().isEmpty()) { String columnName; String value; if (!element.hasAttributes()) { throw new IllegalArgumentException("arg"); } if (element.getAttribute("name") != null) { columnName = elementName; value = element.getAttributeValue("name"); } else if (element.getAttribute("parameterName") != null) { columnName = element.getAttributeValue("parameterName"); value = element.getAttributeValue("parameterValue"); } else { throw new IllegalStateException("arg"); } valuesByColumnName.put(columnName, value); } else { for (Element child : element.getChildren()) { if (child.getName().equals(AGGREGATE_VALUES_ELEMENT_NAME)) { continue; } if (child.getName().equals(EXECUTIONS_RESULTS_ELEMENT_NAME)) { throw new IllegalArgumentException("The file is a full results file!"); } Map<String, Object> extractCaseParametersMapFromElement = extractCaseParametersMapFromElement( child); for (Map.Entry<String, Object> entry : extractCaseParametersMapFromElement.entrySet()) { String columnNameWithPrefix = elementName + "." + entry.getKey(); Object value = entry.getValue(); valuesByColumnName.put(columnNameWithPrefix, value); } } } return valuesByColumnName; }
From source file:jodtemplate.pptx.style.HtmlStylizer.java
License:Apache License
private Element createTextElement(final List<org.jsoup.nodes.Element> tags, final Element arPr, final TextNode textNode, final Slide slide) { final Element ar = new Element(PPTXDocument.R_ELEMENT, getDrawingmlNamespace()); final Element formattedArPr = applyFormatting(tags, arPr, slide); if (formattedArPr.hasAttributes() || formattedArPr.getContentSize() != 0) { ar.addContent(formattedArPr);/* w w w . ja va 2 s. c o m*/ } final Element at = new Element(PPTXDocument.T_ELEMENT, getDrawingmlNamespace()); at.setText(textNode.getWholeText()); ar.addContent(at); return ar; }
From source file:org.ambientdynamix.contextplugins.lastfm.LastFMPluginRuntime.java
License:Apache License
public static Song checkForCurrentSong(String uid) { Log.d(TAG, "checkforCurrentSong"); Song x = null;//from w w w . j a va2 s . c o m String url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + uid + "&api_key=" + Constants.API_KEY; final SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(url); Element root = doc.getRootElement(); List<Element> children = root.getChildren(); Iterator<Element> childrenIterator = children.iterator(); while (childrenIterator.hasNext()) { Element child = childrenIterator.next(); //Log.d(TAG, ""+child.getName()); List<Element> grandchildren = child.getChildren(); Iterator<Element> grandchildrenIterator = grandchildren.iterator(); boolean gotit = false; while (grandchildrenIterator.hasNext()) { Element grandchild = grandchildrenIterator.next(); if (grandchild.getName().equals("track") && grandchild.hasAttributes()) { List<Element> ggclist = grandchild.getChildren(); Iterator<Element> ggcit = ggclist.iterator(); String artist = ""; String name = ""; while (ggcit.hasNext()) { Element ggc = ggcit.next(); if (ggc.getName().equals("artist")) { artist = ggc.getText(); } if (ggc.getName().equals("name")) { name = ggc.getText(); } if (ggc.getName().equals("mbid")) { if (ggc.getText().equals("")) { Log.e(TAG, "mbid is empty for some reason. This should be impossible..."); } x = songinfo(ggc.getText()); } if (ggc.getName().equals("album")) { if (x != null) { } else { x = new Song(name, artist, -999, ggc.getText(), "", ""); } } } } } } } catch (Exception e) { Log.e(TAG, "exception: " + e.getMessage()); } return x; }
From source file:org.ambientdynamix.contextplugins.lastfm.LastFMPluginRuntime.java
License:Apache License
public static ArrayList<Song> getTop100Tracks(String uid) { ArrayList<Song> top100tracks = new ArrayList<Song>(); String url = "http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=" + uid + "&api_key=" + Constants.API_KEY + "&limit=100"; final SAXBuilder builder = new SAXBuilder(); try {/* www. j a va 2s .c o m*/ Log.d(TAG, "Try"); Document doc = builder.build(url); Log.d(TAG, "2"); Element root = doc.getRootElement(); Log.d(TAG, "3"); List<Element> children = root.getChildren(); Log.d(TAG, "4"); Iterator<Element> childrenIterator = children.iterator(); Log.d(TAG, "5"); while (childrenIterator.hasNext()) { Element child = childrenIterator.next(); Log.d(TAG, "" + child.getName()); List<Element> grandchildren = child.getChildren(); Log.d(TAG, "6"); Iterator<Element> grandchildrenIterator = grandchildren.iterator(); while (grandchildrenIterator.hasNext()) { Log.d(TAG, "7"); Element grandchild = grandchildrenIterator.next(); if (grandchild.getName().equals("track") && grandchild.hasAttributes()) { List<Element> ggclist = grandchild.getChildren(); Log.d(TAG, "8"); Iterator<Element> ggcit = ggclist.iterator(); Log.d(TAG, "9"); String artist = ""; String name = ""; int playcount = 0; Log.d(TAG, "10"); while (ggcit.hasNext()) { Element ggc = ggcit.next(); if (ggc.getName().equals("artist")) { Log.d(TAG, "11"); artist = ggc.getChild("name").getText(); Log.d(TAG, "Artist=" + artist); top100tracks.add(new Song(name, artist, -999, ggc.getText(), "", playcount, "")); } if (ggc.getName().equals("name")) { Log.d(TAG, "12"); name = ggc.getText(); } if (ggc.getName().equals("playcount")) { Log.d(TAG, "14 " + ggc.getText()); playcount = Integer.parseInt(ggc.getText()); } } } } } } catch (Exception e) { Log.d(TAG, "-->"); Log.e(TAG, "exception: " + e.getMessage()); } return top100tracks; }
From source file:org.opengroup.archimate.xmlexchange.XMLModelExporter.java
License:Open Source License
/** * @return true if element has attributes or a child element *//*from www .j ava2 s . co m*/ private boolean hasElementContent(Element element) { return element != null && (element.hasAttributes() || !element.getChildren().isEmpty()); }