Java Code Examples for com.rometools.rome.feed.rss.Channel#setItems()

The following examples show how to use com.rometools.rome.feed.rss.Channel#setItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticleRssController.java    From tutorials with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: AbstractRssFeedView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed items.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Channel channel,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = buildFeedItems(model, request, response);
	channel.setItems(items);
}
 
Example 3
Source File: RssChannelHttpMessageConverterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	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);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	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(outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo(expected));
}
 
Example 4
Source File: AbstractRssFeedView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed items.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Channel channel,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = buildFeedItems(model, request, response);
	channel.setItems(items);
}
 
Example 5
Source File: RssChannelHttpMessageConverterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Channel channel = new Channel("rss_2.0");
	channel.setTitle("title");
	channel.setLink("http://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);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	String expected = "<rss version=\"2.0\">" +
			"<channel><title>title</title><link>http://example.com</link><description>description</description>" +
			"<item><title>title1</title></item>" +
			"<item><title>title2</title></item>" +
			"</channel></rss>";
	assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo(expected));
}
 
Example 6
Source File: AbstractRssFeedView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed items.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Channel channel,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = buildFeedItems(model, request, response);
	channel.setItems(items);
}
 
Example 7
Source File: AbstractRssFeedView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedItems(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed items.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Channel channel,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = buildFeedItems(model, request, response);
	channel.setItems(items);
}
 
Example 8
Source File: RssChannelHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Channel channel = new Channel("rss_2.0");
	channel.setTitle("title");
	channel.setLink("http://example.com");
	channel.setDescription("description");

	Item item1 = new Item();
	item1.setTitle("title1");

	Item item2 = new Item();
	item2.setTitle("title2");

	List<Item> items = new ArrayList<Item>(2);
	items.add(item1);
	items.add(item2);
	channel.setItems(items);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(channel, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", utf8),
			outputMessage.getHeaders().getContentType());
	String expected = "<rss version=\"2.0\">" +
			"<channel><title>title</title><link>http://example.com</link><description>description</description>" +
			"<item><title>title1</title></item>" +
			"<item><title>title2</title></item>" +
			"</channel></rss>";
	assertXMLEqual(expected, outputMessage.getBodyAsString(utf8));
}
 
Example 9
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * This puts the pieces together to generate the actual feed.
 * 
 * @param title
 *            The global title for the podcast
 * @param link
 *            The URL for the feed
 * @param description_loc
 *            Global description of the feed
 * @param copyright
 *            Copyright information
 * @param entries
 *            The list of individual podcasts
 * @param feedTyle
 * 			 The output feed type (for potential future development). Set to rss_2.0
 * @param pubDate
 * 			 The date to set the publish date for this feed
 * 
 * @eturn SyndFeed
 * 			The entire podcast stuffed into a SyndFeed object
 */
private Channel doSyndication(Map feedInfo, List entries,
		String feedType, Date pubDate, Date lastBuildDate) {

	final Channel channel = new Channel();

	// FUTURE: How to determine what podcatcher supports and feed that to them
	channel.setFeedType(feedType);
	channel.setTitle((String) feedInfo.get("title"));
	channel.setLanguage(LANGUAGE);

	channel.setPubDate(pubDate);
	channel.setLastBuildDate(lastBuildDate);

	channel.setLink((String) feedInfo.get("url"));
	channel.setDescription((String) feedInfo.get("desc"));		
	channel.setCopyright((String) feedInfo.get("copyright"));
	channel.setGenerator((String) feedInfo.get("gen"));

	channel.setItems(entries);

	// Used to remove the dc: tags from the channel level info
	List modules = new ArrayList();
	
	channel.setModules(modules);

	return channel;
}
 
