Search in sources :

Example 1 with JsoupPostDTO

use of com.nixmash.blog.jsoup.dto.JsoupPostDTO in project nixmash-blog by mintster.

the class JsoupServiceImpl method getJsoupPostDTO.

private JsoupPostDTO getJsoupPostDTO(PostDTO postDTO) {
    Document doc = Jsoup.parse(postDTO.getPostContent());
    JsoupPostDTO jsoupPostDTO = jsoupPostParser.parse(doc);
    if (jsoupPostDTO.hasImages()) {
        String imageUrl = jsoupPostDTO.getImagesInContent().get(0).getSrc();
        try {
            jsoupPostDTO.setTwitterImagePath(JsoupUtil.removeBaseUri(imageUrl));
        } catch (MalformedURLException e) {
            jsoupPostDTO.setTwitterImagePath(applicationSettings.getTwitterImage());
        }
    } else
        jsoupPostDTO.setTwitterImagePath(getTwitterImage(postDTO));
    jsoupPostDTO.setTwitterDescription(JsoupUtil.getTwitterDescription(jsoupPostDTO.getBodyText()));
    return jsoupPostDTO;
}
Also used : JsoupPostDTO(com.nixmash.blog.jsoup.dto.JsoupPostDTO) MalformedURLException(java.net.MalformedURLException) Document(org.jsoup.nodes.Document)

Example 2 with JsoupPostDTO

use of com.nixmash.blog.jsoup.dto.JsoupPostDTO in project nixmash-blog by mintster.

the class JsoupServiceImpl method buildPostMetaToSave.

private PostMeta buildPostMetaToSave(PostDTO postDTO) {
    if (!postDTO.getTwitterCardType().equals(TwitterCardType.NONE)) {
        String twitterCreator = applicationSettings.getTwitterCreator();
        JsoupPostDTO jsoupPostDTO = getJsoupPostDTO(postDTO);
        String twitterImage = jsoupPostDTO.getTwitterImagePath();
        String twitterDescription = jsoupPostDTO.getTwitterDescription();
        return PostMeta.getUpdated(postDTO.getTwitterCardType(), twitterImage, twitterDescription).twitterCreator(twitterCreator).postId(postDTO.getPostId()).build();
    } else
        return PostMeta.getEmpty(postDTO.getPostId(), TwitterCardType.NONE).build();
}
Also used : JsoupPostDTO(com.nixmash.blog.jsoup.dto.JsoupPostDTO)

Aggregations

JsoupPostDTO (com.nixmash.blog.jsoup.dto.JsoupPostDTO)2 MalformedURLException (java.net.MalformedURLException)1 Document (org.jsoup.nodes.Document)1