/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


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(_1){
this.sync=_1;
},useCache:false,alertsEnabled:false,getFeed:function(_2,_3,_4,_5){
this._getXmlDoc(_2,"feed",new dojox.atom.io.model.Feed(),dojox.atom.io.model._Constants.ATOM_NS,_3,_4,_5);
},getService:function(_6,_7,_8,_9){
this._getXmlDoc(_6,"service",new dojox.atom.io.model.Service(_6),dojox.atom.io.model._Constants.APP_NS,_7,_8,_9);
},getEntry:function(_a,_b,_c,_d){
this._getXmlDoc(_a,"entry",new dojox.atom.io.model.Entry(),dojox.atom.io.model._Constants.ATOM_NS,_b,_c,_d);
},_getXmlDoc:function(_e,_f,_10,_11,_12,_13,_14){
if(!_14){
_14=dojo.global;
}
var ae=this.alertsEnabled;
var _16={url:_e,handleAs:"xml",sync:this.sync,load:function(_17,_18){
var _19=null;
var _1a=_17;
var _1b;
if(_1a){
if(typeof (_1a.getElementsByTagNameNS)!="undefined"){
_1b=_1a.getElementsByTagNameNS(_11,_f);
if(_1b&&_1b.length>0){
_19=_1b.item(0);
}else{
if(_1a.lastChild){
_19=_1a.lastChild;
}
}
}else{
if(typeof (_1a.getElementsByTagName)!="undefined"){
_1b=_1a.getElementsByTagName(_f);
if(_1b&&_1b.length>0){
for(var i=0;i<_1b.length;i++){
if(_1b[i].namespaceURI==_11){
_19=_1b[i];
break;
}
}
}else{
if(_1a.lastChild){
_19=_1a.lastChild;
}
}
}else{
if(_1a.lastChild){
_19=_1a.lastChild;
}else{
_12.call(_14,null,null,_18);
return;
}
}
}
_10.buildFromDom(_19);
if(_12){
_12.call(_14,_10,_1a,_18);
}else{
if(ae){
var _1d=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_1d.noCallback);
}
}
}else{
_12.call(_14,null,null,_18);
}
}};
if(this.user&&this.user!==null){
_16.user=this.user;
}
if(this.password&&this.password!==null){
_16.password=this.password;
}
if(_13){
_16.error=function(_1e,_1f){
_13.call(_14,_1e,_1f);
};
}else{
_16.error=function(){
var _20=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_20.failedXhr);
};
}
dojo.xhrGet(_16);
},updateEntry:function(_21,_22,_23,_24,_25,_26){
if(!_26){
_26=dojo.global;
}
_21.updated=new Date();
var url=_21.getEditHref();
if(!url){
var _28=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_28.missingEditUrl);
}
var _29=this;
var ae=this.alertsEnabled;
var _2b={url:url,handleAs:"text",contentType:"text/xml",sync:this.sync,load:function(_2c,_2d){
var _2e=null;
if(_24){
_2e=_2d.xhr.getResponseHeader("Location");
if(!_2e){
_2e=url;
}
var _2f=function(_30,dom,_32){
if(_22){
_22.call(_26,_30,_2e,_32);
}else{
if(ae){
var _33=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_33.noCallback);
}
}
};
_29.getEntry(_2e,_2f);
}else{
if(_22){
_22.call(_26,_21,_2d.xhr.getResponseHeader("Location"),_2d);
}else{
if(ae){
var _34=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_34.noCallback);
}
}
}
return _2c;
}};
if(this.user&&this.user!==null){
_2b.user=this.user;
}
if(this.password&&this.password!==null){
_2b.password=this.password;
}
if(_23){
_2b.error=function(_35,_36){
_23.call(_26,_35,_36);
};
}else{
_2b.error=function(){
var _37=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_37.failedXhr);
};
}
if(_25){
_2b.postData=_21.toString(true);
_2b.headers={"X-Method-Override":"PUT"};
dojo.rawXhrPost(_2b);
}else{
_2b.putData=_21.toString(true);
var xhr=dojo.rawXhrPut(_2b);
}
},addEntry:function(_39,url,_3b,_3c,_3d,_3e){
if(!_3e){
_3e=dojo.global;
}
_39.published=new Date();
_39.updated=new Date();
var _3f=_39.feedUrl;
var ae=this.alertsEnabled;
if(!url&&_3f){
url=_3f;
}
if(!url){
if(ae){
var _41=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_41.missingUrl);
}
return;
}
var _42=this;
var _43={url:url,handleAs:"text",contentType:"text/xml",sync:this.sync,postData:_39.toString(true),load:function(_44,_45){
var _46=_45.xhr.getResponseHeader("Location");
if(!_46){
_46=url;
}
if(!_45.retrieveEntry){
if(_3b){
_3b.call(_3e,_39,_46,_45);
}else{
if(ae){
var _47=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_47.noCallback);
}
}
}else{
var _48=function(_49,dom,_4b){
if(_3b){
_3b.call(_3e,_49,_46,_4b);
}else{
if(ae){
var _4c=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_4c.noCallback);
}
}
};
_42.getEntry(_46,_48);
}
return _44;
}};
if(this.user&&this.user!==null){
_43.user=this.user;
}
if(this.password&&this.password!==null){
_43.password=this.password;
}
if(_3c){
_43.error=function(_4d,_4e){
_3c.call(_3e,_4d,_4e);
};
}else{
_43.error=function(){
var _4f=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_4f.failedXhr);
};
}
dojo.rawXhrPost(_43);
},deleteEntry:function(_50,_51,_52,_53,_54){
if(!_54){
_54=dojo.global;
}
var url=null;
if(typeof (_50)=="string"){
url=_50;
}else{
url=_50.getEditHref();
}
if(!url){
var _56=dojo.i18n.getLocalization("dojox.atom.io","messages");
_51.call(_54,false,null);
throw new Error(_56.missingUrl);
}
var _57={url:url,handleAs:"text",sync:this.sync,load:function(_58,_59){
_51.call(_54,_59);
return _58;
}};
if(this.user&&this.user!==null){
_57.user=this.user;
}
if(this.password&&this.password!==null){
_57.password=this.password;
}
if(_52){
_57.error=function(_5a,_5b){
_52.call(_54,_5a,_5b);
};
}else{
_57.error=function(){
var _5c=dojo.i18n.getLocalization("dojox.atom.io","messages");
throw new Error(_5c.failedXhr);
};
}
if(_53){
_57.headers={"X-Method-Override":"DELETE"};
dojo.xhrPost(_57);
}else{
dojo.xhrDelete(_57);
}
}});
}
