我正在尝试将一些媒体内容添加到我的 Rome 1.0 生成的 RSS 提要中。但是生成的提要没有我的媒体内容标签。我一直在互联网上寻找答案,但到目前为止还没有一个网站真正有帮助。如何让我的媒体内容显示在我的 RSS 源中?下面是我的代码:
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;
}
这是生成的内容:
<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>