@ResponseBody @RequestMapping(method = RequestMethod.POST) public Object insert(Post post, String tags) { MapContainer form = PostFormValidator.validatePublish(post); if (!form.isEmpty()) { return form.put("success", false); } post.setId(optionManager.getNextPostid()); post.setCreator(WebContextFactory.get().getUser().getId()); post.setCreateTime(new Date()); post.setLastUpdate(post.getCreateTime()); /* 由于加入xss的过滤,html内容都被转义了,这里需要unescape */ String content = HtmlUtils.htmlUnescape(post.getContent()); post.setContent(JsoupUtils.filter(content)); String cleanTxt = JsoupUtils.plainText(content); post.setExcerpt( cleanTxt.length() > PostConstants.EXCERPT_LENGTH ? cleanTxt.substring(0, PostConstants.EXCERPT_LENGTH) : cleanTxt); postManager.insertPost(post, PostTagHelper.from(post, tags, post.getCreator())); return new MapContainer("success", true); }
public static MapContainer convert(Document obj) { MapContainer mc = new MapContainer(); for (IndexableField field : obj.getFields()) { mc.put(field.name(), field.stringValue()); } return mc; }
public static MapContainer convert(Document obj, Collection<String> filters) { MapContainer mc = new MapContainer(); for (IndexableField field : obj.getFields()) { if (filters.contains(field.name())) continue; mc.put(field.name(), field.stringValue()); } return mc; }
@RequestMapping(method = RequestMethod.PUT) public String update(User user, String repass, Model model) { MapContainer form = UserFormValidator.validateUpdate(user, repass); if (!form.isEmpty()) { model.addAllAttributes(form); model.addAttribute("user", user); return "backend/user/edit"; } user.setLastUpdate(new Date()); userService.update(user); return "redirect:/backend/users"; }
@RequestMapping(value = "/my", method = RequestMethod.PUT) public String upmy(User user, String repass, Model model) { MapContainer form = UserFormValidator.validateMy(user, repass); if (!form.isEmpty()) { model.addAllAttributes(form); model.addAttribute("my", user); return "backend/user/my"; } user.setRole(WebContextFactory.get().getUser().getRole()); user.setLastUpdate(new Date()); userService.update(user); return "redirect:/backend/users"; }
@RequestMapping(method = RequestMethod.POST) @RequiresRoles("admin") public String insert(User user, String repass, Model model) { MapContainer form = UserFormValidator.validateInsert(user, repass); if (!form.isEmpty()) { model.addAllAttributes(form); return "backend/user/edit"; } user.setId(IdGenerator.uuid19()); user.setCreateTime(new Date()); user.setLastUpdate(user.getCreateTime()); userService.insert(user); return "redirect:/backend/users"; }
@ResponseBody @RequestMapping(value = "/fast", method = RequestMethod.PUT) public Object fast(Post post, String tags) { MapContainer form = PostFormValidator.validateFastUpdate(post); if (!form.isEmpty()) { return form.put("success", false); } Post old = postService.loadById(post.getId()); if (old == null) { return form.put("success", false).put("msg", "非法请求"); } post.setContent(old.getContent()); post.setExcerpt(old.getExcerpt()); post.setType(PostConstants.TYPE_POST); post.setLastUpdate(new Date()); postManager.updatePost( post, PostTagHelper.from(post, tags, WebContextFactory.get().getUser().getId()), true); return new MapContainer("success", true); }