Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / atom / io / Connection.js

History | View | Annotate | Download (5.35 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.atom.io.Connection"]){
9
dojo._hasResource["dojox.atom.io.Connection"]=true;
10
dojo.provide("dojox.atom.io.Connection");
11
dojo.require("dojox.atom.io.model");
12
dojo.declare("dojox.atom.io.Connection",null,{constructor:function(_1,_2){
13
this.sync=_1;
14
this.preventCache=_2;
15
},preventCache:false,alertsEnabled:false,getFeed:function(_3,_4,_5,_6){
16
this._getXmlDoc(_3,"feed",new dojox.atom.io.model.Feed(),dojox.atom.io.model._Constants.ATOM_NS,_4,_5,_6);
17
},getService:function(_7,_8,_9,_a){
18
this._getXmlDoc(_7,"service",new dojox.atom.io.model.Service(_7),dojox.atom.io.model._Constants.APP_NS,_8,_9,_a);
19
},getEntry:function(_b,_c,_d,_e){
20
this._getXmlDoc(_b,"entry",new dojox.atom.io.model.Entry(),dojox.atom.io.model._Constants.ATOM_NS,_c,_d,_e);
21
},_getXmlDoc:function(_f,_10,_11,_12,_13,_14,_15){
22
if(!_15){
23
_15=dojo.global;
24
}
25
var ae=this.alertsEnabled;
26
var _16={url:_f,handleAs:"xml",sync:this.sync,preventCache:this.preventCache,load:function(_17,_18){
27
var _19=null;
28
var _1a=_17;
29
var _1b;
30
if(_1a){
31
if(typeof (_1a.getElementsByTagNameNS)!="undefined"){
32
_1b=_1a.getElementsByTagNameNS(_12,_10);
33
if(_1b&&_1b.length>0){
34
_19=_1b.item(0);
35
}else{
36
if(_1a.lastChild){
37
_19=_1a.lastChild;
38
}
39
}
40
}else{
41
if(typeof (_1a.getElementsByTagName)!="undefined"){
42
_1b=_1a.getElementsByTagName(_10);
43
if(_1b&&_1b.length>0){
44
for(var i=0;i<_1b.length;i++){
45
if(_1b[i].namespaceURI==_12){
46
_19=_1b[i];
47
break;
48
}
49
}
50
}else{
51
if(_1a.lastChild){
52
_19=_1a.lastChild;
53
}
54
}
55
}else{
56
if(_1a.lastChild){
57
_19=_1a.lastChild;
58
}else{
59
_13.call(_15,null,null,_18);
60
return;
61
}
62
}
63
}
64
_11.buildFromDom(_19);
65
if(_13){
66
_13.call(_15,_11,_1a,_18);
67
}else{
68
if(ae){
69
throw new Error("The callback value does not exist.");
70
}
71
}
72
}else{
73
_13.call(_15,null,null,_18);
74
}
75
}};
76
if(this.user&&this.user!==null){
77
_16.user=this.user;
78
}
79
if(this.password&&this.password!==null){
80
_16.password=this.password;
81
}
82
if(_14){
83
_16.error=function(_1c,_1d){
84
_14.call(_15,_1c,_1d);
85
};
86
}else{
87
_16.error=function(){
88
throw new Error("The URL requested cannot be accessed");
89
};
90
}
91
dojo.xhrGet(_16);
92
},updateEntry:function(_1e,_1f,_20,_21,_22,_23){
93
if(!_23){
94
_23=dojo.global;
95
}
96
_1e.updated=new Date();
97
var url=_1e.getEditHref();
98
if(!url){
99
throw new Error("A URL has not been specified for editing this entry.");
100
}
101
var _24=this;
102
var ae=this.alertsEnabled;
103
var _25={url:url,handleAs:"text",contentType:"text/xml",sync:this.sync,preventCache:this.preventCache,load:function(_26,_27){
104
var _28=null;
105
if(_21){
106
_28=_27.xhr.getResponseHeader("Location");
107
if(!_28){
108
_28=url;
109
}
110
var _29=function(_2a,dom,_2b){
111
if(_1f){
112
_1f.call(_23,_2a,_28,_2b);
113
}else{
114
if(ae){
115
throw new Error("The callback value does not exist.");
116
}
117
}
118
};
119
_24.getEntry(_28,_29);
120
}else{
121
if(_1f){
122
_1f.call(_23,_1e,_27.xhr.getResponseHeader("Location"),_27);
123
}else{
124
if(ae){
125
throw new Error("The callback value does not exist.");
126
}
127
}
128
}
129
return _26;
130
}};
131
if(this.user&&this.user!==null){
132
_25.user=this.user;
133
}
134
if(this.password&&this.password!==null){
135
_25.password=this.password;
136
}
137
if(_20){
138
_25.error=function(_2c,_2d){
139
_20.call(_23,_2c,_2d);
140
};
141
}else{
142
_25.error=function(){
143
throw new Error("The URL requested cannot be accessed");
144
};
145
}
146
if(_22){
147
_25.postData=_1e.toString(true);
148
_25.headers={"X-Method-Override":"PUT"};
149
dojo.rawXhrPost(_25);
150
}else{
151
_25.putData=_1e.toString(true);
152
var xhr=dojo.rawXhrPut(_25);
153
}
154
},addEntry:function(_2e,url,_2f,_30,_31,_32){
155
if(!_32){
156
_32=dojo.global;
157
}
158
_2e.published=new Date();
159
_2e.updated=new Date();
160
var _33=_2e.feedUrl;
161
var ae=this.alertsEnabled;
162
if(!url&&_33){
163
url=_33;
164
}
165
if(!url){
166
if(ae){
167
throw new Error("The request cannot be processed because the URL parameter is missing.");
168
}
169
return;
170
}
171
var _34=this;
172
var _35={url:url,handleAs:"text",contentType:"text/xml",sync:this.sync,preventCache:this.preventCache,postData:_2e.toString(true),load:function(_36,_37){
173
var _38=_37.xhr.getResponseHeader("Location");
174
if(!_38){
175
_38=url;
176
}
177
if(!_37.retrieveEntry){
178
if(_2f){
179
_2f.call(_32,_2e,_38,_37);
180
}else{
181
if(ae){
182
throw new Error("The callback value does not exist.");
183
}
184
}
185
}else{
186
var _39=function(_3a,dom,_3b){
187
if(_2f){
188
_2f.call(_32,_3a,_38,_3b);
189
}else{
190
if(ae){
191
throw new Error("The callback value does not exist.");
192
}
193
}
194
};
195
_34.getEntry(_38,_39);
196
}
197
return _36;
198
}};
199
if(this.user&&this.user!==null){
200
_35.user=this.user;
201
}
202
if(this.password&&this.password!==null){
203
_35.password=this.password;
204
}
205
if(_30){
206
_35.error=function(_3c,_3d){
207
_30.call(_32,_3c,_3d);
208
};
209
}else{
210
_35.error=function(){
211
throw new Error("The URL requested cannot be accessed");
212
};
213
}
214
dojo.rawXhrPost(_35);
215
},deleteEntry:function(_3e,_3f,_40,_41,_42){
216
if(!_42){
217
_42=dojo.global;
218
}
219
var url=null;
220
if(typeof (_3e)=="string"){
221
url=_3e;
222
}else{
223
url=_3e.getEditHref();
224
}
225
if(!url){
226
_3f.call(_42,false,null);
227
throw new Error("The request cannot be processed because the URL parameter is missing.");
228
}
229
var _43={url:url,handleAs:"text",sync:this.sync,preventCache:this.preventCache,load:function(_44,_45){
230
_3f.call(_42,_45);
231
return _44;
232
}};
233
if(this.user&&this.user!==null){
234
_43.user=this.user;
235
}
236
if(this.password&&this.password!==null){
237
_43.password=this.password;
238
}
239
if(_40){
240
_43.error=function(_46,_47){
241
_40.call(_42,_46,_47);
242
};
243
}else{
244
_43.error=function(){
245
throw new Error("The URL requested cannot be accessed");
246
};
247
}
248
if(_41){
249
_43.headers={"X-Method-Override":"DELETE"};
250
dojo.xhrPost(_43);
251
}else{
252
dojo.xhrDelete(_43);
253
}
254
}});
255
}