Example #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;
  }
Example #2
0
  public static String dumpNameValuePairsList(List<NameValuePairString> list) {
    String ret = "";

    for (NameValuePairString nvp : list) {
      ret += "\"" + nvp.getKey() + "\" = \"" + nvp.getValue() + "\"";
      ret += "\n";
    }
    return ret;
  }