Invalid content tag from rss feed generated by Rome 1.0
I am trying to add some media content to my rss feed created in Rome 1.0. But the channel being created has no tags for media content. I have searched all over the internet for answers, but no site has helped at the moment. How can I show my media content in my RSS feed? Here's my code below:
public org.w3c.dom.Document createMrssFeed(List<Article> recentArticles, String category, String descr) throws Exception {
SyndCategory syndCategory = new SyndCategoryImpl();
syndCategory.setName(category);
List<SyndCategory> categories = new ArrayList<>();
categories.add(syndCategory);
feed.setFeedType("rss_2.0");
feed.setTitle("My feed title");
feed.setLink("http://myfeedlink.com");
feed.setDescription(descr);
feed.setCategories(categories);
feed.setPublishedDate(new Date());
feed.setCopyright("Feed copyright"));
List<SyndEntry> items = new ArrayList<SyndEntry>();
SyndEntry item;
SyndContent description;
for (Article article : recentArticles) {
item = new Item();
item.setTitle(article.getTitle());
item.setLink(createLink(article.getLink()));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(article.getDescription());
item.setPublishedDate(article.getPublishedDate());
item.setDescription(description);
MediaContent[] contents = new MediaContent[1];
MediaContent image = new MediaContent( new UrlReference("http://me.com/movie2.jpg"));
contents[0] = image;
Metadata md = new Metadata();
Thumbnail[] thumbs = new Thumbnail[2];
thumbs[0] = new Thumbnail(new URI("http://me.com/movie2.jpg"));
thumbs[1] = new Thumbnail(new URI("http://me.com/movie2.jpg"));
md.setThumbnail( thumbs );
image.setMetadata( md );
MediaEntryModuleImpl module = new MediaEntryModuleImpl();
module.setMediaContents(contents);
item.getModules().add(module);
items.add(item);
}
feed.setEntries(items);
SyndFeedOutput output = new SyndFeedOutput();
org.w3c.dom.Document mrssFeed = output.outputW3CDom(feed);
return mrssFeed;
}
It generates here:
<rss xmlns:atom="http://www.w3.org/2005/Atom"xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>My feed title</title>
<link>http://myfeedlink</link>
<description>news,sports</description>
<category>staff article</category>
<copyright>...</copyright>
<lastBuildDate>Sun, 07 Jun 2015 00:36:31 EDT</lastBuildDate>
<pubDate/>
<item>
<description>Item description</description>
<guid>http://www.myitemlink.com</guid>
<link>http://www.myitemlink.com</link>
<pubDate>Thu, 28 May 2015 10:00:34 EDT</pubDate>
<title>My item title</title>
</item>
<item>
<description>Item 2 description</description>
<guid>http://www.myitem2link.com</guid>
<link>http://www.myitem2link.com</link>
<pubDate>Thu, 28 May 2015 10:00:34 EDT</pubDate>
<title>My item 2 title</title>
</item>
</channel>
</rss>
+3
source to share
1 answer
Can you try Rome 1.5.0 ? Your code seems to work fine with it and the media tags are generated as well.
+1
source to share