Exemple #1
0
 /**
  * 会员文库添加
  *
  * @param request
  * @param model
  * @return
  */
 @RequestMapping(value = "/member/doc_add.jspx")
 public String add(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   CmsUser user = CmsUtils.getUser(request);
   CmsSite site = CmsUtils.getSite(request);
   FrontUtils.frontData(request, model, site);
   MemberConfig mcfg = site.getConfig().getMemberConfig();
   // 没有开启会员功能
   if (!mcfg.isMemberOn()) {
     return FrontUtils.showMessage(request, model, "member.memberClose");
   }
   if (user == null) {
     return FrontUtils.showLogin(request, model, site);
   }
   boolean hasPermission = checkUserUploadTotal(user.getGroup(), user.getFileTotal());
   return super.add(hasPermission, DOC_ADD, request, response, model);
 }
Exemple #2
0
 @RequestMapping("/member/doc_upload.jspx")
 public String uploadDoc(
     @RequestParam(value = "doc", required = false) MultipartFile file,
     String docNum,
     HttpServletRequest request,
     HttpServletResponse response,
     ModelMap model) {
   WebErrors errors = validateUpload(file, request);
   CmsUser user = CmsUtils.getUser(request);
   CmsSite site = CmsUtils.getSite(request);
   if (errors.hasErrors()) {
     model.addAttribute("error", errors.getErrors().get(0));
     return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_MEMBER, DOC_UPLOAD);
   }
   errors =
       validateUploadFileSize(
           file, CmsUtils.getUser(request).getGroup().getAllowFileSize(), request);
   if (errors.hasErrors()) {
     model.addAttribute("error", errors.getErrors().get(0));
     return FrontUtils.showError(request, response, model, errors);
   }
   String origName = file.getOriginalFilename();
   String ext = FilenameUtils.getExtension(origName).toLowerCase(Locale.ENGLISH);
   // TODO 检查允许上传的后缀
   try {
     String fileUrl;
     String ctx = request.getContextPath();
     fileUrl = fileRepository.storeByExt(site.getLibraryPath(), ext, file);
     // 加上部署路径
     fileUrl = ctx + fileUrl;
     model.addAttribute("docPath", fileUrl);
     model.addAttribute("docName", origName);
     model.addAttribute("docNum", docNum);
     model.addAttribute("docExt", ext);
   } 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);
   }
   cmsUserMng.updateUploadSize(
       user.getId(), Integer.parseInt(String.valueOf(file.getSize() / 1024)));
   return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_MEMBER, DOC_UPLOAD);
 }
  @SuppressWarnings("unchecked")
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    CmsSite site = FrontUtils.getSite(env);
    Pagination page = (Pagination) super.getData(params, env);

    Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
    paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page));
    paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList()));
    Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
    InvokeType type = DirectiveUtils.getInvokeType(params);
    String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params);
    if (InvokeType.sysDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true);
      FrontUtils.includePagination(site, params, env);
    } else if (InvokeType.userDefined == type) {
      if (StringUtils.isBlank(listStyle)) {
        throw new ParamsRequiredException(PARAM_STYLE_LIST);
      }
      FrontUtils.includeTpl(TPL_STYLE_LIST, site, env);
      FrontUtils.includePagination(site, params, env);
    } else if (InvokeType.custom == type) {
      FrontUtils.includeTpl(TPL_NAME, site, params, env);
      FrontUtils.includePagination(site, params, env);
    } else if (InvokeType.body == type) {
      if (body != null) {
        body.render(env.getOut());
        FrontUtils.includePagination(site, params, env);
      }
    } else {
      throw new RuntimeException("invoke type not handled: " + type);
    }
    DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
  }