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.

@ThingsExpo Stories
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
The Founder of NostaLab and a member of the Google Health Advisory Board, John is a unique combination of strategic thinker, marketer and entrepreneur. His career was built on the "science of advertising" combining strategy, creativity and marketing for industry-leading results. Combined with his ability to communicate complicated scientific concepts in a way that consumers and scientists alike can appreciate, John is a sought-after speaker for conferences on the forefront of healthcare science,...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Archi...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settl...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...