/**
   * Constructor.
   *
   * @param formRepresentation The representation to parse.
   */
  public FormDataSet(Representation formRepresentation) {
    this();

    if ((formRepresentation != null)
        && MediaType.APPLICATION_WWW_FORM.equals(formRepresentation.getMediaType())) {
      FormUtils.parse(this.entries, formRepresentation);
    }
  }
 /**
  * Decodes form parameters that are sent double encoded by performing one decode step on their
  * values, if their restlet framework decoded value starts with an "%".
  *
  * @param request a restlet request
  * @throws IOException did not occur during tests but may.
  * @throws IllegalArgumentException if an Encode representation is received.
  */
 void decodeFormParamsIfDoubleEncoded(Request request) throws IOException {
   Representation r = request.getEntity();
   if (r instanceof EncodeRepresentation)
     throw new IllegalArgumentException(
         "Received an Encode representation."
             + " This filter must be after the Encoder filter. please check your filter chain order.");
   if (!(r instanceof EmptyRepresentation)) {
     ContentType c = new ContentType(r);
     if (MediaType.APPLICATION_WWW_FORM.equals(c.getMediaType(), true)) {
       Form form = new Form(r);
       Form newform = new Form(r);
       Map<String, String> valuesMap = form.getValuesMap();
       for (Map.Entry<String, String> e : valuesMap.entrySet()) {
         if (DBG) ThreadLocalStopwatch.now("" + e.getKey() + " - " + e.getValue());
         String shouldBeDecodedValue = e.getValue();
         if (shouldBeDecodedValue.startsWith("%")) {
           shouldBeDecodedValue = URLDecoder.decode(e.getValue(), DECODER_CHAR_SET);
           totalDecodings.incrementAndGet();
           if (DBG) {
             ThreadLocalStopwatch.now("DECODED " + request.getResourceRef());
             ThreadLocalStopwatch.now(
                 "DECODED "
                     + totalDecodings.get()
                     + " : "
                     + e.getKey()
                     + " - "
                     + shouldBeDecodedValue);
           }
         }
         newform.add(e.getKey(), shouldBeDecodedValue);
       }
       // we must always set the entity, because above getEntitiy call causes
       // NPEs later if repeated by the framework.
       request.setEntity(newform.encode(), c.getMediaType());
     }
   }
 }
Beispiel #3
0
 @Override
 protected String getMediaType() throws AmbitException {
   return MediaType.APPLICATION_WWW_FORM.toString();
 }