com.clearfield.rss
Class SimpleRSSGenerator

java.lang.Object
  extended by com.clearfield.rss.SimpleRSSGenerator

public class SimpleRSSGenerator
extends java.lang.Object

Copyright © 2006 Clearfield Software Ltd. This software is distributed under the BSD license. See the accompanying license.txt for details.

Standalone class to generate the XML file needed to drive an RSS feed.

This class implements the simplest RSS scenario, generating an XML file conformant to the RSS 2.0 standard, containing a single channel.

This class was generated with the help of the Document Making An RSS Feed by Danny Sullivan of Search Engine Watch. Incidentally, the document states that new RSS items should be placed at the top of the XML, but research shows that modern RSS aggregators don't require this, so this implementation places new RSS items at the bottom of the XML.

Author:
Mark Howard mark@clearfield.com

Field Summary
static int DEFAULT_MAXIMUM_ITEM_COUNT
           
 
Constructor Summary
SimpleRSSGenerator(java.io.File rssFile, java.lang.String channelTitle, java.lang.String channelDescription, java.net.URL channelLink)
          Creates an new RSS generator.
 
Method Summary
 void add(java.lang.String itemTitle, java.lang.String itemDescription, java.lang.String itemLink)
          Adds an RSS item into the feed.
 int getMaximumItemCount()
          Gets the maximum number of items allowed to exist in this XML file at one time.
 void publish()
          Commits the generated RSS feed to disk.
 void setMaximumItemCount(int maximumItemCount)
          Gets the maximum number of items allowed to exist in this XML file at one time.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAXIMUM_ITEM_COUNT

public static final int DEFAULT_MAXIMUM_ITEM_COUNT
See Also:
Constant Field Values
Constructor Detail

SimpleRSSGenerator

public SimpleRSSGenerator(java.io.File rssFile,
                          java.lang.String channelTitle,
                          java.lang.String channelDescription,
                          java.net.URL channelLink)
                   throws java.io.IOException,
                          org.jdom.JDOMException
Creates an new RSS generator. If rssFile exists, modifies that; otherwise does the work necessary to set up a new feed given the channel attributes.

Parameters:
rssFile - File into which the RSS feed is output. Will be created if it does not exist
channelTitle - Brief title for the RSS feed
channelDescription - Description of the RSS feed
channelLink - URL of the website hosting the RSS feed
Throws:
java.io.IOException - In the case of an I/O problem when attempting to load the given RSS file
org.jdom.JDOMException - If JDOM cannot parse the XML in the given RSS file
Method Detail

add

public void add(java.lang.String itemTitle,
                java.lang.String itemDescription,
                java.lang.String itemLink)
Adds an RSS item into the feed. Items are the "articles" shown in RSS aggregators, and many aggregators treat them differently. Some (like IE7 or Opera) will display the description, while others (like Thunderbird) will ignore the description and instead attempt to fetch the URL given by itemLink and display that. In the most extreme case, Firefox will only display the title in an active bookmark and will go the URL when clicked.

Parameters:
itemTitle - Brief title of the item
itemDescription - Short description of the item, to be displayed as body content in some aggregators
itemLink - URL pointing to the website-based content, fetched and displayed as body content in some aggregators, as a link in others.
Throws:
java.lang.IllegalArgumentException - Thrown should the underlying XML not contain the expected structure

publish

public void publish()
             throws java.io.IOException
Commits the generated RSS feed to disk.

Throws:
java.io.IOException - Should an I/O exception occur when writing to disk

getMaximumItemCount

public int getMaximumItemCount()
Gets the maximum number of items allowed to exist in this XML file at one time. Defaults to DEFAULT_MAXIUMUM_ITEM_COUNT


setMaximumItemCount

public void setMaximumItemCount(int maximumItemCount)
Gets the maximum number of items allowed to exist in this XML file at one time. The number of items is capped to prevent them building up ad infinitum.