Search in sources :

Example 1 with Content

use of com.rometools.rome.feed.rss.Content in project books by aidanwhiteley.

the class SiteRssFeed method createSiteRssFeed.

public Channel createSiteRssFeed() {
    PageRequest pageObj = PageRequest.of(0, booksFeedsMaxEntries);
    Page<Book> recentBooks = bookRepository.findAllByOrderByCreatedDateTimeDesc(pageObj);
    Channel channel = new Channel(FEED_TYPE_RSS_2_0);
    channel.setTitle(booksFeedsTitles);
    channel.setLink(booksFeedsDomain);
    channel.setDescription(booksFeedsDescription);
    channel.setPubDate(new Date());
    channel.setItems(recentBooks.stream().map(b -> {
        Item item = new Item();
        item.setTitle(b.getTitle() + " by " + b.getAuthor());
        item.setLink(booksFeedsDomain + "#/book/" + b.getId());
        Guid guid = new Guid();
        guid.setPermaLink(true);
        guid.setValue(booksFeedsDomain + "#/book/" + b.getId());
        item.setGuid(guid);
        ZonedDateTime zdt = b.getCreatedDateTime().atZone(ZoneId.systemDefault());
        item.setPubDate(Date.from(zdt.toInstant()));
        Content content = new Content();
        content.setType("text/html");
        content.setValue(b.getSummary() + "\r\n \r\nRating: " + b.getRating());
        item.setContent(content);
        return item;
    }).collect(Collectors.toList()));
    return channel;
}
Also used : Item(com.rometools.rome.feed.rss.Item) PageRequest(org.springframework.data.domain.PageRequest) ZonedDateTime(java.time.ZonedDateTime) Book(com.aidanwhiteley.books.domain.Book) Content(com.rometools.rome.feed.rss.Content) Channel(com.rometools.rome.feed.rss.Channel) Guid(com.rometools.rome.feed.rss.Guid) Date(java.util.Date)

Aggregations

Book (com.aidanwhiteley.books.domain.Book)1 Channel (com.rometools.rome.feed.rss.Channel)1 Content (com.rometools.rome.feed.rss.Content)1 Guid (com.rometools.rome.feed.rss.Guid)1 Item (com.rometools.rome.feed.rss.Item)1 ZonedDateTime (java.time.ZonedDateTime)1 Date (java.util.Date)1 PageRequest (org.springframework.data.domain.PageRequest)1