Ejemplo n.º 1
0
  /**
   * Used to set form fields
   *
   * @param formFields
   * @param replaceVals
   * @param removeList
   * @param addList
   * @return
   */
  public static boolean setFormParams(
      List<NameValuePairString> formFields,
      List<NameValuePairString> replaceVals,
      List<String> removeList,
      List<NameValuePairString> addList) {

    // campi da rimuovere
    if (removeList != null)
      for (NameValuePairString nvp : formFields) {
        for (String removeKey : removeList) {
          if (removeKey.equals(nvp.getKey())) {
            formFields.remove(nvp);
            continue;
          }
        }
      }

    // replace values
    if (replaceVals != null)
      for (NameValuePairString nvp : formFields) {
        for (NameValuePairString repl : replaceVals) {
          if (nvp.getKey().equals(repl.getKey())) {
            nvp.setValue(repl.getValue());
          }
        }
      }

    // addMap name value pairs
    if (addList != null)
      for (NameValuePairString nvp : addList) {
        formFields.add(nvp);
      }

    // rimuoviamo campi con chiave nulla, non so perchè ma ne pesco
    ArrayList<NameValuePairString> temp = new ArrayList<NameValuePairString>();
    for (NameValuePairString nvp : formFields) {
      if (nvp.getKey().length() > 0) {
        temp.add(nvp);
      } else {
        log.info("beccata chiave nulla, valore: " + nvp.getValue());
      }
    }
    formFields.clear();
    formFields.addAll(temp);

    return true;
  }
Ejemplo n.º 2
0
  public static Result textSelList(Element elsPar, ArrayList<String> jsoupSelectors) {
    Result res = new Result();
    Elements els;
    Elements elsTemp;

    els = elsPar.select(jsoupSelectors.remove(0));
    for (String sel : jsoupSelectors) {
      elsTemp = els.select(sel);
      if (elsTemp != null) els = elsTemp;
    }

    if (els == null || els.size() != 1) {
      log.error("jsoup selector on elements does not match 1");
      System.exit(1);
      return res.setContinua(false);
    }
    return res.setRetStr(els.get(0).text());
  }