Exemple #1
0
  public String body(Post post) {
    if (!StringUtils.hasText(post.getBody())) {
      return null;
    }

    //		Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
    Document document = Jsoup.parse(post.getBody());
    Elements elements = document.select("img");
    for (Element element : elements) {
      String src = element.attr("src");
      if (src.startsWith(wallRideProperties.getMediaUrlPrefix())) {
        String style = element.attr("style");
        Pattern pattern = Pattern.compile("width: ([0-9]+)px;");
        Matcher matcher = pattern.matcher(element.attr("style"));
        if (matcher.find()) {
          String replaced = src + "?w=" + matcher.group(1);
          element.attr("src", replaced);
        }
      }
    }
    return document.body().html();
  }
Exemple #2
0
 public String summary(Post post, int length) {
   Document document = Jsoup.parse(post.getBody());
   String summary = document.text();
   if (!StringUtils.hasText(summary)) {
     return summary;
   }
   summary = summary.replaceAll("<.+?>", "");
   if (!StringUtils.hasText(summary)) {
     return summary;
   }
   if (summary.length() <= length) {
     return summary;
   }
   return summary.substring(0, length) + "...";
 }