public void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { Integer folderId = Integer.parseInt(params.get("folderId").toString()); String basePath = HttpUtils.getBasePath(request); try { Folder folder = folderService.getFolderById(folderId); if (Boolean.getBoolean(PropertyUtils.getValue("shishuo.static"))) { env.getOut().write(basePath + "/html/folder/" + folder.getEname() + ".html"); } else { env.getOut() .write(basePath + "/folder/" + folder.getEname() + ".htm?classifyId=" + folderId); } } catch (FolderNotFoundException e) { e.printStackTrace(); } }
/** @author 添加新的目录 */ @ResponseBody @RequestMapping(value = "/add.json", method = RequestMethod.POST) public JsonVo<String> add( @RequestParam(value = "fatherId", defaultValue = "0") long fatherId, @RequestParam(value = "folderName") String folderName, @RequestParam(value = "folderEname") String folderEname, @RequestParam(value = "status") FolderConstant.Status status, ModelMap modelMap) { JsonVo<String> json = new JsonVo<String>(); // FIXME 检查目录的ename不能用循环遍历检查 List<FolderVo> list = folderService.getAllFolderList(0, null); try { if (StringUtils.isBlank(folderName)) { json.getErrors().put("folderName", "目录名称不能为空"); } if (StringUtils.isBlank(folderEname)) { json.getErrors().put("folderEname", "英文名称不能为空"); } else if (!RegexUtils.isAlphaUnderline(folderEname)) { json.getErrors().put("folderEname", "只能是英文字母,数字和下划线"); } else { for (Folder folder : list) { if (folderEname.equals(folder.getEname())) { json.getErrors().put("folderEname", "英文名称不能重复"); } } } // 检测校验结果 validate(json); folderService.addFolder( fatherId, folderName, status, folderEname.toLowerCase(), FolderConstant.Rank.everyone, FolderConstant.Type.folder); json.setResult(true); } catch (Exception e) { logger.error(e.getMessage(), e); json.setResult(false); json.setMsg(e.getMessage()); } return json; }
/** @author 修改目录资料 */ @ResponseBody @RequestMapping(value = "/update.json", method = RequestMethod.POST) public JsonVo<String> updateFolder( @RequestParam(value = "folderId") long folderId, @RequestParam(value = "name") String name, @RequestParam(value = "ename") String ename, @RequestParam(value = "content", required = false) String content) { JsonVo<String> json = new JsonVo<String>(); // FIXME 检查目录的ename不能用循环遍历检查 List<FolderVo> list = folderService.getAllFolderList(0, null); try { if (name.equals("")) { json.getErrors().put("name", "目录名称不能为空"); } if (ename.equals("")) { json.getErrors().put("ename", "英文名称不能为空"); } else { for (Folder folder : list) { if (folderId != folder.getFolderId()) { if (ename.equals(folder.getEname())) { json.getErrors().put("folderEname", "英文名称不能重复"); } } } } // 检测校验结果 validate(json); String newEname = ename.toLowerCase(); folderService.updateFolderById(folderId, newEname, name, content); json.setResult(true); } catch (Exception e) { json.setResult(false); json.setMsg(e.getMessage()); } return json; }