Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

Writing an RSS Aggregator Part 1

Building an application

So often in this column I feel that I'm writing about basic concepts and using trivial examples. It's often up to you, as the reader, to figure out how to apply these concepts to your development. I thought it might be a good idea to take some space to try to bring a lot of the concepts together and build an application. I don't always take the space to do so, but thought I'd give it a try here.

I'm sure that most of you read (or at least have heard of) blogs. Blogs are a great way to keep up on the up-to-the-minute comings and going of whatever community you choose. There are tons of bloggers throughout the ColdFusion community, some blogging from inside Adobe. Many blogs provide an RSS feed for content. RSS stands for Really Simple Syndication and is an XML dialect. There are a handful of RSS aggregators in the ColdFusion community such as mxna (http://weblogs.macromedia.com/mxna/), Full As a Goog (www.fullasagoog.com/), and Feed Squirrel (www.feed-squirrel.com/). I've always thought it would be cool to create something like a LiveJournal friends list of my very own. In this series of articles, I'm going to step you through the thought process that I'd go through to create one. First I'll concentrate on designing the database and fleshing out the ColdFusion components.

Designing the Back End
When developing an application, I normally start with the database design, and that is where we'll start here. If you need a refresher on database design techniques, you can review the database design article from this column at http://coldfusion.sys-con.com/read/49177.htm. What data do you want to store in an RSS Aggregator application? You can read all about the RSS 2.0 spec at www.rssboard.org/rss-specification. For purposes of this article, I'm only going to concentrate on required fields.

  • RSS Feeds: The RSS feed seems like a good place to start. The app will have to store the name of the RSS feed and the URL location of the feed.
  • Items: Since we're aggregating feed data from a lot of different sources, we'll need to store the posts from each individual feed. It'll be more efficient to store them locally than to create the feed manually each time we want to display something. A post is put into the RSS XML document as an item. According to the spec, nothing is required in the item except for title or description; there's no guarantee that one will be there. For the sake of this article, we'll assume that title, link, and description will be there. Items have a one-to-many relationship with RSS feeds. Each blog can contain many posts, but each post belongs to only one blog. To implement this in the database, we put a primary key for the RSS feed into the items table.
  • Categories: Within the app, I want to be able to categorize each feed, so I can filter the group of messages that I'm reading. We'll add a category table to the database. This data won't be coming from the RSS, but some identifier that we create.
The database structure is shown in Figure 1.

For the model portion of this app, I'm going to use ColdFusion components. You can read more about component basics in two of my articles at http://coldfusion.sys-con.com/read/47203.htm and http://coldfusion.sys-con.com/read/47446.htm. I'd create one CFC for each element: an RSS Feed, an Item, and a Category. You can see the model in Figure 2. You may notice that the CFCs are named in the singular tense, while the database tables are plural. This is because each CFC is designed to represent a single item, while the database tables contain many items. I left out individual getter and setter methods from the diagram, but the code will use the generic getter and setter methods from Hal Helm's BaseComponent.cfc http://halhelms.com/webresources/BaseComponent.cfc. Each component includes an init and a commit method. The init will load information out of the database, while the commit will create (or update) information in the database.

The RSSFeed and RSSCategory components will be used for maintaining feeds and categories. You might notice that the RSSFeed component contains an RSSCategory component instead of the CategoryID foreign key. I thought about putting an array of item objects in the RSSFeed, but decided against it. The application won't need to load all the items from the feed in question; a gateway object can be used to handle this type of action when viewing the data (although that's beyond the scope of this article). The RSSaggregator component is where most of the magic takes place. It will be the background process, run as part of a scheduled task. It will loop through each feed in the database, collect the latest data, and store the new items in the database. It will use the item component.

