Creating an RSS Feed in JHTML

Posted on

Because we use an older version of ATG Dynamo (6.2.0) at my place of employment, we’re sometimes constrained in what we can do and aren’t able to take advantage of features in newer versions of Dynamo. One of those features is the ability to generate an RSS feed from a content repository (which I believe is available now as part of the suite of personalization features ATG offers). If you have the ability to deploy droplet code, there’s certainly an RSSFeed module. But if all you need is a basic RSS feed for a particular collection, the following is what I came up with.

<!--?xml version="1.0" encoding="UTF-8" ?-->&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;importbean bean="/atg/targeting/TargetingForEach"&gt;
&lt;importbean bean="/atg/dynamo/droplet/Switch"&gt;
 
&lt;%-- import files --%&gt; 
&lt;%@ page import="java.util.*, java.text.*" %&gt;
 
&lt;%-- Generate the RSS XML --%&gt;
 
&lt;%-- Set the rss type --%&gt;
&lt;rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"&gt;
   &lt;channel&gt;
      &lt;title&gt;News&lt;/title&gt;
      &lt;link&gt;http://www.foobar.com/&lt;/link&gt;
      &lt;description&gt;News and information.&lt;/description&gt;
   &lt;textInput&gt;
      &lt;title&gt;News&lt;/title&gt;
         &lt;link&gt;http://www.foobar.com/&lt;/link&gt;
         &lt;description&gt;News and information.&lt;/description&gt;
   &lt;/textInput&gt;
   &lt;skipHours&gt;
      &lt;hour&gt;0&lt;/hour&gt;
   &lt;/skipHours&gt;
      &lt;language&gt;en-us&lt;/language&gt;
      &lt;webMaster&gt;webmaster@foobar.com&lt;/webMaster&gt;
 
      &lt;droplet bean="/atg/targeting/TargetingForEach"&gt;
         &lt;param name="targeter" value="bean:/atg/registry/RepositoryTargeters/News/archiveNews"&gt;
         &lt;param name="fireContentEvent" value="false"&gt;
         &lt;param name="firecontentTypeEvent" value="false"&gt;
         &lt;param name="sortProperties" value="-postingDate"&gt;
         &lt;oparam name="output"&gt;
            &lt;droplet bean="/atg/dynamo/droplet/Switch"&gt;
               &lt;param name="value" value="param:element.linkURL"&gt;
               &lt;oparam name="unset"&gt;
                  &lt;item&gt; 
                     &lt;title&gt;&lt;valueof param="element.title"/&gt;&lt;/title&gt;
                     &lt;description&gt;&lt;valueof param="element.description"/&gt;&lt;/description&gt;
                     &lt;link&gt;http://www.foobar.com/news/news.jhtml?reposid=&lt;valueof param="element.repositoryId"/&gt;&lt;/link&gt;
                     &lt;pubDate&gt;&lt;valueof param="element.postingDate" converter="Date" date="EEE, dd MMM yyyy HH:mm:ss Z"/&gt;&lt;/pubDate&gt;
                  &lt;/item&gt;
               &lt;/oparam&gt;
               &lt;oparam name="default"&gt;
                  &lt;item&gt; 
                     &lt;title&gt;&lt;valueof param="element.title"/&gt;&lt;/title&gt;
                     &lt;description&gt;&lt;valueof param="element.description"/&gt;&lt;/description&gt;
                     &lt;link&gt;&lt;valueof param="element.linkURL"/&gt;&lt;/link&gt;
                     &lt;pubDate&gt;&lt;valueof param="element.postingDate" converter="Date" date="EEE, dd MMM yyyy HH:mm:ss Z"/&gt;&lt;/pubDate&gt;
                  &lt;/item&gt;
               &lt;/oparam&gt;
            &lt;/droplet&gt;
         &lt;/oparam&gt;
         &lt;oparam name="empty"&gt;
            &lt;p&gt;No archived news&lt;/p&gt;
         &lt;/oparam&gt;
      &lt;/droplet&gt;
   &lt;/channel&gt;
&lt;/rss&gt;

A couple of the important things with an RSS feed is to have a properly formatted date and to properly include the various elements and the like. Some readers are more forgiving than others. The date version here is the RSS 2.0-compatible RFC822 and not the older ISO8601, though you can read all about the ins and outs of RSS dates. Many elements are optional but the output may display strangely depending on the reader and are included here primarily for consistent display with the built-in readers on IE and Firefox.


Leave a Reply

Your email address will not be published. Required fields are marked *