EMC Developer Network

Preparing an RSS feed from a DQL Query

March 2005

Abstract

RSS stands for Really Simple Syndication and is a popular web syndication format. This article describes an XSL file that converts a DQL query to an RSS 2.0 file. This could be used in conjunction with Web Publisher to build RSS files by querying the web content. For example, the Developer Program used this to build an RSS file that lists the latest content posted on the website.

References

RSS 2.0 Specification - http://blogs.law.harvard.edu/tech/rss This also contains a link to sample RSS 2.0 file.

Design

Brief Introduction to RSS

RSS is a format for collating important content links from a website. A website can publish an RSS-compliant XML file that contains links to important pieces of content on the website. RSS clients can aggregate RSS files from various websites and present them to the user. A user can categorize various RSS feeds. For example, under the 'Technical' category, a user might have feeds from Slashdot, Wired, Developer Program. Under the 'News' category, a user might have feeds from 'CNN', 'BBC', ... For more information on RSS you can search on the word 'RSS' in various search engines

Converting a DQL query to XML

XDQL can be used to obtain the results of a DQL query as XML. The DFC interface com.documentum.xml.xdql.IDfXmlQuery can be used to execute XDQL. This Java interface can be invoked from an XSL file and the XML results transformed into other formats.This technique was used to obtain DQL results as XML and then transform them to RSS XML format. This sample assumes that you have some familiarity with using XDQL in XSL files.

DQL to RSS Mapping

A DQL query was mapped to an RSS channel and each result of the query to an RSS item element. Each RSS channel has three required elements. These are title, description, link. These were defined as XSL variables and their values need to be set before using the XSL file.

Object attributes were mapped to elements under the RSS item element. The item element contains a lot of children elements. In this example, we have mapped only a few attributes. If you want to map additional attributes you can modify the XSL file and map them as per your requirements. Here are the attributes that we mapped -

  • object_name ~ title
  • r_modify_date ~ pubDate
  • r_object_id ~ guid

Every item element must contain a link element. The value of this link element identifies the location of the content. There are two ways to construct this link. One is to append a link base (e.g. http://www.documentum.com/developer) to the repository folder path of the object and the other is to use DRLs.

To use the repository folder path of the object for creating a link, we wrote a Java method that finds the path to the object. This method can also create a path to a specific rendition, if one exists. The method is com.documentum.devprog.rss.Helper#getURL(...). Its parameters are as follows -

  • sessionId - Repository session id.
  • objectId - Respository object id.
  • basePath - Repository folder path under which the object should be searched. This is useful if an object is linked to multiple locations.It is not a required parameter.
  • linkBase - This is appended to the repository folder path. Example- http://www.documentum.com/developer
  • format - The rendition of the object to link to. If left null, the default rendition is used.
To use this Java method, you will need to put the attached rssHelper.jar file into JVM's classpath.

To use a DRL as the value of the link element, append the r_object_id to a link base of form http://server:[port]/virtualRoot/drl.html?objectId=. The XSL file contains commented lines that create a link using a DRL.

Preparing the pubDate

The pubDate element that specifies the date a piece of content was published needs to be in RFC 822 date format. Its not possible to get this date format using DQL. To overcome this, the date obtained from results is formatted using the Java class java.text.SimpleDateFormat The steps needed to do this are -

  • Get date from results
  • Feed the java.text.SimpleDateFormat this date and get back a java.util.Date object
  • Feed the java.util.Date object to java.text.SimpleDateFormat and get back date formatted in RFC 822 format
You will need to configure an XSL variable called dateAttributePattern with the pattern in which DQL returns date values. This pattern will be used to parse the date returned in the DQL results. To find out more details about creating a date pattern refer to the JavaDocs of java.text.SimpleDateFormat

Trivia

When we started thinking about this sample, we wanted to make a Business Object but soon realized that creating an XSL file is a more flexible approach in this scenario. Some of the reasons we used an XSL file are -

  • There is not much algorithmic (business) logic involved in this sample. Its simply mapping Documentum Repository attributes to RSS XML elements. If there was plenty of algorithmic logic involved, then trying to do the same in XSL would make the code unreadable and clumsy. In that case, Java would have been a better option.
  • A well designed Business Object should be easily configurable. An XSL file, being XML, is inherently configurable.

Using the XSL file on the Developer Program site

We modified the file to create an RSS feed containing links to the latest content. Specifically, we changed the way links are created. Links to our content have the following structure - $linkBase/pageName.htm#i_chronicle_id. E.g. http://customernet.documentum.com/developer/componentexchange.htm#0900c35580be4467. Thus, we don't need the Repository path or DRL. The page name was obtained based on an object attribute that defines the type of posted content (i.e. componentexchange, samplecode, tip).

Installation and Configuration

  • Download the rssStylesheet.zip file.
  • Extract the rssStylesheet.zip file.
  • This file contains the following files -
    • rssGen.xsl - The stylesheet that converts DQL to RSS
    • rssHelper.jar - The jar that contains the class and method to obtain respository path of an object
    • Devprog_RSS.xsl - This is the stylesheet we used to generate the 'Whats New and Updated' RSS feed on the Developer Program website
  • The rssHelper.jar needs to be in the classpath of the application that uses the RSS Stylesheet. If you using it in Web Publisher, reference the rssHelper.jar in the application server's classpath. For example, with Apache Tomcat, you might need to modify the CLASSPATH variable in $TOMCAT_HOME/bin/catalina.bat file.
  • You can modify the rssGen.xsl file to specify your own query and for mapping your own attributes. You can use Devprog_RSS.xsl as an example.
  • If you are using Web Publisher, you can set up the RSS XSL as the presentation file of a template. Refer to Web Publisher documentation for more details on setting up a template.