Mark Howard
If you are unfamiliar with RSS, Wikipedia has an excellent overview.
This is a very simple Java implementation of an RSS feed generator. It consists of a single class which will generate an XML file in RSS 2.0 format, which can then be published to your website and parsed by an RSS aggregator. This file presents a basic API which can be called from your own Java code - it is not a runnable program.
This class generates only RSS files containing a single channel, which is currently the most common RSS scenario. Although the file is RSS 2.0 compliant, older RSS 0.91 aggregators are able to deal with it.
This class handles only the most common case - if you require more sophisticated RSS functionality, take a look at the Rome project.
Dependencies
This class uses JDOM, my XML library of choice. JDOM can be downloaded from www.jdom.org.
Although JDOM comes with lots of jars, you only need to include jdom.jar in your classpath for this to work.
RSS feeds consist of "channels" and "items".
Usually, an item corresponds to an article or a post on your website. Each time you publish a piece of content you wish to bring to the attention of your subscribers, you add an item. The subscriber's RSS reader will detect that the item is new, and will present it to the user as "unread". Items have a one-paragraph summary of the content and a link to get to the full article or post.
It is possible to further split up items, and logically group them into channels. A channel might correspond to a different website using the same feed, or a separate department within a website. This implementation only supports a single channel.
Using the API only requires three lines of real code (exception handling is extra)
SimpleRSSGenerator rss = new SimpleRSSGenerator(rssOutputFile, channelTitle, channelDescription, channelUrl);
rss.add(itemTitle, itemDescription, itemLink);
rss.publish();
In a nutshell, this code will:
- Attempt to load the RSS file (specified by rssOutputFile). If it finds the file, appends to it. If it can't find the file creates a fresh one with appropriate structure.
- Add an item to the RSS file.
- Write your changes back to the RSS file.
Naturally, the file generated by the above process will have to live somewhere where your webserver can get to it (typically under the web root directory). Once the file is accessible to the wider web, you only need to link to the file from you HTML - the user's web browser will load it, recognise it as an RSS feed and take appropriate action.
Comprehensive help can be found in the JavaDoc.
Licensing
The Simple RSS Generator is Copyright © 2006 Clearfield Software Ltd. This software is made available under the terms of the BSD license. Feel free to modify and redistribute at will. This software has been posted here in the hope it will be useful, but comes with no warranties - express or implied. See the accompanying license.txt for full details.



