Пример #1
0
  /**
   * Parses a parameters string into a given form.
   *
   * @param form The target form.
   * @param parametersString The parameters string.
   * @param characterSet The supported character encoding.
   * @param decode Indicates if the query parameters should be decoded using the given character
   *     set.
   * @param separator The separator character to append between parameters.
   */
  public static void parse(
      Form form,
      String parametersString,
      CharacterSet characterSet,
      boolean decode,
      char separator) {
    if ((parametersString != null) && !parametersString.equals("")) {
      FormReader fr = null;

      if (decode) {
        fr = new FormReader(parametersString, characterSet, separator);
      } else {
        fr = new FormReader(parametersString, separator);
      }

      fr.addParameters(form);
    }
  }
Пример #2
0
  /**
   * Parses a post into a given form.
   *
   * @param form The target form.
   * @param post The posted form.
   */
  public static void parse(Form form, Representation post) {
    if (post != null) {
      if (post.isAvailable()) {
        FormReader fr = null;
        try {
          fr = new FormReader(post);
        } catch (IOException ioe) {
          Context.getCurrentLogger()
              .log(Level.WARNING, "Unable to create a form reader. Parsing aborted.", ioe);
        }

        if (fr != null) {
          fr.addParameters(form);
        }
      } else {
        throw new IllegalStateException(
            "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
      }
    }
  }