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;
  }
Beispiel #3
0
        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();
        }
  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;
  }
  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.");
    }
  }
Beispiel #6
0
    private void parseEntries(@Nonnull final Document document) {
      NodeList entryNodes = document.getElementsByTagName(ENTRY_TAG);

      if (entryNodes != null) {
        Node entryNode;
        for (int i = 0; i < entryNodes.getLength(); i++) {
          entryNode = entryNodes.item(i);
          assert entryNode != null;

          if (entryNode.getNodeType() == ELEMENT_NODE) {
            entries.add(new Entry(entryNodes.item(i)));
          }
        }
        Collections.reverse(entries);
      }
    }
  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;
  }
Beispiel #8
0
    /** return the text content of a tag in a xml document. */
    public static String getXmlNodeValue(Document doc, String tag) {
      if (doc == null) return null;

      NodeList list = doc.getElementsByTagName(tag);
      if (list.getLength() == 0) return null;

      Node node = list.item(0);
      if (node.getNodeType() != Node.ELEMENT_NODE) return null;

      String ret = "";
      NodeList textNodes = node.getChildNodes();
      for (int i = 0; i < textNodes.getLength(); i++) {
        Node n = textNodes.item(i);
        if (n.getNodeType() == Node.TEXT_NODE
            && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0)
          ret += n.getNodeValue();
      }
      return ret.length() == 0 ? null : ret;
    }
  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;
  }
Beispiel #10
0
  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) {
      }
    }
  }
Beispiel #11
0
 /** return the text content of a tag in the position idx inside a xml document */
 public static String getXmlNodeValue(Document doc, String tag, int idx) {
   if (doc == null) {
     return null;
   }
   return getXmlNodeValue(doc.getElementsByTagName(tag), tag, idx);
 }