Example 10
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * This puts the pieces together to generate the actual feed.
 * 
 * @param title
 *            The global title for the podcast
 * @param link
 *            The URL for the feed
 * @param description_loc
 *            Global description of the feed
 * @param copyright
 *            Copyright information
 * @param entries
 *            The list of individual podcasts
 * @param feedTyle
 * 			 The output feed type (for potential future development). Set to rss_2.0
 * @param pubDate
 * 			 The date to set the publish date for this feed
 * 
 * @eturn SyndFeed
 * 			The entire podcast stuffed into a SyndFeed object
 */
private Channel doSyndication(Map feedInfo, List entries,
		String feedType, Date pubDate, Date lastBuildDate) {

	final Channel channel = new Channel();

	// FUTURE: How to determine what podcatcher supports and feed that to them
	channel.setFeedType(feedType);
	channel.setTitle((String) feedInfo.get("title"));
	channel.setLanguage(LANGUAGE);

	channel.setPubDate(pubDate);
	channel.setLastBuildDate(lastBuildDate);

	channel.setLink((String) feedInfo.get("url"));
	channel.setDescription((String) feedInfo.get("desc"));		
	channel.setCopyright((String) feedInfo.get("copyright"));
	channel.setGenerator((String) feedInfo.get("gen"));

	channel.setItems(entries);

	// Used to remove the dc: tags from the channel level info
	List modules = new ArrayList();
	
	channel.setModules(modules);

	return channel;
}
 
Example 11
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = new Channel(type);
    channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
    channel.setStyleSheet(syndFeed.getStyleSheet());
    channel.setEncoding(syndFeed.getEncoding());

    channel.setTitle(syndFeed.getTitle());
    final String link = syndFeed.getLink();
    final List<SyndLink> links = syndFeed.getLinks();
    if (link != null) {
        channel.setLink(link);
    } else if (!links.isEmpty()) {
        channel.setLink(links.get(0).getHref());
    }

    channel.setDescription(syndFeed.getDescription());

    final SyndImage sImage = syndFeed.getImage();
    if (sImage != null) {
        channel.setImage(createRSSImage(sImage));
    }

    final List<SyndEntry> sEntries = syndFeed.getEntries();
    if (sEntries != null) {
        channel.setItems(createRSSItems(sEntries));
    }

    final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;
}
 
Example 12
Source File: RSS090Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Parses the root element of an RSS document into a Channel bean.
 * <p/>
 * It reads title, link and description and delegates to parseImage, parseItems and
 * parseTextInput. This delegation always passes the root element of the RSS document as
 * different RSS version may have this information in different parts of the XML tree (no
 * assumptions made thanks to the specs variaty)
 * <p/>
 *
 * @param rssRoot the root element of the RSS document to parse.
 * @return the parsed Channel bean.
 */
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = new Channel(getType());
    channel.setStyleSheet(getStyleSheet(rssRoot.getDocument()));

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final Element title = eChannel.getChild("title", getRSSNamespace());
    if (title != null) {
        channel.setTitle(title.getText());
    }

    final Element link = eChannel.getChild("link", getRSSNamespace());
    if (link != null) {
        channel.setLink(link.getText());
    }

    final Element description = eChannel.getChild("description", getRSSNamespace());
    if (description != null) {
        channel.setDescription(description.getText());
    }

    channel.setImage(parseImage(rssRoot));

    channel.setTextInput(parseTextInput(rssRoot));

    // Unfortunately Microsoft's SSE extension has a special case of effectively putting the
    // sharing channel module inside the RSS tag and not inside the channel itself. So we also
    // need to look for channel modules from the root RSS element.
    final List<Module> allFeedModules = new ArrayList<Module>();
    final List<Module> rootModules = parseFeedModules(rssRoot, locale);
    final List<Module> channelModules = parseFeedModules(eChannel, locale);

    if (rootModules != null) {
        allFeedModules.addAll(rootModules);
    }

    if (channelModules != null) {
        allFeedModules.addAll(channelModules);
    }

    channel.setModules(allFeedModules);
    channel.setItems(parseItems(rssRoot, locale));

    final List<Element> foreignMarkup = extractForeignMarkup(eChannel, channel, getRSSNamespace());
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;

}