Wicket and RSS Feeds

Ryan Sonnek bio photo By Ryan Sonnek

I love Wicket, and I love RSS so it’s only logical that I’d find a way to serve up RSS within Wicket.  There’s an example RssPage posted on the Wicket wiki, and I posted a simple RSS solution a while back, but neither of these are really solid solutions.  For the past few weeks I’ve been working heavily with serving RSS feeds, and I’ve finally gotten to a point where I can provide something back to the Wicket community.

Introducing, the new and improved Wicket FeedPage.  It’s actually the same API as my previous solution, but the inner workings are much improved.  To create an RSS feed, just create a subclass of FeedPage and follow the ROME API to create a SyndFeed for your RSS (or Atom) content.

public class ItemFeedPage extends FeedPage {
 protected SyndFeed getFeed() {
   SyndFeed feed = new SyndFeedImpl();
   feed.setFeedType("rss_2.0");
   feed.setTitle("Sample Feed");
   feed.setLink("http://mysite.com");
   feed.setDescription("Sample Feed for how cool Wicket is");

   List entries = new ArrayList();
   SyndEntry entry = new SyndEntryImpl();
   entry.setTitle("Article One");
   entry.setLink("http://mysite.com/article/one");
   entry.setPublishedDate(new Date());

   SyndContent description = new SyndContentImpl();
   description.setType("text/plain");
   description.setValue("Article descriping how cool wicket is.");
   entry.setDescription(description);

   entries.add(entry);
   feed.setEntries(entries);
   return feed;
 }
}

The ROME library has really impressed me and does an excellent job of hiding the internals of creating these feeds.  Want to change from RSS to Atom?  Simple!  Just change this line:

feed.setFeedType("rss_2.0");

to this

feed.setFeedType("atom_0.3");

As Borat would say…“Very Nice!”

I’ve created a new Wicket Stuff project to host this project which should make it super easy to get up and going.  Just add this block to your pom.xml file:

<repositories>
  <repository>
    <id>wicket-stuff-repository</id>
    <name>Wicket-Stuff Repository</name>
    <url>http://www.wicketstuff.org/maven/repository/</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>wicketstuff-rome</artifactId>
    <version>1.3-SNAPSHOT</version>
  </dependency>
</dependencies>

As a side note, if you’re having difficulty creating a dynamic url for use in your feed (guid, return url, etc) vote for this Wicket issue to help create a new API for that info.