Accessibility

Table of Contents

The RSS Watch Sample App (Part 1): Monitoring RSS Feeds Automatically

The getSearches Method

The first method, getSearches, returns a set of data specifying the words to search for and which RSS feed to examine. The method returns an array. Each item in the array is a structure with two keys: terms and rss. Terms is a string that represents the search terms; RSS is an array of URLs that are valid RSS feeds.

What’s interesting is that when I began designing this CFC, I wasn’t sure how I wanted to store the configuration data. I knew it would be in an XML file, but I wasn’t 100% sure of how I would set it up. For that reason, the original version of the CFC method contains static data, as shown in Listing 1.

Listing 1 : Original version of the getSearches method, which contains static data

<cffunction name="getSearches" returnType="array" 
output="false" access="private"
		hint="Handles getting search data and returning it to the processor">
	
	<cfset var aSearches = arrayNew(1)>
	
	<cfset aSearches[1] = structNew()>
	<cfset aSearches[1].terms = "camden">
	<cfset aSearches[1].rss = arrayNew(1)>
	<cfset aSearches[1].rss[1] = "http://www.fullasagoog.com/xml/ColdFusionMX.xml">

	<cfset aSearches[2] = structNew()>
	<cfset aSearches[2].terms = "blog">
	<cfset aSearches[2].rss = arrayNew(1)>
	<cfset aSearches[2].rss[1] = "http://www.camdenfamily.com/morpheus/blog/rss.cfm?mode=short&">
	
	<cfreturn aSearches>
	
</cffunction>

If you remember, I said the return data is an array of structures. In the code above, I’ve simply hard coded two items. The first item searches the RSS feed, FullAsAGoog, for any mention of my last name. (What? You mean you didn’t realize I was simply building this as an ego booster?!?) The second item searches for the word "blog" in the RSS feed for my own blog.

Obviously this static data isn’t the final version of the method, but because I have to create a structure in which to return data, I can leave this code as is and focus on the more difficult aspects of the application.