ROME and custom Generator elements
The majority of the articles I’ve seen on using ROME to create Atom and RSS feeds don’t show you how to customize the optional ‘generator’ element that both Atom and RSS support. It’s really easy. I’m assuming that you’ve already created and populated a SyndFeed instance:
SyndFeed feed = ..
WireFeedOutput feedOutput = new WireFeedOutput();
WireFeed wireFeed = feed.createWireFeed();
if (wireFeed.getFeedType().startsWith("atom")) {
Feed atomFeed = (Feed)wireFeed;
Generator gen = new Generator();
gen.setUrl("http://yoursite.com/");
gen.setValue("Your Site");
gen.setVersion("1.0");
atomFeed.setGenerator(gen);
feedOutput.output(atomFeed, ...);
} else {
Channel rssFeed = (Channel)wireFeed;
rssFeed.setGenerator("Your Site 1.0 (http://yoursite.com/)");
feedOutput.output(rssFeed, ...);
}
Make a decision about which feed you’re going to produce, cast to the appropriate implementation of WireFeed (Channel for RSS and Feed for Atom), and then use the appropriate setters on each of those respective classes.
2 Comments