Generating RSS Feeds with Rome
Want to have RSS feeds in your Java application? Try Rome..
"Rome is an open source library for generating, parsing and manipulating RSS and Atom feeds. It supports different RSS and Atom feed formats such as Atom 0.3, and Atom 1.0, RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0 and RSS 2.0."
A couple months back, I got to use the Rome library to implement RSS in Archiva. What I liked about Rome is how it’s so easy to understand and use. To generate an RSS feed, you basically just need to be familiar with these three classes: SyndFeed, SyndEntry and SyndContent. These three are Java interfaces with the following concrete implementations: SyndFeedImpl, SyndEntryImpl and SyndContentImpl respectively. Here’s a short example on how you can generate a RSS 2.0 feed:
SyndFeed feed = new SyndFeedImpl(); // create the feed
Date publishDate = new Date( System.currentTimeMillis() );feed.setTitle( "Techblog.ph RSS Feeds" );
feed.setDescription( "RSS feeds of blog entries from Techblog.ph" );
feed.setLanguage( "en-us" );
feed.setPublishedDate( publishDate );
feed.setFeedType( "rss_2.0" ); // set the type of your feedList<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry = new SyndEntryImpl(); // create a feed entry
entry.setTitle( "Generating RSS Feeds with Rome" );
entry.setPublishedDate( publishDate );SyndContent content = new SyndContentImpl(); // create the content of your entry
content.setType( "text/plain" );
content.setValue( "Want to have RSS feeds in your Java application? Try Rome….." );entry.setDescription( content );
entries.add( entry );
feed.setEntries( entries ); // you can add multiple entries in your feed
For the published date, make sure that you update it whenever you have a new entry and publish the feed so that the reader knows there were changes/updates in your feed.
Now, to publish your feed.. you can write it into a file (example, write it to rss.xml) which the feed reader checks for updates or you can generate the feed by request (like how it is done in Archiva). If you are publishing your feeds by writing it on a file, you might need to read the file into a SyndFeed before adding new entries as shown below:
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build( new XmlReader( outputFile ) );
To learn more about the Rome library, check out the Rome API.
- BROWSE / IN TIMELINE
- « BarCamp in Manila tonight!
- » Archiva @ApacheCon US 2008
- BROWSE / IN Tech blogs
- « BarCamp in Manila tonight!
- » Archiva @ApacheCon US 2008
COMMENTS / 3 COMMENTS
Jon added these pithy words on Aug 26 08 at 5:10 pmRome is a royal pain in the ass. It is the equivalent of using Java to build a HTML page, which has long been a stupid idea. If there is some extension to RSS/Atom that you want, you have to go find some extra library that implements it or implement it yourself.
A far far easier and more easily maintained solution is to just use Velocity templates. Pass in a context of your data objects and render the output via the template.
Rohit added these pithy words on Dec 31 08 at 6:22 amYou mentioned that:
Now, to publish your feed.. you can write it into a file (example, write it to rss.xml) which the feed reader checks for updates or you can generate the feed by request (like how it is done in Archiva). If you are publishing your feeds by writing it on a file, you might need to read the file into a SyndFeed before adding new entries as shown below:If it is so, where do we place the code for generating the feed (RSS/Atom). Can I have a sample of any JSP file or can you be little elaborate on this?
I need to implement the same. Please help.
Alex added these pithy words on Jan 27 09 at 8:41 amHi Deng,
I’m using ROME to update an XML file for my RSS feeds. If I wanted to go with the “generate by request” approach, do you just always add a fixed number of entries into the feed for each request? Or is there a way for knowing when the reader was last updated?
Thanks!
SPEAK / ADD YOUR COMMENT
Comments are moderated.

