Search in sources :

Example 1 with Channel

use of com.rometools.rome.feed.rss.Channel in project nixmash-blog by mintster.

the class RssPostFeedView method newFeed.

@Override
protected Channel newFeed() {
    Channel channel = new Channel("rss_2.0");
    channel.setLink(applicationSettings.getBaseUrl() + "/posts/feed/");
    channel.setTitle(applicationSettings.getRssChannelTitle());
    channel.setDescription(applicationSettings.getRssChannelDescription());
    postService.getOneMostRecent().ifPresent(p -> channel.setPubDate(Date.from(p.getPostDate().toInstant())));
    return channel;
}
Also used : Channel(com.rometools.rome.feed.rss.Channel)

Example 2 with Channel

use of com.rometools.rome.feed.rss.Channel in project tutorials by eugenp.

the class ArticleRssController method buildChannel.

private Channel buildChannel(List<Article> articles) {
    Channel channel = new Channel("rss_2.0");
    channel.setLink("http://localhost:8080/spring-mvc-simple/rss");
    channel.setTitle("Article Feed");
    channel.setDescription("Article Feed Description");
    channel.setPubDate(new Date());
    List<Item> items = new ArrayList<>();
    for (Article article : articles) {
        Item item = new Item();
        item.setLink(article.getLink());
        item.setTitle(article.getTitle());
        Description description1 = new Description();
        description1.setValue(article.getDescription());
        item.setDescription(description1);
        item.setPubDate(article.getPublishedDate());
        item.setAuthor(article.getAuthor());
        items.add(item);
    }
    channel.setItems(items);
    return channel;
}
Also used : Item(com.rometools.rome.feed.rss.Item) Description(com.rometools.rome.feed.rss.Description) Channel(com.rometools.rome.feed.rss.Channel) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 3 with Channel

use of com.rometools.rome.feed.rss.Channel in project tutorials by eugenp.

the class ArticleRssController method articleHttpFeed.

@GetMapping(value = "/rss2", produces = { "application/rss+xml", "application/rss+json" })
@ResponseBody
public Channel articleHttpFeed() {
    List<Article> items = new ArrayList<>();
    Article item1 = new Article();
    item1.setLink("http://www.baeldung.com/netty-exception-handling");
    item1.setTitle("Exceptions in Netty");
    item1.setDescription("In this quick article, we’ll be looking at exception handling in Netty.");
    item1.setPublishedDate(new Date());
    item1.setAuthor("Carlos");
    Article item2 = new Article();
    item2.setLink("http://www.baeldung.com/cockroachdb-java");
    item2.setTitle("Guide to CockroachDB in Java");
    item2.setDescription("This tutorial is an introductory guide to using CockroachDB with Java.");
    item2.setPublishedDate(new Date());
    item2.setAuthor("Baeldung");
    items.add(item1);
    items.add(item2);
    Channel channelData = buildChannel(items);
    return channelData;
}
Also used : Channel(com.rometools.rome.feed.rss.Channel) ArrayList(java.util.ArrayList) Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Channel

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

the class RssChannelHttpMessageConverterTests method write.

@Test
public void write() throws IOException {
    Channel channel = new Channel("rss_2.0");
    channel.setTitle("title");
    channel.setLink("https://example.com");
    channel.setDescription("description");
    Item item1 = new Item();
    item1.setTitle("title1");
    Item item2 = new Item();
    item2.setTitle("title2");
    List<Item> items = new ArrayList<>(2);
    items.add(item1);
    items.add(item2);
    channel.setItems(items);
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(channel, null, outputMessage);
    assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content-type").isEqualTo(RSS_XML_UTF8);
    String expected = "<rss version=\"2.0\">" + "<channel><title>title</title><link>https://example.com</link><description>description</description>" + "<item><title>title1</title></item>" + "<item><title>title2</title></item>" + "</channel></rss>";
    assertThat(XmlContent.of(outputMessage.getBodyAsString(StandardCharsets.UTF_8))).isSimilarToIgnoringWhitespace(expected);
}
Also used : Item(com.rometools.rome.feed.rss.Item) Channel(com.rometools.rome.feed.rss.Channel) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with Channel

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

the class SiteRssFeedTest method checkFeedForFeedData.

@Test
void checkFeedForFeedData() {
    Channel channel = siteFeed.createSiteRssFeed();
    assertEquals(booksFeedsDescription, channel.getDescription());
    assertTrue(channel.getItems().size() > 0 && channel.getItems().size() <= booksFeedsMaxEntries);
    Item item = channel.getItems().get(0);
    assertFalse(item.getContent().getValue().isEmpty());
}
Also used : Item(com.rometools.rome.feed.rss.Item) Channel(com.rometools.rome.feed.rss.Channel) Test(org.junit.jupiter.api.Test)

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