Search in sources :

Example 11 with Channel

use of com.rometools.rome.feed.rss.Channel in project spring-framework by spring-projects.

the class RssChannelHttpMessageConverterTests method read.

@Test
public void read() throws IOException {
    InputStream inputStream = getClass().getResourceAsStream("rss.xml");
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(inputStream);
    inputMessage.getHeaders().setContentType(RSS_XML_UTF8);
    Channel result = converter.read(Channel.class, inputMessage);
    assertThat(result.getTitle()).isEqualTo("title");
    assertThat(result.getLink()).isEqualTo("https://example.com");
    assertThat(result.getDescription()).isEqualTo("description");
    List<?> items = result.getItems();
    assertThat(items.size()).isEqualTo(2);
    Item item1 = (Item) items.get(0);
    assertThat(item1.getTitle()).isEqualTo("title1");
    Item item2 = (Item) items.get(1);
    assertThat(item2.getTitle()).isEqualTo("title2");
}
Also used : Item(com.rometools.rome.feed.rss.Item) MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) InputStream(java.io.InputStream) Channel(com.rometools.rome.feed.rss.Channel) Test(org.junit.jupiter.api.Test)

Example 12 with Channel

use of com.rometools.rome.feed.rss.Channel in project rssriver by dadoonet.

the class RomeTest method testLeMonde.

@Test
public void testLeMonde() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    input.setPreserveWireFeed(true);
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/lemonde/rss.xml")));
    assertThat(feed, notNullValue());
    assertThat(feed.getEntries().isEmpty(), equalTo(false));
    assertThat(feed.originalWireFeed(), notNullValue());
    assertThat(feed.originalWireFeed(), instanceOf(Channel.class));
    Channel channel = (Channel) feed.originalWireFeed();
    assertThat(channel.getTtl(), equalTo(15));
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) Channel(com.rometools.rome.feed.rss.Channel) XmlReader(com.rometools.rome.io.XmlReader) Test(org.junit.Test)

Example 13 with Channel

use of com.rometools.rome.feed.rss.Channel 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

Channel (com.rometools.rome.feed.rss.Channel)13 Item (com.rometools.rome.feed.rss.Item)6 Date (java.util.Date)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)3 MediaType (org.springframework.http.MediaType)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Book (com.aidanwhiteley.books.domain.Book)1 Content (com.rometools.rome.feed.rss.Content)1 Description (com.rometools.rome.feed.rss.Description)1 Guid (com.rometools.rome.feed.rss.Guid)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)1 XmlReader (com.rometools.rome.io.XmlReader)1 InputStream (java.io.InputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 Test (org.junit.Test)1 PageRequest (org.springframework.data.domain.PageRequest)1 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)1