List of usage examples for com.google.gwt.xml.client Element getElementsByTagName
NodeList getElementsByTagName(String name);
name. From source file:ccc.client.gwt.widgets.EditPagePanel.java
License:Open Source License
private List<Option> parseOptions(final Element field) { final List<Option> options = new ArrayList<Option>(); final NodeList nl = field.getElementsByTagName("option"); for (int i = 0; i < nl.getLength(); i++) { final Element option = ((Element) nl.item(i)); final String def = option.getAttribute("default"); final String title = option.getAttribute("title"); final String value = option.getAttribute("value"); options.add(new Option(title, value, Boolean.valueOf("true".equals(def)))); }/*from www . j av a2 s.com*/ return options; }
From source file:com.anzsoft.client.utils.XMLHelper.java
License:Open Source License
public static Element queryTag(final Element e) { if (e == null) return null; NodeList list = e.getElementsByTagName("query"); if (list.getLength() > 0) return (Element) list.item(0); else//from ww w .ja v a2 s .c o m return null; }
From source file:com.anzsoft.client.utils.XMLHelper.java
License:Open Source License
public static Element findSubTag(final Element e, final String tagName) { if (e == null) return null; NodeList list = e.getElementsByTagName(tagName); if (list.getLength() > 0) return (Element) list.item(0); return null;/*from w ww . ja v a 2 s .c o m*/ }
From source file:com.anzsoft.client.utils.XMLHelper.java
License:Open Source License
public static ArrayList<String> getSubTagsConents(final Element e, String tagName) { ArrayList<String> groups = new ArrayList<String>(); NodeList list = e.getElementsByTagName(tagName); for (int index = 0; index < list.getLength(); index++) { Element item = (Element) list.item(index); groups.add(item.getFirstChild().getNodeValue()); }//w ww. ja v a 2s.c o m return groups; }
From source file:com.anzsoft.client.XMPP.mandioca.XmppRoster.java
License:Open Source License
private void parseRoster(String xml) { contacts.clear();/* w w w . j a v a2s . com*/ Document doc = XMLParser.parse(xml); Element query = XMLHelper.queryTag(doc.getDocumentElement()); if (query != null && query.getAttribute("xmlns").equals("jabber:iq:roster")) { NodeList itemList = query.getElementsByTagName("item"); for (int index = 0; index < itemList.getLength(); index++) { Element item = (Element) itemList.item(index); XmppContact contact = XmppContact.fromXml(item); contacts.put(contact.getJID().toString(), contact); } } if (!contacts.isEmpty()) fireOnRoster(); }
From source file:com.colinalworth.xmlview.client.ElementCell.java
License:Apache License
/** * @param parent//from ww w. j a va2 s .com * @return */ private com.google.gwt.dom.client.Element getActiveInput(com.google.gwt.dom.client.Element parent) { NodeList<com.google.gwt.dom.client.Element> elts = parent.getElementsByTagName("input"); if (elts.getLength() == 1) { return elts.getItem(0); } else { assert elts.getLength() == 2; switch (getViewData(lastKey).section) { case AttributeName: return elts.getItem(0); case AttributeValue: return elts.getItem(1); default: throw new UnsupportedOperationException(); } } }
From source file:com.flatown.client.eutils.ESearch.java
License:Apache License
/** What to do if we are going to a browser */ protected AResult[] formatResults(Document eResult) { AResult[] results = new AResult[1]; // set a result for every Id Element idListNode; if ((idListNode = (Element) getFirstNodeOfTag(eResult, "IdList")) != null) { NodeList idList = idListNode.getElementsByTagName("Id"); results = new AResult[idList.getLength() + 1]; for (int i = 0; i < idList.getLength(); i++) { results[i] = new AResult(); results[i].addLabel(makeString(idList.item(i))); }// w ww . ja va 2s .c om } // set the result for all the other info results[results.length - 1] = new AResult(); String[] otherNodes = { "Count", "RetMax", "RestStart", "TranslationSet", "QueryTranslation", "QueryKey", "WebEnv", "TranslationStack" }; Node currentNode; for (int i = 0; i < otherNodes.length; i++) { if ((currentNode = getFirstNodeOfTag(eResult, otherNodes[i])) != null) { results[results.length - 1].addLabel(makeString(currentNode)); } } return results; }
From source file:com.flatown.client.eutils.YieldsEnvironment.java
License:Apache License
/** What to do to the utilParams if we are running another utility (yields takes care of environments) * Override this to add extra parsing for the piped utility, but be sure to call the super method in order * to pass the environment.//ww w.ja v a 2s. c o m */ protected void extractParams(Document eResults) throws EntrezException { // attempt to extract the webenv and querykey Node envNode, queryKeyNode; Element idListNode; if (((envNode = getFirstNodeOfTag(eResults, "WebEnv")) != null) && ((queryKeyNode = getFirstNodeOfTag(eResults, "QueryKey")) != null)) { _utilParams.setEnv(getNodeText(envNode), Integer.parseInt(getNodeText(queryKeyNode))); } // otherwise try for an IdList else if ((idListNode = (Element) getFirstNodeOfTag(eResults, "IdList")) != null) { NodeList idList = idListNode.getElementsByTagName("Id"); String ids[] = new String[idList.getLength()]; for (int i = 0; i < idList.getLength(); i++) { ids[i] = getNodeText(idList.item(i)); } _utilParams.setEnv(ids); } }
From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcClient.java
License:Open Source License
private Object getValueNode(Node node) { if (!node.getNodeName().equals("value")) return new XmlRpcException("Value node must be named <value>, not " + "<" + node.getNodeName() + ">"); if (getElementNodeCount(node.getChildNodes()) == 0) { // If no type is indicated, the type is string. String strValue = getNodeTextValue(node); return strValue == null ? "" : strValue; }//from ww w.j a v a2s. com if (getElementNodeCount(node.getChildNodes()) != 1) return new XmlRpcException("A <value> node must have exactly one child"); Node valueType = getFirstElementChild(node); if (valueType.getNodeName().equals("i4") || valueType.getNodeName().equals("int")) { String intValueString = getNodeTextValue(valueType); if (intValueString == null) return new XmlRpcException("Integer child is not a text node"); try { return new Integer(intValueString); } catch (NumberFormatException e) { return new XmlRpcException("Value \"" + intValueString + "\" is not" + " an integer"); } } else if (valueType.getNodeName().equals("boolean")) { String boolValue = getNodeTextValue(valueType); if (boolValue == null) return new XmlRpcException("Child of <boolean> is not a text node"); if (boolValue.equals("0")) return new Boolean(false); else if (boolValue.equals("1")) return new Boolean(true); else return new XmlRpcException("Value \"" + boolValue + "\" must be 0 or 1"); } else if (valueType.getNodeName().equals("string")) { String strValue = getNodeTextValue(valueType); if (strValue == null) strValue = ""; // Make sure <string/> responses will exist as empty return strValue; } else if (valueType.getNodeName().equals("double")) { String doubleValueString = getNodeTextValue(valueType); if (doubleValueString == null) return new XmlRpcException("Child of <double> is not a text node"); try { return new Double(doubleValueString); } catch (NumberFormatException e) { return new XmlRpcException("Value \"" + doubleValueString + "\" is not a double"); } } else if (valueType.getNodeName().equals("dateTime.iso8601")) { String dateValue = getNodeTextValue(valueType); if (dateValue == null) return new XmlRpcException("Child of <dateTime> is not a text node"); try { return iso8601ToDate(dateValue); } catch (XmlRpcException e) { return new XmlRpcException(e.getMessage()); } } else if (valueType.getNodeName().equals("base64")) { String baseValue = getNodeTextValue(valueType); if (baseValue == null) return new XmlRpcException("Improper XML-RPC response format"); return new Base64(baseValue); } else if (valueType.getNodeName().equals("struct")) { @SuppressWarnings("unchecked") Map<String, Object> map = new HashMap<String, Object>(getElementNodeCount(valueType.getChildNodes())); for (int i = 0; i < valueType.getChildNodes().getLength(); i++) { if (valueType.getChildNodes().item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element memberNode = (Element) valueType.getChildNodes().item(i); String name = null; Object value = null; if (!memberNode.getNodeName().equals("member")) return new XmlRpcException("Children of <struct> may only be " + "named <member>"); // NodeList.getElementsByTagName(String) does a deep search, so we // can legally get more than one back. Therefore, if the response // has more than one <name/> and <value/> at it's highest level, // we will only process the first one it comes across. if (memberNode.getElementsByTagName("name").getLength() < 1) return new XmlRpcException("A <struct> element must contain " + "at least one <name> child"); if (memberNode.getElementsByTagName("value").getLength() < 1) return new XmlRpcException("A <struct> element must contain " + "at least one <value> child"); name = getNodeTextValue(memberNode.getElementsByTagName("name").item(0)); value = getValueNode(memberNode.getElementsByTagName("value").item(0)); if (name == null) return new XmlRpcException("The <name> element must " + "contain a string value"); map.put(name, value); } return map; } else if (valueType.getNodeName().equals("array")) { if (getElementNodeCount(valueType.getChildNodes()) != 1) return new XmlRpcException("An <array> element must contain " + "a single <data> element"); Node dataNode = getFirstElementChild(valueType); if (!dataNode.getNodeName().equals("data")) return new XmlRpcException("An <array> element must contain " + "a single <data> element"); List<Object> list = new ArrayList<Object>(); for (int i = 0; i < dataNode.getChildNodes().getLength(); i++) { Node valueNode = dataNode.getChildNodes().item(i); if (valueNode.getNodeType() != Node.ELEMENT_NODE) continue; if (!valueNode.getNodeName().equals("value")) return new XmlRpcException("Children of <data> may only be " + "<value> elements"); list.add(getValueNode(valueNode)); } return list; } else if (valueType.getNodeName().equals("nil")) { return null; } // Not sure what it was supposed to be return new XmlRpcException( "Improper XML-RPC response format:" + " Unknown node name \"" + valueType.getNodeName() + "\""); }
From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcRequest.java
License:Open Source License
@SuppressWarnings("unchecked") private T getValueNode(Node node) throws XmlRpcException { if (!node.getNodeName().equals("value")) throw new XmlRpcException("Value node must be named <value>, not " + "<" + node.getNodeName() + ">"); if (getElementNodeCount(node.getChildNodes()) == 0) { // If no type is indicated, the type is string. String strValue = getNodeTextValue(node); return (T) (strValue == null ? "" : strValue); }/* w w w .j a va2 s . c o m*/ if (getElementNodeCount(node.getChildNodes()) != 1) throw new XmlRpcException("A <value> node must have exactly one child"); Node valueType = getFirstElementChild(node); if (valueType.getNodeName().equals("i4") || valueType.getNodeName().equals("int")) { String intValueString = getNodeTextValue(valueType); if (intValueString == null) throw new XmlRpcException("Integer child is not a text node"); try { return (T) (new Integer(intValueString)); } catch (NumberFormatException e) { throw new XmlRpcException("Value \"" + intValueString + "\" is not" + " an integer"); } } else if (valueType.getNodeName().equals("boolean")) { String boolValue = getNodeTextValue(valueType); if (boolValue == null) throw new XmlRpcException("Child of <boolean> is not a text node"); if (boolValue.equals("0")) return (T) (new Boolean(false)); else if (boolValue.equals("1")) return (T) (new Boolean(true)); else throw new XmlRpcException("Value \"" + boolValue + "\" must be 0 or 1"); } else if (valueType.getNodeName().equals("string")) { String strValue = getNodeTextValue(valueType); if (strValue == null) strValue = ""; // Make sure <string/> responses will exist as empty return (T) strValue; } else if (valueType.getNodeName().equals("double")) { String doubleValueString = getNodeTextValue(valueType); if (doubleValueString == null) throw new XmlRpcException("Child of <double> is not a text node"); try { return (T) (new Double(doubleValueString)); } catch (NumberFormatException e) { throw new XmlRpcException("Value \"" + doubleValueString + "\" is not a double"); } } else if (valueType.getNodeName().equals("dateTime.iso8601")) { String dateValue = getNodeTextValue(valueType); if (dateValue == null) throw new XmlRpcException("Child of <dateTime> is not a text node"); try { return (T) iso8601ToDate(dateValue); } catch (XmlRpcException e) { throw new XmlRpcException(e.getMessage()); } } else if (valueType.getNodeName().equals("base64")) { String baseValue = getNodeTextValue(valueType); if (baseValue == null) throw new XmlRpcException("Improper XML-RPC response format"); return (T) new Base64(baseValue); } else if (valueType.getNodeName().equals("struct")) { @SuppressWarnings("unchecked") Map<String, Object> map = new HashMap<String, Object>(getElementNodeCount(valueType.getChildNodes())); for (int i = 0; i < valueType.getChildNodes().getLength(); i++) { if (valueType.getChildNodes().item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element memberNode = (Element) valueType.getChildNodes().item(i); String name = null; Object value = null; if (!memberNode.getNodeName().equals("member")) throw new XmlRpcException("Children of <struct> may only be " + "named <member>"); // NodeList.getElementsByTagName(String) does a deep search, so we // can legally get more than one back. Therefore, if the response // has more than one <name/> and <value/> at it's highest level, // we will only process the first one it comes across. if (memberNode.getElementsByTagName("name").getLength() < 1) throw new XmlRpcException("A <struct> element must contain " + "at least one <name> child"); if (memberNode.getElementsByTagName("value").getLength() < 1) throw new XmlRpcException("A <struct> element must contain " + "at least one <value> child"); name = getNodeTextValue(memberNode.getElementsByTagName("name").item(0)); value = getValueNode(memberNode.getElementsByTagName("value").item(0)); if (name == null) throw new XmlRpcException("The <name> element must " + "contain a string value"); map.put(name, value); } return (T) map; } else if (valueType.getNodeName().equals("array")) { if (getElementNodeCount(valueType.getChildNodes()) != 1) throw new XmlRpcException("An <array> element must contain " + "a single <data> element"); Node dataNode = getFirstElementChild(valueType); if (!dataNode.getNodeName().equals("data")) throw new XmlRpcException("An <array> element must contain " + "a single <data> element"); List<Object> list = new ArrayList<Object>(); for (int i = 0; i < dataNode.getChildNodes().getLength(); i++) { Node valueNode = dataNode.getChildNodes().item(i); if (valueNode.getNodeType() != Node.ELEMENT_NODE) continue; if (!valueNode.getNodeName().equals("value")) throw new XmlRpcException("Children of <data> may only be " + "<value> elements"); list.add(getValueNode(valueNode)); } return (T) list; } else if (valueType.getNodeName().equals("nil")) { return null; } // Not sure what it was supposed to be throw new XmlRpcException( "Improper XML-RPC response format:" + " Unknown node name \"" + valueType.getNodeName() + "\""); }