Package org.opentides.bean

Examples of org.opentides.bean.FileInfo


   * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected ModelAndView handleRequestInternal(HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    FileInfo fileInfo = fileInfoService.load(request.getParameter("FileInfoId"));
    if (fileInfo != null) {
      File file = new File(fileInfo.getFullPath());
      if(!file.exists()) {
        _log.error("File [" + fileInfo.getFullPath() + "] not found.");
      } else {
        response.setContentType("image");
        byte[] bytes = FileCopyUtils.copyToByteArray(file);
        OutputStream outputStream = response.getOutputStream();
        outputStream.write(bytes);
View Full Code Here


      if (multipartFiles != null && !multipartFiles.isEmpty())
        // loop through all the attachments
        for (MultipartFile multipartFile : multipartFiles) {
          // check if there is anything to process
          if (multipartFile != null && !multipartFile.isEmpty()) {
            FileInfo fileInfo = new FileInfo();
            fileInfo.setFilename(multipartFile.getOriginalFilename());
            fileInfo.setFileSize(multipartFile.getSize());
            fileInfo.setFullPath(uploadPath);

            try {
              // setup the directory
              File directory;
              directory = FileUtil.createDirectory(uploadPath);
              String subdir = directory.getAbsoluteFile()
                  + File.separator
                  + DateUtil.convertShortDate(new Date());
              File subDirectory = FileUtil.createDirectory(subdir);

              String filePath = subDirectory.getAbsoluteFile()
                  + File.separator
                  + multipartFile.getOriginalFilename();

              // change filename if already existing in the given path
              // to avoid overriding of files
              if (fileInfoService.getFileInfoByFullPath(filePath) != null) {
                Long fileCnt = 1L;
                String newFilePath = subDirectory.getAbsoluteFile()
                    + File.separator + fileCnt.toString() + "_"
                    + multipartFile.getOriginalFilename();
                while (fileInfoService
                    .getFileInfoByFullPath(newFilePath) != null) {
                  fileCnt++;
                  newFilePath = subDirectory.getAbsoluteFile()
                      + File.separator + fileCnt.toString()
                      + "_"
                      + multipartFile.getOriginalFilename();
                }

                filePath = newFilePath;
                fileInfo.setOriginalFileName(multipartFile
                    .getOriginalFilename());
              }

              File uploadFile = new File(filePath);

              // update file path information
              fileInfo.setFullPath(uploadFile.getAbsolutePath());
              _log.debug("Uploading file to "
                  + fileInfo.getFullPath());
              // now copy the file
              FileUtil.copyMultipartFile(multipartFile, uploadFile);
              // add fileinfo
              if (isMultipleUpload())
                files = upload.getFiles();
View Full Code Here

   * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected ModelAndView handleRequestInternal(HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    FileInfo fileInfo = fileInfoService.load(request.getParameter("FileInfoId"));
    if (fileInfo != null) {
      File file = new File(fileInfo.getFullPath());
      if(!file.exists()) {
        _log.error("File [" + fileInfo.getFullPath() + "] not found.");
      } else {
        response.setHeader(
            "Content-disposition",
            "attachment; filename=" + fileInfo.getFilename());
       
        byte[] bytes = FileCopyUtils.copyToByteArray(file);
        OutputStream outputStream = response.getOutputStream();
        outputStream.write(bytes);
        outputStream.flush();   
View Full Code Here

      HttpServletResponse response, DynamicReport command, BindException errors) {
    try {
      List<FileInfo> jasperFiles = processUpload(request, response,
          command, errors, "jasperFile");
      if (jasperFiles != null && !jasperFiles.isEmpty()) {
        FileInfo jasperFile = jasperFiles.get(0);
        File jasperPath = new File(jasperFile.getFullPath());
        command.setReportPath(jasperPath.getParent());
      }
    } catch (IOException e) {
      String message = "Unable to upload jasper file.";
      _log.error(message, e);
View Full Code Here

TOP

Related Classes of org.opentides.bean.FileInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.