/**
   * Creates a response that is a copy of another response
   *
   * @param response The response to copy
   */
  public Response(Response response) {
    this._nIdResponse = response.getIdResponse();
    this._strToStringValueResponse = response.getToStringValueResponse();
    this._entry = response.getEntry();
    this._field = response.getField();
    this._strResponseValue = response.getResponseValue();
    this._nStatus = response.getStatus();

    File file = response.getFile();

    if (file != null) {
      _file = new File();
      _file.setExtension(file.getExtension());
      _file.setIdFile(file.getIdFile());
      _file.setMimeType(file.getMimeType());
      _file.setSize(file.getSize());
      _file.setTitle(file.getTitle());

      PhysicalFile physicalFile = file.getPhysicalFile();

      if (physicalFile != null) {
        PhysicalFile pfDuplicated = new PhysicalFile();
        pfDuplicated.setIdPhysicalFile(pfDuplicated.getIdPhysicalFile());
        pfDuplicated.setValue(pfDuplicated.getValue());
        _file.setPhysicalFile(pfDuplicated);
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Get a file contained in the request from the name of the parameter
   *
   * @param strFileInputName name of the file parameter of the request
   * @param request the request
   * @return file the file contained in the request with the given parameter key
   */
  private static File getFileData(String strFileInputName, HttpServletRequest request) {
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    FileItem fileItem = multipartRequest.getFile(strFileInputName);

    if ((fileItem != null)
        && (fileItem.getName() != null)
        && !EMPTY_STRING.equals(fileItem.getName())) {
      File file = new File();
      PhysicalFile physicalFile = new PhysicalFile();
      physicalFile.setValue(fileItem.get());
      file.setTitle(FileUploadService.getFileNameOnly(fileItem));
      file.setSize((int) fileItem.getSize());
      file.setPhysicalFile(physicalFile);
      file.setMimeType(FileSystemUtil.getMIMEType(FileUploadService.getFileNameOnly(fileItem)));

      return file;
    }

    return null;
  }
  /**
   * Get a generic attributes response from a file item
   *
   * @param fileItem The file item
   * @param entry The entry
   * @param bCreatePhysicalFile True to create the physical file associated with the file of the
   *     response, false otherwise. Note that the physical file will never be saved in the database
   *     by this method, like any other created object.
   * @return The created response
   */
  private Response getResponseFromFile(
      FileItem fileItem, Entry entry, boolean bCreatePhysicalFile) {
    if (fileItem instanceof GenAttFileItem) {
      GenAttFileItem genAttFileItem = (GenAttFileItem) fileItem;

      if (genAttFileItem.getIdResponse() > 0) {
        Response response = ResponseHome.findByPrimaryKey(genAttFileItem.getIdResponse());
        response.setEntry(entry);
        response.setFile(FileHome.findByPrimaryKey(response.getFile().getIdFile()));

        if (bCreatePhysicalFile) {
          response.getFile().getPhysicalFile().setValue(fileItem.get());
        }

        return response;
      }
    }

    Response response = new Response();
    response.setEntry(entry);

    File file = new File();
    file.setTitle(fileItem.getName());
    file.setSize(
        (fileItem.getSize() < Integer.MAX_VALUE) ? (int) fileItem.getSize() : Integer.MAX_VALUE);

    if (bCreatePhysicalFile) {
      file.setMimeType(FileSystemUtil.getMIMEType(file.getTitle()));

      PhysicalFile physicalFile = new PhysicalFile();
      physicalFile.setValue(fileItem.get());
      file.setPhysicalFile(physicalFile);
    }

    response.setFile(file);

    return response;
  }
Exemplo n.º 4
0
  /**
   * Initiate a download of a XSL file
   *
   * @param request The request
   * @param response The response
   * @throws IOException Throw an exception if the outputstream has error.
   */
  public void doDownloadXslExport(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    String strXslExportId = request.getParameter(PARAMETER_ID_XSL_EXPORT);

    if (strXslExportId != null) {
      int nXslExportId = Integer.parseInt(strXslExportId);
      XslExport xslExport = XslExportHome.findByPrimaryKey(nXslExportId);

      String strMimetype = xslExport.getFile().getMimeType();
      response.setContentType((strMimetype != null) ? strMimetype : "application/octet-stream");
      response.setHeader(
          "Content-Disposition",
          "attachement; filename=\"" + xslExport.getFile().getTitle() + "\"");

      OutputStream out = response.getOutputStream();
      PhysicalFile physicalFile =
          PhysicalFileHome.findByPrimaryKey(
              xslExport.getFile().getPhysicalFile().getIdPhysicalFile());
      out.write(physicalFile.getValue());
      out.flush();
      out.close();
    }
  }