views:

77

answers:

2

I'm trying to build a polling service in Java that checks for updates from a RSS feed.

On detecting new items, it should only send new items further on in the system.

Is there an API that does this or would I have to do the comparison checks myself?

At the moment, my poller just returns what it currently sees causing duplicates in my system.

A: 

Similar to what you require is available in Informa

"Poller module is intended to provide convenient services for background polling of channel changes"

http://informa.sourceforge.net/poller.html

Joseph Kulandai
+1  A: 

Sun have an RSS Utilities library that was built for creating feeds. However it also includes a useful RSS parser that I am using to do a similar thing.

You can download the library from here (scroll down to the bottom for more information on the parser):

http://java.sun.com/developer/technicalArticles/javaserverpages/rss_utilities/

To check for new items, just get the GUID and compare it with GUIDs for existing items.

// Create an RSS Parser
RssParser parser = RssParserFactory.createDefault();

// Parse the feed
Rss rss = parser.parse( new URL( YOUR_FEED ) );

// Get the channel
Channel channel = rss.getChannel();

// Get the items
Collection<Item> items = channel.getItems();

// Loop for each item
for ( Item item : items )
{
  // Get the GUID
  Guid guid = item.getGuid();

  // Loop for each of the previously seen GUIDs and compare
}
Matthew Blackford
This is the actual download link: http://java.sun.com/developer/technicalArticles/javaserverpages/rss_utilities/rss_utils_1.1.zip
Matthew Blackford