コード例 #1
0
  @Override
  public String toString() {
    LeoMap obj = new LeoMap();
    obj.putByString("contents", this.contents);
    obj.putByString("pathParams", this.pathParams);
    obj.putByString("params", LeoObject.valueOf(this.request.getParameterMap()));
    obj.putByString("method", LeoString.valueOf(this.request.getMethod()));
    obj.putByString("requestUri", LeoString.valueOf(this.request.getRequestURI()));

    return obj.toString();
  }
コード例 #2
0
  /**
   * @return attempts to return all of the {@link Part} data if and only if this is a <code>
   *     multipart/form-data</code> request.
   */
  public LeoArray parts() {
    LeoArray results = new LeoArray();
    try {
      for (Part part : this.request.getParts()) {
        results.add(LeoObject.valueOf(part));
      }
    } catch (Exception ignore) {
    }

    return results;
  }
コード例 #3
0
  /**
   * Attempts to save any {@link Part}'s to the specified directory.
   *
   * @param directory the directory in which to save the files to
   * @return the array of {@link File}'s that were saved
   * @throws IOException
   */
  public LeoArray save(String directory) throws IOException {
    LeoArray result = new LeoArray();
    try {
      File parentFolder = new File(directory);
      if (!parentFolder.exists()) {
        if (!parentFolder.mkdirs()) {
          throw new IOException("Unable to create directory structure: " + directory);
        }
      }

      for (Part part : this.request.getParts()) {
        String filename = Util.getFileName(part);
        File file = new File(parentFolder, filename);
        Util.writeFile(file, part.getInputStream());

        result.add(LeoObject.valueOf(file));
      }
    } catch (ServletException ignore) {
      // not a multipart/form-data request
    }

    return result;
  }