|
| 1 | +package com.baeldung.rss; |
| 2 | + |
| 3 | +import com.rometools.rome.feed.rss.Channel; |
| 4 | +import com.rometools.rome.feed.rss.Description; |
| 5 | +import com.rometools.rome.feed.rss.Item; |
| 6 | +import org.springframework.stereotype.Service; |
| 7 | +import org.springframework.web.servlet.view.feed.AbstractRssFeedView; |
| 8 | + |
| 9 | +import javax.servlet.http.HttpServletRequest; |
| 10 | +import javax.servlet.http.HttpServletResponse; |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.Date; |
| 13 | +import java.util.List; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +@Service("articleFeedView") |
| 17 | +public class ArticleFeedView extends AbstractRssFeedView { |
| 18 | + |
| 19 | + protected Channel newFeed() { |
| 20 | + Channel channel = new Channel("rss_2.0"); |
| 21 | + channel.setLink("http://localhost:8080/rss"); |
| 22 | + channel.setTitle("Article Feed"); |
| 23 | + channel.setDescription("Article Feed Description"); |
| 24 | + channel.setPubDate(new Date()); |
| 25 | + return channel; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception { |
| 30 | + List list = new ArrayList<Item>(); |
| 31 | + |
| 32 | + Item item1 = new Item(); |
| 33 | + item1.setLink("http://www.baeldung.com/netty-exception-handling"); |
| 34 | + item1.setTitle("Exceptions in Netty"); |
| 35 | + Description description1 = new Description(); |
| 36 | + description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); |
| 37 | + item1.setDescription(description1); |
| 38 | + item1.setPubDate(new Date()); |
| 39 | + item1.setAuthor("Carlos"); |
| 40 | + |
| 41 | + Item item2 = new Item(); |
| 42 | + item2.setLink("http://www.baeldung.com/cockroachdb-java"); |
| 43 | + item2.setTitle("Guide to CockroachDB in Java"); |
| 44 | + Description description2 = new Description(); |
| 45 | + description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); |
| 46 | + item2.setDescription(description2); |
| 47 | + item2.setPubDate(new Date()); |
| 48 | + item2.setAuthor("Baeldung"); |
| 49 | + |
| 50 | + list.add(item1); |
| 51 | + list.add(item2); |
| 52 | + return list; |
| 53 | + } |
| 54 | +} |
0 commit comments