Ejemplo n.º 1
0
 @RequestMapping("/ftp/o_save.do")
 public String save(Ftp bean, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateSave(bean, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   bean = manager.save(bean);
   log.info("save Ftp id={}", bean.getId());
   cmsLogMng.operating(request, "ftp.log.save", "id=" + bean.getId() + ";name=" + bean.getName());
   return "redirect:v_list.do";
 }
Ejemplo n.º 2
0
 @RequestMapping("/ftp/o_delete.do")
 public String delete(Integer[] ids, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateDelete(ids, request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   Ftp[] beans = manager.deleteByIds(ids);
   for (Ftp bean : beans) {
     log.info("delete Ftp id={}", bean.getId());
     cmsLogMng.operating(
         request, "ftp.log.delete", "id=" + bean.getId() + ";name=" + bean.getName());
   }
   return list(pageNo, request, model);
 }
Ejemplo n.º 3
0
 @RequestMapping("/ftp/o_update.do")
 public String update(Ftp bean, Integer pageNo, HttpServletRequest request, ModelMap model) {
   WebErrors errors = validateUpdate(bean.getId(), request);
   if (errors.hasErrors()) {
     return errors.showErrorPage(model);
   }
   // 留空不修改
   if (StringUtils.isBlank(bean.getPassword())) {
     bean.setPassword(manager.findById(bean.getId()).getPassword());
   }
   bean = manager.update(bean);
   log.info("update Ftp id={}.", bean.getId());
   cmsLogMng.operating(
       request, "ftp.log.update", "id=" + bean.getId() + ";name=" + bean.getName());
   return list(pageNo, request, model);
 }
Ejemplo n.º 4
0
 @RequiresPermissions("common:o_upload_image")
 @RequestMapping("/common/o_upload_image.do")
 public String execute(
     String filename,
     Integer uploadNum,
     Boolean mark,
     @RequestParam(value = "uploadFile", required = false) MultipartFile file,
     HttpServletRequest request,
     ModelMap model) {
   WebCoreErrors errors = validateImage(file, request);
   if (errors.hasErrors()) {
     model.addAttribute(ERROR, errors.getErrors().get(0));
     return RESULT_PAGE;
   }
   CmsSite site = CmsUtils.getSite(request);
   MarkConfig conf = site.getConfig().getMarkConfig();
   if (mark == null) {
     mark = conf.getOn();
   }
   String origName = file.getOriginalFilename();
   String ext = FilenameUtils.getExtension(origName).toLowerCase(Locale.ENGLISH);
   try {
     String fileUrl;
     if (site.getConfig().getUploadToDb()) {
       String dbFilePath = site.getConfig().getDbFileUri();
       if (!StringUtils.isBlank(filename)) {
         filename = filename.substring(dbFilePath.length());
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl = dbFileMng.storeByFilename(filename, new FileInputStream(tempFile));
           tempFile.delete();
         } else {
           fileUrl = dbFileMng.storeByFilename(filename, file.getInputStream());
         }
       } else {
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl =
               dbFileMng.storeByExt(site.getUploadPath(), ext, new FileInputStream(tempFile));
           tempFile.delete();
         } else {
           fileUrl = dbFileMng.storeByExt(site.getUploadPath(), ext, file.getInputStream());
         }
         // 加上访问地址
         fileUrl = request.getContextPath() + dbFilePath + fileUrl;
       }
     } else if (site.getUploadFtp() != null) {
       Ftp ftp = site.getUploadFtp();
       String ftpUrl = ftp.getUrl();
       if (!StringUtils.isBlank(filename)) {
         filename = filename.substring(ftpUrl.length());
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl = ftp.storeByFilename(filename, new FileInputStream(tempFile));
           tempFile.delete();
         } else {
           fileUrl = ftp.storeByFilename(filename, file.getInputStream());
         }
       } else {
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl = ftp.storeByExt(site.getUploadPath(), ext, new FileInputStream(tempFile));
           tempFile.delete();
         } else {
           fileUrl = ftp.storeByExt(site.getUploadPath(), ext, file.getInputStream());
         }
         // 加上url前缀
         fileUrl = ftpUrl + fileUrl;
       }
     } else {
       String ctx = request.getContextPath();
       if (!StringUtils.isBlank(filename)) {
         filename = filename.substring(ctx.length());
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl = fileRepository.storeByFilename(filename, tempFile);
           tempFile.delete();
         } else {
           fileUrl = fileRepository.storeByFilename(filename, file);
         }
       } else {
         if (mark) {
           File tempFile = mark(file, conf);
           fileUrl = fileRepository.storeByExt(site.getUploadPath(), ext, tempFile);
           tempFile.delete();
         } else {
           fileUrl = fileRepository.storeByExt(site.getUploadPath(), ext, file);
         }
         // 加上部署路径
         fileUrl = ctx + fileUrl;
       }
     }
     fileMng.saveFileByPath(fileUrl, origName, false);
     model.addAttribute("uploadPath", fileUrl);
     model.addAttribute("uploadNum", uploadNum);
   } catch (IllegalStateException e) {
     model.addAttribute(ERROR, e.getMessage());
     log.error("upload file error!", e);
   } catch (IOException e) {
     model.addAttribute(ERROR, e.getMessage());
     log.error("upload file error!", e);
   } catch (Exception e) {
     model.addAttribute(ERROR, e.getMessage());
     log.error("upload file error!", e);
   }
   cmsUserMng.updateUploadSize(
       CmsUtils.getUserId(request), Integer.parseInt(String.valueOf(file.getSize() / 1024)));
   return RESULT_PAGE;
 }