dojo.provide('dojox.atom.io.Connection'); dojo.require('dojox.atom.io.model'); dojo.declare("dojox.atom.io.Connection",null,{ // summary: This object implements a transport layer for working with ATOM feeds and ATOM publishing protocols. // description: This object implements a transport layer for working with ATOM feeds and ATOM publishing protocols. // Specifically, it provides a mechanism by which feeds can be fetched and entries can be fetched, created // deleted, and modified. It also provides access to the introspection data. constructor: function(/* Boolean */sync, /* Boolean */preventCache){ // summary: // initializer this.sync = sync; this.preventCache = preventCache; }, preventCache: false, //Flag to denote if the instance should use the xhr prevent cache mechanism alertsEnabled: false, //Flag to turn on alerts instead of throwing errors. getFeed: function(/*String*/url, /*Function*/callback, /*Function*/errorCallback, scope){ // summary: // Function to obtain a s specific ATOM feed from a given ATOM Feed url. // description: // This function takes the URL for a specific ATOM feed and returns // the data from that feed to the caller through the use of a callback // handler. // // url: String // The URL of the ATOM feed to fetch. // callback: // Function // A function reference that will handle the feed when it has been retrieved. // The callback should accept two parameters: The feed object and the original complete DOM object. // scope: Object // The scope to use for all callbacks. // // returns: // Nothing. The return is handled through the callback handler. this._getXmlDoc(url, "feed", new dojox.atom.io.model.Feed(), dojox.atom.io.model._Constants.ATOM_NS, callback, /*handleDocumentRetrieved,*/ errorCallback, scope); }, getService: function(url, callback, errorCallback, scope){ // summary: // Function to retrieve an introspection document from the given URL. // description: // This function takes the URL for an ATOM item and feed and returns // the introspection document. // // url: // String // The URL of the ATOM document to obtain the introspection document of. // callback: // Function // A function reference that will handle the introspection document when it has been retrieved. // The callback should accept two parameters: The introspection document object and the original complete DOM object. // // returns: // Nothing. The return is handled through the callback handler. this._getXmlDoc(url, "service", new dojox.atom.io.model.Service(url), dojox.atom.io.model._Constants.APP_NS, callback, errorCallback, scope); }, getEntry: function(url, callback, errorCallback, scope){ // summary: // Function to retrieve a single entry from an ATOM feed from the given URL. // description: // This function takes the URL for an ATOM entry and returns the constructed dojox.atom.io.model.Entry object through // the specified callback. // // url: // String // The URL of the ATOM Entry document to parse. // callback: // Function // A function reference that will handle the Entry object obtained. // The callback should accept two parameters, the dojox.atom.io.model.Entry object and the original dom. // // returns: // Nothing. The return is handled through the callback handler. this._getXmlDoc(url, "entry", new dojox.atom.io.model.Entry(), dojox.atom.io.model._Constants.ATOM_NS, callback, errorCallback, scope); }, _getXmlDoc: function(url, nodeName, newNode, namespace, callback, errorCallback, scope){ // summary: // Internal Function to retrieve an XML document and pass the results to a callback. // description: // This internal function takes the URL for an XML document and and passes the // parsed contents to a specified callback. // // url: // String // The URL of the XML document to retrieve // callback: // Function // A function reference that will handle the retrieved XML data. // The callback should accept one parameter, the DOM of the parsed XML document. // // returns: // Nothing. The return is handled through the callback handler. if(!scope){ scope = dojo.global; } var ae = this.alertsEnabled; var xhrArgs = { url: url, handleAs: "xml", sync: this.sync, preventCache: this.preventCache, load: function(data, args){ var node = null; var evaldObj = data; var nodes; if(evaldObj){ //find the first node of the appropriate name if(typeof(evaldObj.getElementsByTagNameNS)!= "undefined"){ nodes = evaldObj.getElementsByTagNameNS(namespace,nodeName); if(nodes && nodes.length > 0){ node = nodes.item(0); }else if(evaldObj.lastChild){ // name_spaces can be used without declaration of atom (for example // gooogle feeds often returns iTunes name_space qualifiers on elements) // Treat this situation like name_spaces not enabled. node = evaldObj.lastChild; } }else if(typeof(evaldObj.getElementsByTagName)!= "undefined"){ // Find the first eith the correct tag name and correct namespace. nodes = evaldObj.getElementsByTagName(nodeName); if(nodes && nodes.length > 0){ for(var i=0; i