Ejemplo n.º 1
0
  /**
   * Adds a regular text parameter to the set of text parameters for this request. Handles the case
   * of multiple values for the same parameter by using an array for the parameter value.
   *
   * @param request The request in which the parameter was specified.
   * @param item The file item for the parameter to add.
   */
  public void addTextParameter(RequestWrapper request, FileItem item) {

    String name = item.getFieldName();
    String value = null;
    boolean haveValue = false;
    String encoding = request.getCharacterEncoding();

    if (encoding != null) {
      try {
        value = item.getString(encoding);
        haveValue = true;
      } catch (Exception e) {
        // Handled below, since haveValue is false.
      }
    }
    if (!haveValue) {
      try {
        value = item.getString("ISO-8859-1");
      } catch (java.io.UnsupportedEncodingException uee) {
        value = item.getString();
      }
      haveValue = true;
    }

    String[] oldArray = (String[]) request.getParameterValues(name);
    String[] newArray;

    if (oldArray != null) {
      newArray = new String[oldArray.length + 1];
      System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
      newArray[oldArray.length] = value;
    } else {
      newArray = new String[] {value};
    }

    request.addParameter(name, newArray);
  }