Package org.opentides.service

Examples of org.opentides.service.FileInfoService


   * @throws IOException
   */
  protected List<FileInfo> processUpload(HttpServletRequest request,
      HttpServletResponse response, Object command, BindException errors,
      String htmlId) throws IOException {
    FileInfoService fileInfoService = (FileInfoService) this.fileInfoService;

    // are we expecting file upload?
    if (Uploadable.class.isAssignableFrom(command.getClass())
        && request instanceof MultipartHttpServletRequest) {
      List<FileInfo> files = null;
      Uploadable upload = (Uploadable) command;
      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      List<MultipartFile> multipartFiles = multipartRequest
          .getFiles(htmlId);

      // check if there is anything to process
      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()
                      + "_"
View Full Code Here

TOP

Related Classes of org.opentides.service.FileInfoService

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.