Exemple #1
0
  @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);
  }
Exemple #2
0
  @ResponseBody
  @RequestMapping(method = RequestMethod.PUT)
  public Object update(Post post, String tags) {
    MapContainer form = PostFormValidator.validateUpdate(post);
    if (!form.isEmpty()) {
      return form.put("success", false);
    }

    /* 由于加入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);

    post.setType(PostConstants.TYPE_POST);
    post.setLastUpdate(new Date());
    postManager.updatePost(
        post, PostTagHelper.from(post, tags, WebContextFactory.get().getUser().getId()));
    return new MapContainer("success", true);
  }