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 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 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."); } }
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 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; }
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 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(); }