123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- if(!dojo._hasResource['dojox.atom.io.Connection']){
- dojo._hasResource['dojox.atom.io.Connection'] = true;
- dojo.provide('dojox.atom.io.Connection');
- dojo.require('dojox.atom.io.model');
- dojo.declare("dojox.atom.io.Connection",null,{
-
-
-
-
- constructor: function(/* Boolean */sync, /* Boolean */preventCache){
-
-
- this.sync = sync;
- this.preventCache = preventCache;
- },
- preventCache: false,
- alertsEnabled: false,
- getFeed: function(/*String*/url, /*Function*/callback, /*Function*/errorCallback, scope){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this._getXmlDoc(url, "feed", new dojox.atom.io.model.Feed(), dojox.atom.io.model._Constants.ATOM_NS, callback, errorCallback, scope);
- },
-
- getService: function(url, callback, errorCallback, scope){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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){
-
- if(typeof(evaldObj.getElementsByTagNameNS)!= "undefined"){
- nodes = evaldObj.getElementsByTagNameNS(namespace,nodeName);
- if(nodes && nodes.length > 0){
- node = nodes.item(0);
- }else if(evaldObj.lastChild){
-
-
-
- node = evaldObj.lastChild;
- }
- }else if(typeof(evaldObj.getElementsByTagName)!= "undefined"){
-
- nodes = evaldObj.getElementsByTagName(nodeName);
- if(nodes && nodes.length > 0){
- for(var i=0; i<nodes.length; i++){
- if(nodes[i].namespaceURI == namespace){
- node = nodes[i];
- break;
- }
- }
- }else if(evaldObj.lastChild){
- node = evaldObj.lastChild;
- }
- }else if(evaldObj.lastChild){
- node = evaldObj.lastChild;
- }else{
- callback.call(scope, null, null, args);
- return;
- }
- newNode.buildFromDom(node);
- if(callback){
- callback.call(scope, newNode, evaldObj, args);
- }else if(ae){
- throw new Error("The callback value does not exist.");
- }
- }else{
- callback.call(scope, null, null, args);
- }
- }
- };
- if(this.user && this.user !== null){
- xhrArgs.user = this.user;
- }
- if(this.password && this.password !== null){
- xhrArgs.password = this.password;
- }
- if(errorCallback){
- xhrArgs.error = function(error, args){errorCallback.call(scope, error, args);};
- }else{
- xhrArgs.error = function(){
- throw new Error("The URL requested cannot be accessed");
- };
- }
- dojo.xhrGet(xhrArgs);
- },
- updateEntry: function(entry, callback, errorCallback, retrieveUpdated, xmethod, scope){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(!scope){
- scope = dojo.global;
- }
- entry.updated = new Date();
- var url = entry.getEditHref();
- if(!url){
- throw new Error("A URL has not been specified for editing this entry.");
- }
- var self = this;
- var ae = this.alertsEnabled;
- var xhrArgs = {
- url: url,
- handleAs: "text",
- contentType: "text/xml",
- sync: this.sync,
- preventCache: this.preventCache,
- load: function(data, args){
- var location = null;
- if(retrieveUpdated){
- location = args.xhr.getResponseHeader("Location");
- if(!location){location = url;}
-
-
- var handleRetrieve = function(entry, dom, args){
- if(callback){
- callback.call(scope, entry, location, args);
- }else if(ae){
- throw new Error("The callback value does not exist.");
- }
- };
- self.getEntry(location,handleRetrieve);
- }else{
- if(callback){
- callback.call(scope, entry, args.xhr.getResponseHeader("Location"), args);
- }else if(ae){
- throw new Error("The callback value does not exist.");
- }
- }
- return data;
- }
- };
-
- if(this.user && this.user !== null){
- xhrArgs.user = this.user;
- }
- if(this.password && this.password !== null){
- xhrArgs.password = this.password;
- }
- if(errorCallback){
- xhrArgs.error = function(error, args){errorCallback.call(scope, error, args);};
- }else{
- xhrArgs.error = function(){
- throw new Error("The URL requested cannot be accessed");
- };
- }
- if(xmethod){
- xhrArgs.postData = entry.toString(true);
- xhrArgs.headers = {"X-Method-Override": "PUT"};
- dojo.rawXhrPost(xhrArgs);
- }else{
- xhrArgs.putData = entry.toString(true);
- var xhr = dojo.rawXhrPut(xhrArgs);
- }
- },
- addEntry: function(entry, url, callback, errorCallback, retrieveEntry, scope){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(!scope){
- scope = dojo.global;
- }
- entry.published = new Date();
- entry.updated = new Date();
- var feedUrl = entry.feedUrl;
- var ae = this.alertsEnabled;
-
- if(!url && feedUrl){url = feedUrl;}
- if(!url){
- if(ae){
- throw new Error("The request cannot be processed because the URL parameter is missing.");
- }
- return;
- }
- var self = this;
- var xhrArgs = {
- url: url,
- handleAs: "text",
- contentType: "text/xml",
- sync: this.sync,
- preventCache: this.preventCache,
- postData: entry.toString(true),
- load: function(data, args){
- var location = args.xhr.getResponseHeader("Location");
- if(!location){
- location = url;
- }
- if(!args.retrieveEntry){
- if(callback){
- callback.call(scope, entry, location, args);
- }else if(ae){
- throw new Error("The callback value does not exist.");
- }
- }else{
-
-
- var handleRetrieve = function(entry, dom, args){
- if(callback){
- callback.call(scope, entry, location, args);
- }else if(ae){
- throw new Error("The callback value does not exist.");
- }
- };
- self.getEntry(location,handleRetrieve);
- }
- return data;
- }
- };
- if(this.user && this.user !== null){
- xhrArgs.user = this.user;
- }
- if(this.password && this.password !== null){
- xhrArgs.password = this.password;
- }
- if(errorCallback){
- xhrArgs.error = function(error, args){errorCallback.call(scope, error, args);};
- }else{
- xhrArgs.error = function(){
- throw new Error("The URL requested cannot be accessed");
- };
- }
- dojo.rawXhrPost(xhrArgs);
- },
- deleteEntry: function(entry,callback,errorCallback,xmethod,scope){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(!scope){
- scope = dojo.global;
- }
- var url = null;
- if(typeof(entry) == "string"){
- url = entry;
- }else{
- url = entry.getEditHref();
- }
- if(!url){
- callback.call(scope, false, null);
- throw new Error("The request cannot be processed because the URL parameter is missing.");
- }
- var xhrArgs = {
- url: url,
- handleAs: "text",
- sync: this.sync,
- preventCache: this.preventCache,
- load: function(data, args){
- callback.call(scope, args);
- return data;
- }
- };
- if(this.user && this.user !== null){
- xhrArgs.user = this.user;
- }
- if(this.password && this.password !== null){
- xhrArgs.password = this.password;
- }
- if(errorCallback){
- xhrArgs.error = function(error, args){errorCallback.call(scope, error, args);};
- }else{
- xhrArgs.error = function(){
- throw new Error("The URL requested cannot be accessed");
- };
- }
- if(xmethod){
- xhrArgs.headers = {"X-Method-Override": "DELETE"};
- dojo.xhrPost(xhrArgs);
- }else{
- dojo.xhrDelete(xhrArgs);
- }
- }
- });
- }
|