List of usage examples for com.google.gwt.xml.client Document getElementsByTagName
NodeList getElementsByTagName(String tagname);
tagname
. From source file:ccc.client.gwt.core.GWTValidations.java
License:Open Source License
/** {@inheritDoc} */ @Override/* www .j a v a 2 s .c om*/ public String notValidXML(final String definition) { try { final Document d = XMLParser.parse(definition); final NodeList fields = d.getElementsByTagName("field"); if (fields.getLength() > 32) { return UI_CONSTANTS.tooManyFields(); } final NodeList l = d.getElementsByTagName("option"); for (int n = 0; n < l.getLength(); n++) { final NamedNodeMap al = l.item(n).getAttributes(); final Node value = al.getNamedItem("value"); if (value != null && value.getNodeValue().indexOf(',') != -1) { return "XML option value " + UI_CONSTANTS.mustNotContainComma(); } } } catch (final DOMParseException e) { return "XML " + UI_CONSTANTS.isNotValid(); } return null; }
From source file:ccc.client.gwt.widgets.EditPagePanel.java
License:Open Source License
/** * Adds necessary fields for the panel./* ww w . jav a2s . co m*/ * * @param definition XML of the definition. */ private void createFields(final String definition) { if (definition == null || definition.trim().equals("")) { return; } addStaticFields(); final Document def = XMLParser.parse(definition); final NodeList fields = def.getElementsByTagName("field"); for (int i = 0; i < fields.getLength(); i++) { final Element field = ((Element) fields.item(i)); final String type = field.getAttribute("type"); final String name = field.getAttribute("name"); final String title = field.getAttribute("title"); final String desc = field.getAttribute("description"); final String regexp = field.getAttribute("regexp"); final String vocabulary = field.getAttribute("vocabulary"); final List<Option> options = parseOptions(field); PageElement<? extends Component> pe = null; if ("text_field".equals(type)) { pe = new CCTextField(name, regexp, title, desc); } else if ("text_area".equals(type)) { pe = new CCTextAreaField(name, regexp, title, desc); } else if ("date".equals(type)) { pe = new CCDateField(name, title, desc); } else if ("html".equals(type)) { pe = new CCHtmlField(name, title, desc); } else if ("checkbox".equals(type)) { pe = new CCCheckBoxField(name, title, desc, options); } else if ("radio".equals(type)) { pe = new CCRadioField(name, title, desc, options); } else if ("combobox".equals(type)) { pe = new CCComboBoxField(name, title, desc, options); } else if ("list".equals(type)) { pe = new CCListField(name, title, desc, options); } else if ("image".equals(type)) { pe = new CCImageField(name, title, desc); } else if ("resource".equals(type)) { pe = new CCResourceField(name, title, desc, _targetRoot); } else if ("taxonomy".equals(type)) { pe = new CCTaxonomyField(name, title, desc, vocabulary, _targetRoot); } else if ("number".equals(type)) { pe = new CCNumberField(name, title, desc); } if (null != pe) { add(pe.getUI(), new FormData("95%")); _pageElements.add(pe); } } }
From source file:com.chinarewards.gwt.license.util.XmlUtil_GWT.java
public static String getSingleNodeText(Document doc, String tagName) { String itemValue = ""; if (doc != null) { NodeList nodeList = doc.getElementsByTagName(tagName); for (int i = 0; i < nodeList.getLength(); i++) { // System.out.println("node item:" + nodeList.item(i)); // System.out.println(nodeList.item(i).getFirstChild() // .getNodeValue()); // System.out.println(nodeList.item(i).toString()); itemValue = nodeList.item(i).getFirstChild().getNodeValue(); return itemValue; }//w w w . ja v a 2s.c o m } else { System.out.println("document is null..."); } return itemValue; }
From source file:com.chrome.example.helloworld.client.Monitor.java
License:Apache License
public void onModuleLoad() { FlickService pingService = GWT.create(FlickService.class); pingService.ping("flickr.photos.search", "90485e931f687a9b9c2a66bf58a3861a", "hello world", "1", "1", "relevance", "20", new RequestCallback() { public void onError(Request arg0, Throwable arg1) { }/*from ww w . j a va2s . c om*/ public void onResponseReceived(Request arg0, Response resp) { Document dom = XMLParser.parse(resp.getText()); NodeList photos = dom.getElementsByTagName("photo"); for (int i = 0; i < photos.getLength(); i++) { Element photo = (Element) photos.item(i); com.google.gwt.dom.client.Element imgElement = com.google.gwt.dom.client.Document.get() .createImageElement(); imgElement.setAttribute("src", constructImageURL(photo)); RootPanel.get().getElement().appendChild(imgElement); } } private String constructImageURL(Element photo) { return "http://farm" + photo.getAttribute("farm") + ".static.flickr.com/" + photo.getAttribute("server") + "/" + photo.getAttribute("id") + "_" + photo.getAttribute("secret") + "_s.jpg"; } }); }
From source file:com.data2semantics.yasgui.client.tab.results.input.XmlResults.java
License:Open Source License
private void storeVariables(Document xmlDoc) throws SparqlParseException, SparqlEmptyException { NodeList variables = xmlDoc.getElementsByTagName("variable"); if (variables.getLength() == 0) { throw new SparqlEmptyException("Variables missing from xml"); }/*from w ww .j av a 2 s. c o m*/ for (int i = 0; i < variables.getLength(); i++) { Node variable = variables.item(i); if (variable == null) { throw new SparqlParseException("Variable in head parsed as null"); } String varName = ((Element) variable).getAttribute("name"); if (varName == null) { throw new SparqlParseException("Variable in head has null value"); } this.variables.add(varName); } }
From source file:com.data2semantics.yasgui.client.tab.results.input.XmlResults.java
License:Open Source License
private void storeBindings(Document xmlDoc) throws SparqlParseException, SparqlEmptyException { NodeList xmlSolutions = xmlDoc.getElementsByTagName("result"); if (xmlSolutions.getLength() == 0) { throw new SparqlEmptyException("No results"); }/*from www . j a va2 s. c o m*/ //Loop through results for (int i = 0; i < xmlSolutions.getLength(); i++) { bindings.add(getSolutionFromNode(xmlSolutions.item(i))); } }
From source file:com.data2semantics.yasgui.client.tab.results.input.XmlResults.java
License:Open Source License
private void storeBooleanResult(Document xmlDoc) throws SparqlParseException { NodeList booleanNodeList = xmlDoc.getElementsByTagName("boolean"); if (booleanNodeList.getLength() == 0) { throw new SparqlParseException("Missing boolean value in xml"); }/* w ww. j a v a 2s . c om*/ if (booleanNodeList.item(0).getFirstChild().getNodeValue().equals("true")) { booleanResult = true; } else { booleanResult = false; } }
From source file:com.data2semantics.yasgui.client.tab.results.ResultContainer.java
License:Open Source License
public int detectContentType(String responseString) { int contentType = 0; try {//from ww w.ja v a 2 s. c o m JSONValue jsonValue = JSONParser.parseStrict(responseString); if (jsonValue != null) { JSONObject jsonObject = jsonValue.isObject(); JSONValue head = jsonObject.get("head"); if (head != null) { return CONTENT_TYPE_JSON; } } } catch (Exception e) { } try { Document xmlDoc = XMLParser.parse(responseString); if (xmlDoc != null && xmlDoc.getElementsByTagName("sparql").getLength() > 0) { return CONTENT_TYPE_XML; } } catch (Exception e) { } return contentType; }
From source file:com.extjs.gxt.ui.client.data.XmlReader.java
License:sencha.com license
@SuppressWarnings({ "unchecked", "rawtypes" }) public D read(Object loadConfig, Object data) { Document doc = XMLParser.parse((String) data); NodeList list = doc.getElementsByTagName(modelType.getRecordName()); ArrayList<ModelData> records = new ArrayList<ModelData>(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); Element elem = (Element) node; ModelData model = newModelInstance(); for (int j = 0; j < modelType.getFieldCount(); j++) { DataField field = modelType.getField(j); Class type = field.getType(); String name = field.getName(); String map = field.getMap() != null ? field.getMap() : field.getName(); String v = getValue(elem, map); if (v == null) continue; if (type != null) { if (type.equals(Boolean.class)) { model.set(name, Boolean.parseBoolean(v)); } else if (type.equals(Integer.class)) { model.set(name, Integer.parseInt(v)); } else if (type.equals(Long.class)) { model.set(name, Long.parseLong(v)); } else if (type.equals(Float.class)) { model.set(name, Float.parseFloat(v)); } else if (type.equals(Double.class)) { model.set(name, Double.parseDouble(v)); } else if (type.equals(Date.class)) { if ("timestamp".equals(field.getFormat())) { Date d = new Date(Long.parseLong(v) * 1000); model.set(name, d); } else { DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat()); Date d = format.parse(v); model.set(name, d); }/*from ww w . java2 s.c o m*/ } } else { model.set(field.getName(), v); } } records.add(model); } int totalCount = records.size(); Node root = doc.getElementsByTagName(modelType.getRoot()).item(0); if (root != null && modelType.getTotalName() != null) { String tot = getValue((Element) root, modelType.getTotalName()); if (tot != null) { totalCount = Integer.parseInt(tot); } } return (D) createReturnData(loadConfig, records, totalCount); }
From source file:com.flatown.client.eutils.EFetch.java
License:Apache License
protected AResult[] formatResults(Document eResult) { NodeList articleNodes = eResult.getElementsByTagName("PubmedArticle"); AResult[] results = null;//from w ww. j ava 2s . c o m if (articleNodes.getLength() > 0) { results = new AResult[articleNodes.getLength()]; Node handler; for (int i = 0; i < results.length; i++) { results[i] = new PubmedArticle(articleNodes.item(i)); } } return results; }