Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

The Feed Object

The Feed object is a prototype. Through its constructor function, the Feed object receives all of the parameters that we passed when we created it in the Aggregator object. These parameters are the ID, title, link, and items of the feed. In this function we set all of our default values, create some arrays for later use, and send the items to a method called parseItems. The parseItems method is where we retrieve all of the values from our feed items and populate the arrays that we created in the constructor.

Feed.prototype.parseItems = function(items)
  for(var i=0; i<items.length; i++)
    var linkTitle = items[i].getElementsByTagName("title")[0].firstChild.nodeValue;
    var title = "<a href=’#’ class=’title’ onclick=’Aggregator.DisplayFeed("+ this.id +", "+ i +");’>" + linkTitle +"</a>";

    var _link = items[i].getElementsByTagName("link")[0].firstChild.nodeValue;

    var description = items[i].getElementsByTagName("description")[0].firstChild.nodeValue;

    var pubDate = items[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue;

Once we have all of our values stored in arrays, we can use them when we’re ready to display the data in the page. The last three methods in this object focus on displaying the data of the feed:

  • GetTitle is used to get the title of the feed as a link that toggles the item titles by calling the Aggregator’s toggleTitles method.
  • GetAllTitles simply returns all the item titles from the feed.
  • GetDetails is all about the displaying the feed details. This method retrieves the values from the Feed object’s arrays based on the ID that’s passed as a parameter. The values are then formatted into an HTML string and returned to the caller, which then adds them to the index page.
Feed.prototype.GetTitle = function()
  return "<div id=’title_"+ this.id +"’><br/><a href=’#’ onclick=’Aggregator.ToggleTitles("+ this.id +");’>" + this.title + "</a></div>";

Feed.prototype.GetAllTitles = function()
  return this.titleArray;

Feed.prototype.GetDetails = function(id)
  details = "<a href=’"+ this.linkArray[id] +"’ target=’_blank’>"+ this.linkTitleArray[id] +"</a><br/>";
  details += this.descriptionArray[id] +"<br/>";
  details += this.pubDateArray[id];
  return details;
  • + Share This
  • 🔖 Save To Your Account