罗马1.0生成的RSS Feed中缺少媒体内容标记

时间:2015-06-08 14:48:03

标签: rss media rome

我正在尝试将一些媒体内容添加到我的Rome 1.0生成的RSS源中。但生成的Feed没有我的媒体内容标记。我一直在互联网上寻找答案,但到目前为止还没有任何网站真正有用。如何让我的媒体内容显示在我的RSS Feed中?这是我的代码:

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>

1 个答案:

答案 0 :(得分:1)

你能试试Rome 1.5.0吗?您的代码似乎可以正常工作,并且也会生成媒体标记。