public static ArrayList<String> getUsedFqnFromHits(String xmlResultInString) { ArrayList<String> usedFqns = new ArrayList<String>(); Document doc = XMLParser.parse(xmlResultInString); NodeList _arrs = doc.getElementsByTagName("arr"); for (int i = 0; i < _arrs.getLength(); i++) { Node _arr = _arrs.item(i); NamedNodeMap _nnm = _arr.getAttributes(); if (_nnm != null) { Node _nameNode = _nnm.getNamedItem("name"); if (_nameNode != null) { String _nodeType = _nameNode.getNodeValue(); if (_nodeType.equals("lib_use_fqn_full") || _nodeType.equals("jdk_use_fqn_full") || _nodeType.equals("local_use_fqn_full")) { NodeList _fqns = _arr.getChildNodes(); for (int j = 0; j < _fqns.getLength(); j++) { Node _fqn = _fqns.item(j); if (_fqn.getNodeName().equals("str")) { String _usedFqn = _fqn.getFirstChild().getNodeValue(); usedFqns.add(_usedFqn); } } } } } } return usedFqns; }
public void onResponseReceived(Request request, Response response) { try { String s = Utils.getXmlNodeValue(XMLParser.parse(response.getText()), TAG_BLOBSTORE); blobstore = "true".equalsIgnoreCase(s); // with blobstore status does not make sense if (blobstore) { updateStatusTimer.setInterval(5000); } uploadForm.setAction(session.getServletPath()); uploadForm.submit(); } catch (Exception e) { String message = e.getMessage().contains("error:") ? i18nStrs.uploaderServerUnavailable() + " (3) " + getServletPath() + "\n\n" + i18nStrs.uploaderServerError() + "\nAction: " + getServletPath() + "\nException: " + e.getMessage() + response.getText() : i18nStrs.submitError(); cancelUpload(message); } }
public static ArrayList<String> getHitEidsFromHits(String xmlResultInString) { ArrayList<String> _hitEids = new ArrayList<String>(); Document doc = XMLParser.parse(xmlResultInString); NodeList hits = doc.getElementsByTagName("doc"); for (int i = 0; i < hits.getLength(); i++) { Node hit = hits.item(i); NodeList hitDocChildNodes = hit.getChildNodes(); String entity_id = ""; for (int j = 0; j < hitDocChildNodes.getLength(); j++) { Node hitDocChildNode = hitDocChildNodes.item(j); NamedNodeMap attrs = hitDocChildNode.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals("entity_id")) { entity_id = hitDocChildNode.getFirstChild().getNodeValue(); } } } _hitEids.add(entity_id); } return _hitEids; }
public void onSubmitComplete(SubmitCompleteEvent event) { updateStatusTimer.cancel(); onSubmitComplete = true; serverRawResponse = event.getResults(); if (serverRawResponse != null) { serverRawResponse = serverRawResponse.replaceFirst( ".*" + TAG_MSG_START + "([\\s\\S]*?)" + TAG_MSG_END + ".*", "$1"); serverRawResponse = serverRawResponse .replace(TAG_MSG_LT, "<") .replace(TAG_MSG_GT, ">") .replace("<", "<") .replaceAll(">", ">") .replaceAll(" ", " "); } try { // Parse the xml and extract UploadedInfos Document doc = XMLParser.parse(serverRawResponse); // If the server response is a valid xml parseAjaxResponse(serverRawResponse); } catch (Exception e) { log("onSubmitComplete exception parsing response (Check CORS and XML syntax): ", e); // Otherwise force an ajax request so as we have not to wait to the timer schedule // updateStatusTimer.run(); // how could the upload server response be corrupted ?? This // causes an error loop in my project with firefox } }
private void parseXml(String messageXml) { try { Document messageDom = XMLParser.parse(messageXml); Node customerNode = messageDom.getElementsByTagName("customer").item(0); String id = ((Element) customerNode).getAttribute("id"); idField.setText(id); String name = messageDom.getElementsByTagName("fullname").item(0).getFirstChild().getNodeValue(); nameField.setText(name); String street = messageDom.getElementsByTagName("street").item(0).getFirstChild().getNodeValue(); streetField.setText(street); String city = messageDom.getElementsByTagName("city").item(0).getFirstChild().getNodeValue(); cityField.setText(city); String state = messageDom.getElementsByTagName("state").item(0).getFirstChild().getNodeValue(); stateField.setText(state); String zip = messageDom.getElementsByTagName("zip").item(0).getFirstChild().getNodeValue(); zipField.setText(zip); } catch (DOMException e) { Window.alert("Could not parse XML document."); } }
private Element getXMLDoc() { Document d = XMLParser.createDocument(); Element root = d.createElement("PedEx"); PelicanPerson[] people = getAllPeople(); for (int i = 0; i < people.length; i++) { root.appendChild(people[i].save()); } return root; }
public void onResponseReceived(Request request, Response response) { String text = response.getText(); String url = null; Document document = null; String bpath = "<" + TAG_BLOBSTORE_PATH + ">"; String sbpath = "</" + TAG_BLOBSTORE_PATH + ">"; if (text.contains(bpath)) { try { document = XMLParser.parse(text); url = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_PATH); } catch (Exception e) { cancelUpload( i18nStrs.uploaderBlobstoreError() + "\n>>>\n" + e.getMessage() + "\n>>>>\n" + e); return; } if (url == null) { url = text.replaceAll("[\r\n]+", "") .replaceAll("^.*" + bpath + "\\s*", "") .replaceAll("\\s*" + sbpath + ".*$", ""); } } if (url != null && url.length() > 0 && !"null".equalsIgnoreCase(url)) { if (session.getServletPath().startsWith("http")) { url = session.getServletPath().replaceFirst("(https?://[^/]+).*", "$1") + url; } uploadForm.setAction(url); } else { uploadForm.setAction(session.getServletPath()); } removeHiddens(); if (document != null) { String name = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_NAME); if (name != null) { fileInput.setName(name); } NodeList list = document.getElementsByTagName(TAG_BLOBSTORE_PARAM); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); String value = Utils.getXmlNodeValue(node); if (value != null) { Node attribute = node.getAttributes().getNamedItem(ATTR_BLOBSTORE_PARAM_NAME); if (attribute != null) { String paramName = attribute.getNodeValue(); if (paramName != null) { addHidden(paramName, value); } } } } } receivedBlobPath = true; uploadForm.submit(); }
@Override public Document decode(JSONValue value) throws DecodingException { if (value == null || value.isNull() != null) { return null; } JSONString str = value.isString(); if (str == null) { throw new DecodingException("Expected a json string, but was given: " + value); } return XMLParser.parse(str.stringValue()); }
public static Payload parseMessage(String message) { final Payload payload = new Payload(); Document messageDom = XMLParser.parse(message); NodeList statements = messageDom.getElementsByTagName("com.freedomotic.reactions.Statement"); for (int i = 0; i < statements.getLength(); i++) { Element statement = (Element) statements.item(i); payload.enqueueStatement(parseStatement(statement)); } return payload; }
public void loadQueryDef(String xml) { Document doc = XMLParser.parse(xml); Element rootNode = doc.getDocumentElement(); if (!rootNode.getNodeName().equalsIgnoreCase(XmlBuilder.NODE_NAME_QUERYDEF)) return; HashMap<String, DisplayColumnWidget> displayCols = new HashMap<String, DisplayColumnWidget>(); NodeList nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_DISPLAY_FIELDS); if (nodes != null && nodes.getLength() > 0) loadDisplayFields((Element) nodes.item(0), displayCols); nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_SORT_FIELDS); if (nodes != null && nodes.getLength() > 0) loadSortFields((Element) nodes.item(0), displayCols); }
public static List<HitFqnEntityId> getUsedApisFromFacetedHits( String xmlResultInString, EntityCategory c) { // if (c.equals(EntityCategory.LOCAL)) // throw new IllegalArgumentException("only jdk or lib"); List<HitFqnEntityId> apis = new LinkedList<HitFqnEntityId>(); Document doc = XMLParser.parse(xmlResultInString); NodeList apisNodes = doc.getElementsByTagName("lst"); String nodeName; if (c.equals(EntityCategory.JDK)) nodeName = "jdk_use_fqn_full"; else if (c.equals(EntityCategory.LIB)) nodeName = "lib_use_fqn_full"; else return apis; for (int i = 0; i < apisNodes.getLength(); i++) { Node apiNode = apisNodes.item(i); NamedNodeMap attrs = apiNode.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals(nodeName)) { // iterate through int nodes NodeList fqnNodes = apiNode.getChildNodes(); for (int j = 0; j < fqnNodes.getLength(); j++) { Node fqnNode = fqnNodes.item(j); if (fqnNode.getNodeName().equals("int")) { String fqn = getAttributeValue(fqnNode, "name"); if (fqn != null) { String count = fqnNode.getFirstChild().getNodeValue(); HitFqnEntityId _apiFqn = new HitFqnEntityId(fqn, "-1", count); apis.add(_apiFqn); } } } } } } return apis; }
/** * Converts a form definition object to an XHTML document object. * * @param formDef the form definition object. * @return the xhtml document object. */ public static Document fromFormDef2XhtmlDoc(FormDef formDef) { Document prevdoc = formDef.getDoc(); Document doc = XMLParser.createDocument(); doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"")); Element htmlNode = doc.createElement("h:html"); // formDef.setXformsNode(htmlNode); htmlNode.setAttribute("xmlns:h", "http://www.w3.org/1999/xhtml"); htmlNode.setAttribute("xmlns:jr", "http://openrosa.org/javarosa"); htmlNode.setAttribute( XformConstants .XML_NAMESPACE /*XformConstants.XML_NAMESPACE_PREFIX+XformConstants.PREFIX_XFORMS*/, XformConstants.NAMESPACE_XFORMS); htmlNode.setAttribute( XformConstants.XML_NAMESPACE_PREFIX + XformConstants.PREFIX_XML_SCHEMA, XformConstants.NAMESPACE_XML_SCHEMA); doc.appendChild(htmlNode); // add head Element headNode = doc.createElement("h:head"); htmlNode.appendChild(headNode); // add title Element titleNode = doc.createElement("h:title"); titleNode.appendChild(doc.createTextNode(formDef.getName())); headNode.appendChild(titleNode); // add body Element bodyNode = doc.createElement("h:body"); htmlNode.appendChild(bodyNode); // add model Element modelNode = doc.createElement(XformConstants.NODE_NAME_MODEL); headNode.appendChild(modelNode); // we do not want to lose anything that the model could have had which we do not build when // creating an xform from scratch XformBuilder.buildXform(formDef, doc, bodyNode, modelNode); XformUtil.copyModel(prevdoc, doc); return doc; }
private static Node getResponseNode(String xmlResultInString) { Document doc = XMLParser.parse(xmlResultInString); NodeList results = doc.getElementsByTagName("result"); for (int i = 0; i < results.getLength(); i++) { Node result = results.item(i); NamedNodeMap attrs = result.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals("response")) { return result; } } } return null; }
private void parseAjaxResponse(String responseTxt) { if (responseTxt == null) { return; } String error = null; Document doc = null; try { doc = XMLParser.parse(responseTxt); error = Utils.getXmlNodeValue(doc, "error"); if (error == null) { // Response brings uploaded files info in either: // POST response or FINISHED status String msg = Utils.getXmlNodeValue(doc, TAG_MESSAGE); serverMessage.setMessage(msg); String fld = Utils.getXmlNodeValue(doc, TAG_FIELD); NodeList list = doc.getElementsByTagName(TAG_FILE); for (int i = 0, l = list.getLength(); i < l; i++) { UploadedInfo info = new UploadedInfo(); info.setField(getInputName() + "-" + i); info.setName(Utils.getXmlNodeValue(doc, TAG_NAME, i)); info.setCtype(Utils.getXmlNodeValue(doc, TAG_CTYPE, i)); // TODO: test info.setKey(Utils.getXmlNodeValue(doc, TAG_KEY, i)); // TODO: remove info.message = msg; String url = session.composeURL(PARAM_SHOW + "=" + info.getField()); if (info.getKey() != null) { url += "&" + PARAM_BLOBKEY + "=" + info.getKey(); } info.setFileUrl(url); String size = Utils.getXmlNodeValue(doc, TAG_SIZE, i); if (size != null) { info.setSize(Integer.parseInt(size)); } serverMessage.getUploadedInfos().add(info); } } } catch (Exception e) { if (responseTxt.toLowerCase().matches("error")) { error = i18nStrs.uploaderServerError() + "\nAction: " + getServletPath() + "\nException: " + e.getMessage() + responseTxt; } } if (error != null) { successful = false; cancelUpload(error); return; } else if (Utils.getXmlNodeValue(doc, TAG_WAIT) != null) { if (serverRawResponse != null) { log( "server response received, cancelling the upload " + getFileNames() + " " + serverRawResponse, null); successful = true; uploadFinished(); } } else if (Utils.getXmlNodeValue(doc, TAG_CANCELED) != null) { log("server response is: canceled " + getFileNames(), null); successful = false; canceled = true; uploadFinished(); return; } else if (Utils.getXmlNodeValue(doc, TAG_FINISHED) != null) { log("server response is: finished " + serverMessage.getUploadedFileNames(), null); successful = true; if (onSubmitComplete) { log("POST response from server has been received", null); uploadFinished(); } return; } else if (Utils.getXmlNodeValue(doc, TAG_PERCENT) != null) { lastData = now(); long transferredKB = Long.valueOf(Utils.getXmlNodeValue(doc, TAG_CURRENT_BYTES)) / 1024; long totalKB = Long.valueOf(Utils.getXmlNodeValue(doc, TAG_TOTAL_BYTES)) / 1024; statusWidget.setProgress(transferredKB, totalKB); log( "server response transferred " + transferredKB + "/" + totalKB + " " + getFileNames(), null); if (onSubmitComplete) { successful = true; // why suppose an error here in this case ? String msg = i18nStrs.uploaderBadServerResponse() + "\n" + serverRawResponse; if (blobstore) { msg += "\n" + i18nStrs.uploaderBlobstoreBilling(); } else { msg += "\n" + i18nStrs.uploaderBadParsing(); } msg += "\n\n" + responseTxt; log(msg, null); // keep log message anyway // statusWidget.setError(msg); // disable the user visible error message uploadFinished(); } return; } else { log("incorrect response: " + getFileNames() + " " + responseTxt, null); } if (uploadTimeout > 0 && now() - lastData > uploadTimeout) { successful = false; cancelUpload(i18nStrs.uploaderTimeout()); try { sendAjaxRequestToCancelCurrentUpload(); } catch (Exception e) { } } }
public String getGrade() { Document d = XMLParser.createDocument(); Element root = d.createElement("Grade"); // first, some specifications of the pedigree int numMales = 0; int numFemales = 0; int numAffectedMales = 0; int numAffectedFemales = 0; PelicanPerson[] people = getAllPeople(); for (int i = 0; i < people.length; i++) { PelicanPerson p = people[i]; if (p.sex == PelicanPerson.male) { numMales++; if (p.affection == PelicanPerson.affected) { numAffectedMales++; } } else { numFemales++; if (p.affection == PelicanPerson.affected) { numAffectedFemales++; } } } Element e = d.createElement("Counts"); Element M = d.createElement("M"); M.appendChild(d.createTextNode(String.valueOf(numMales))); e.appendChild(M); Element F = d.createElement("F"); F.appendChild(d.createTextNode(String.valueOf(numFemales))); e.appendChild(F); Element aM = d.createElement("aM"); aM.appendChild(d.createTextNode(String.valueOf(numAffectedMales))); e.appendChild(aM); Element aF = d.createElement("aF"); aF.appendChild(d.createTextNode(String.valueOf(numAffectedFemales))); e.appendChild(aF); root.appendChild(e); // now, the analysis results renumberAll(); updateDisplay(); String integrity = checkIntegrity(history.lastElement()); if (integrity.equals("")) { PedigreeSolver ps = new PedigreeSolver(getAllPeople(), getMatingList()); PedigreeSolution sol = ps.solve(); e = d.createElement("Analysis"); GenotypeSet[] results = sol.getResults(); Element AR = d.createElement("AR"); if (results[0].getAll().size() > 0) { AR.appendChild(d.createTextNode("Y")); } else { AR.appendChild(d.createTextNode("N")); } e.appendChild(AR); Element AD = d.createElement("AD"); if (results[1].getAll().size() > 0) { AD.appendChild(d.createTextNode("Y")); } else { AD.appendChild(d.createTextNode("N")); } e.appendChild(AD); Element SR = d.createElement("SR"); if (results[2].getAll().size() > 0) { SR.appendChild(d.createTextNode("Y")); } else { SR.appendChild(d.createTextNode("N")); } e.appendChild(SR); Element SD = d.createElement("SD"); if (results[3].getAll().size() > 0) { SD.appendChild(d.createTextNode("Y")); } else { SD.appendChild(d.createTextNode("N")); } e.appendChild(SD); } root.appendChild(e); return root.toString(); }
public void setState(String state) { // read in this pedigree from the xml Vector<PelicanPerson> newPedigree = new Vector<PelicanPerson>(); int pedSize = 0; Vector<Integer> pidList = new Vector<Integer>(); Vector<Integer> midList = new Vector<Integer>(); HashMap<Integer, Integer> idMap = new HashMap<Integer, Integer>(); Document doc = XMLParser.parse(state); NodeList people = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < people.getLength(); i++) { Element e = (Element) people.item(i); if (e.getTagName().equals("Person")) { int id = Integer.parseInt(e.getAttribute("Id")); int sex = Integer.parseInt(e.getAttribute("Sex")); int affection = Integer.parseInt(e.getAttribute("Affection")); String[] genotype = new String[2]; genotype[0] = "?"; genotype[1] = "?"; PelicanPerson person = new PelicanPerson(this, id, null, null, sex, affection, "", 0, genotype); newPedigree.add(person); int father = Integer.parseInt(e.getAttribute("Father")); pidList.add(new Integer(father)); int mother = Integer.parseInt(e.getAttribute("Mother")); midList.add(new Integer(mother)); idMap.put(new Integer(id), new Integer(pedSize++)); } } for (int i = 0; i < newPedigree.size(); i++) { PelicanPerson person = (PelicanPerson) newPedigree.elementAt(i); // gww if (((Integer)pidList.elementAt(i)).intValue()!=PelicanPerson.unknown) { if ((Integer) pidList.elementAt(i) != PelicanPerson.unknownID) { if (!idMap.containsKey(pidList.elementAt(i))) // gww throw(new Error("Father of subject "+String.valueOf(person.id)+" is // missing")); throw (new Error("Father of subject " + person.id + " is missing")); person.father = (PelicanPerson) newPedigree.elementAt(((Integer) idMap.get(pidList.elementAt(i))).intValue()); } // gww if (((Integer)midList.elementAt(i)).intValue()!=PelicanPerson.unknown) { if ((Integer) midList.elementAt(i) != PelicanPerson.unknownID) { if (!idMap.containsKey(midList.elementAt(i))) // gww throw(new Error("Mother of subject "+String.valueOf(person.id)+" is // missing")); throw (new Error("Mother of subject " + person.id + " is missing")); person.mother = (PelicanPerson) newPedigree.elementAt(((Integer) idMap.get(midList.elementAt(i))).intValue()); } } // figure out the generations ((PelicanPerson) newPedigree.elementAt(0)).laidOut = true; boolean someChange = true; int nperson = newPedigree.size(); // repeatedly pass through the pedigree all subjects laid out while (someChange) { someChange = false; for (int i = 0; i < nperson; i++) { PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i); if (!p.laidOut) { // try to get it from the parents for (int j = 0; j < nperson; j++) { PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j); if (parent == p.father && parent.laidOut) { p.generation = parent.generation + 1; p.laidOut = true; someChange = true; } if (parent == p.mother && parent.laidOut) { p.generation = parent.generation + 1; p.laidOut = true; someChange = true; } } } if (p.laidOut) { // assign parents generation for (int j = 0; j < nperson; j++) { PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j); if (parent == p.father && !parent.laidOut) { parent.generation = p.generation - 1; parent.laidOut = true; someChange = true; } if (parent == p.mother && !parent.laidOut) { parent.generation = p.generation - 1; parent.laidOut = true; someChange = true; } } } } } if (!checkIntegrity(newPedigree).equals("")) { return; } // end clear(); currentId = 0; for (int i = 0; i < nperson; i++) { PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i); add(p); // gww need to add in check for valid integer ID else ignore updating of currentId if (p.id > 0) { // gww if (i==0 || p.id>currentId) currentId=p.id; if (i == 0 || p.id > currentId) currentId = p.id; } } currentId++; newPedigree.removeAllElements(); updateDisplay(); }