Media content tag missing from rss feed generated by Rome 1.0

728 views Asked by At

I am trying to add some media content to my Rome 1.0 generated RSS feed. But the feed that generates is without my media content tags. I've been looking all over the Internet for answers but no site has really been helpful this far. How do I get my media content to show 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;
}

Here's what is generated:

<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

There are 1 answers

1
janih On BEST ANSWER

Can you try Rome 1.5.0? Your code seems to work fine with it and the media tags get generated too.