Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Journal Articles to RSS Feed

RSS Feeds and Journal Content#

This entry will describe how to use an how to create an RSS feed using your Journal Articles. I am going to assume that you already know XSL.

Creating RSS Feeds using Journal Templates #

XSLT is a transform language to modify XML documents to another form of XML. Since Liferay's Journal is capable of returning search in an XML document, XSL is a great way to change the search results to an RSS feed.

The URL need to return search queries is below:

http://@portal_url@/c/journal/get_articles?

Immediately following the "?" is the criteria for the search in the format [parameter]=[variable]. In the example below we are asking for articles that have a display date less than 1/1/2003.

displayDateLT=20030101

Listed below are the most commonly used arguments. Multiple parameters can be used and should be separated by an escaped ampersand, "&". Note: To use the URL in your browser be sure to change each "&" to an non-escaped ampersand, "&".

  • groupId
    • This parameter searches a particular group. When set to @group_ID@ it will only search for content in the community where the article resides.
  • templateId
    • This parameter restricts the search to articles created with a certain template. Note: Be sure to set this to the templates ID and not the templates name.
  • orderBy
    • This parameter sorts the results by the method passed.
  • type
    • Much like templateID, this parameter will restrict the results to articles that are created with the specified type.
  • displayDateGT
    • This parameter will restrict articles that are greater then the specified time. Note: Takes the form, YYYYMMDD.
  • displayDateLT
    • This parameter will restrict articles that are less than the specified time. Note: Takes the form YYYYMMDD.
  • delta
    • This parameter will restrict the result set to a specified amount.

Example#

The following is an incomplete example illustrating how to create an RSS Feed using XSL.

  <?xml version="1.0"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">  
    <xsl:output method="xml" omit-xml-declaration="no" media-type="application/rss+xml" indent="yes" />
    <xsl:template match="/">
      <xsl:variable name="articles" select="document('http://@portal_url@/c/journal/get_articles?groupId=@group_id@&amp;templateId=BASIC-RSS-ITEM&amp;delta=20&amp;orderBy=display-date')/result-set/result"/>
      <rss version="2.0">
        <channel>
          <title>
            <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='rss-title']/dynamic-content"/>
          </title>
          <link>
            <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='rss-link']/dynamic-content"/>
          </link>
          <description>
            <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='rss-description']/dynamic-content"/>
          </description>
  
          <xsl:for-each select="$articles">
            <item>
              <title>
                <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='headline']/dynamic-content"/>
              </title>
              <link>
                <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='link']/dynamic-content"/>
              </link>
              <description>
                <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='description']/dynamic-content"/>
              </description>
              <author>
                <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='creator']/dynamic-content"/>
                <xsl:text> &lt;pr@liferay.com&gt;</xsl:text>
              </author>
              <guid isPermaLink="false">
                <xsl:text>http://@portal_url@/c/journal/view_article_content?groupId=14&amp;articleId=</xsl:text>
                <xsl:value-of disable-output-escaping="no" select="root/dynamic-element[@name='reserved-article-id']/dynamic-content"/>
              </guid>
            </item>
          </xsl:for-each>
        </channel>
      </rss>
    </xsl:template>
  </xsl:stylesheet>

Journal Internal API shows in great detail on how the result set is formed.

0 Attachments
30011 Views
Average (3 Votes)
The average rating is 1.66666666666667 stars out of 5.
Comments