@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; }
@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); }