Creating the RSS Feed Components
In real-world applications, I often like to start by building the administrator first. That way I don't have to worry about filling the tables with fake data to test the public-facing part of the site. Before we can start to process feeds on the back-end, we have to be able to enter the feeds into the database. We can start by fleshing out the RSSFeed and RSSCategory components. First, let's examine the RSSCategory component, as shown in Listing 1. Nothing in the RSSCategory.cfc should surprise you. It contains two instance variables, the CategoryID and Category. The CategoryID is initialized as a string because this app uses UUIDs as primary keys instead of auto-incrementing integers. The component has two methods (plus a few inherited from Hal's BaseComponent.cfc). There's an init method that accepts the CategoryID and the datasource. It queries the database and sets the instance variables, if applicable. The second method is a commit method. It accepts the datasource name as an argument. If the CategoryID is blank, a new category is created. If it isn't, an update is performed. This isn't much different, in concept, from the address.cfc I wrote about in one of my previous component articles.

The RSSFeed component is shown in Listing 2. You'll notice many similarities to the RSSCategory component. There are more properties in RSSFeed than RSSCategory, but the concept is the same. You can notice that the category property of the component is an instance of the RSSCategory component. Instead of containing the category information directly, only the reference is stored. To access the category information, we can use the get, or set, methods off the component instance. The set methods are demonstrated in init; while the get methods are demonstrated in commit.

Entering the Data
To enter the data, a simple HTML form is used, as shown in Listing 3. The first lines include a syslib.cfm file. This is just a utility library of functions. Two functions from the library are used in this component. The GetCategories function contains a query to get all categories. The "CreateSelectList" function is very similar to the cfselect tag for those who don't use cfform. (I'll make sure that all the code behind this article gets up on my blog; I left out the syslib.cfm for brevity).

The file creates an instance of the RSSFeed component. If an RSSFeedID is defined, it will run the init method; otherwise the base component is used. A form is created that asks for the category, and the http link of the RSS feed. The title and description are displayed on this form, but are actually populated from the RSS feed, so they're not editable.

The form submits onto Feedip.cfm, which is shown in Listing 4. The initialization code is the same as in Listing 3. Then the code enters a try block. To get the description and title, we need to call the RSS feed. If the cfhttp call times out, we know that the RSS feed is wrong. The URL could be invalid in other ways, but that's the only thing we check for in this code. XMLParse is called on cfhttp.filecontent. I wrote an article about getting and processing XML feeds this way, and you can read it at http://coldfusion.sys-con.com/read/117667.htm. The remainder of the code sets the instance variables and calls the commit. Congratulations, you've saved a feed in the database.

What's Next
I've just about run out of space for this article, but this app is far from complete. In the next article I'll talk about the RSSAggregator and item componentS. It will create the scheduled task to call the aggregation code. Space permitting, I'll go into a gateway component along with some code that can be used to look at the aggregated data. If there isn't space in the next article for that, I'll fit it into some future article. Until next time, keep coding.

More Stories By Jeffry Houser

Jeffry is a technical entrepreneur with over 10 years of making the web work for you. Lately Jeffry has been cooped up in his cave building the first in a line of easy to use interface components for Flex Developers at www.flextras.com . He has a Computer Science degree from the days before business met the Internet and owns DotComIt, an Adobe Solutions Partner specializing in Rich Internet Applications. Jeffry is an Adobe Community Expert and produces The Flex Show, a podcast that includes expert interviews and screencast tutorials. Jeffry is also co-manager of the Hartford CT Adobe User Group, author of three ColdFusion books and over 30 articles, and has spoken at various events all over the US. In his spare time he is a musician, old school adventure game aficionado, and recording engineer. He also owns a Wii. You can read his blog at www.jeffryhouser.com, check out his podcast at www.theflexshow.com or check out his company at www.dot-com-it.com.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON India News Desk 06/28/06 04:53:01 PM EDT

So often in this column I feel that I'm writing about basic concepts and using trivial examples. It's often up to you, as the reader, to figure out how to apply these concepts to your development. I thought it might be a good idea to take some space to try to bring a lot of the concepts together and build an application. I don't always take the space to do so, but thought I'd give it a try here.

IoT & Smart Cities Stories
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...