Child pages
  • RomeResult
Skip to end of metadata
Go to start of metadata

Now available as a Struts 2 plugin

The RomeResult is now available as a Struts 2 plugin over at http://code.google.com/p/s2-rome.

A couple of days ago I quickly had to create a result type that would transform a Rome (https://rome.dev.java.net/) SyndFeed to several news feeds. The framework makes this very, very easy.

Used versions

WebWork 2.2 beta 4
Rome 0.7 beta

The code

com.acme.result.RomeResult.java

Code Explanation

Easy enough. We try to find the SyndFeed object on the WW stack. If we can find it, we will set the feed type (rss v0.9 +, atom 0.3) if it has been specified in the result parameters (see below). Then we use a SyndFeedOutput to write our newsfeed to our PrintWriter from our response.

Action Configuration

Before you can use this result, you will need to register it in your struts.xml:

You can now use this result type. So, create an Action that will create and populate the Rome SyndFeed, and make sure you provide a getter for your populated SyndFeed. The actual creation of your feed is beyond this recipe, but you can find plenty of examples in the Rome Wiki (http://wiki.java.net/bin/view/Javawsxml/Rome05Tutorials).

Summary

This is a simple feed result using Rome as a news feed generator. You might want to make sure you don't generate your feed on every request, but there are lots of ways to deal with such problems. You can also provi
de additional setters in the Result to set your feed title, url, etc, but this should suffice for a quickstart.

  • No labels