Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / atom / io / model.js @ 12

History | View | Annotate | Download (22.8 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.model"]){
9
dojo._hasResource["dojox.atom.io.model"]=true;
10
dojo.provide("dojox.atom.io.model");
11
dojo.require("dojox.xml.parser");
12
dojo.require("dojo.string");
13
dojo.require("dojo.date.stamp");
14
dojox.atom.io.model._Constants={"ATOM_URI":"http://www.w3.org/2005/Atom","ATOM_NS":"http://www.w3.org/2005/Atom","PURL_NS":"http://purl.org/atom/app#","APP_NS":"http://www.w3.org/2007/app"};
15
dojox.atom.io.model._actions={"link":function(_1,_2){
16
if(_1.links===null){
17
_1.links=[];
18
}
19
var _3=new dojox.atom.io.model.Link();
20
_3.buildFromDom(_2);
21
_1.links.push(_3);
22
},"author":function(_4,_5){
23
if(_4.authors===null){
24
_4.authors=[];
25
}
26
var _6=new dojox.atom.io.model.Person("author");
27
_6.buildFromDom(_5);
28
_4.authors.push(_6);
29
},"contributor":function(_7,_8){
30
if(_7.contributors===null){
31
_7.contributors=[];
32
}
33
var _9=new dojox.atom.io.model.Person("contributor");
34
_9.buildFromDom(_8);
35
_7.contributors.push(_9);
36
},"category":function(_a,_b){
37
if(_a.categories===null){
38
_a.categories=[];
39
}
40
var _c=new dojox.atom.io.model.Category();
41
_c.buildFromDom(_b);
42
_a.categories.push(_c);
43
},"icon":function(_d,_e){
44
_d.icon=dojox.xml.parser.textContent(_e);
45
},"id":function(_f,_10){
46
_f.id=dojox.xml.parser.textContent(_10);
47
},"rights":function(obj,_11){
48
obj.rights=dojox.xml.parser.textContent(_11);
49
},"subtitle":function(obj,_12){
50
var cnt=new dojox.atom.io.model.Content("subtitle");
51
cnt.buildFromDom(_12);
52
obj.subtitle=cnt;
53
},"title":function(obj,_13){
54
var cnt=new dojox.atom.io.model.Content("title");
55
cnt.buildFromDom(_13);
56
obj.title=cnt;
57
},"updated":function(obj,_14){
58
obj.updated=dojox.atom.io.model.util.createDate(_14);
59
},"issued":function(obj,_15){
60
obj.issued=dojox.atom.io.model.util.createDate(_15);
61
},"modified":function(obj,_16){
62
obj.modified=dojox.atom.io.model.util.createDate(_16);
63
},"published":function(obj,_17){
64
obj.published=dojox.atom.io.model.util.createDate(_17);
65
},"entry":function(obj,_18){
66
if(obj.entries===null){
67
obj.entries=[];
68
}
69
var _19=obj.createEntry?obj.createEntry():new dojox.atom.io.model.Entry();
70
_19.buildFromDom(_18);
71
obj.entries.push(_19);
72
},"content":function(obj,_1a){
73
var cnt=new dojox.atom.io.model.Content("content");
74
cnt.buildFromDom(_1a);
75
obj.content=cnt;
76
},"summary":function(obj,_1b){
77
var _1c=new dojox.atom.io.model.Content("summary");
78
_1c.buildFromDom(_1b);
79
obj.summary=_1c;
80
},"name":function(obj,_1d){
81
obj.name=dojox.xml.parser.textContent(_1d);
82
},"email":function(obj,_1e){
83
obj.email=dojox.xml.parser.textContent(_1e);
84
},"uri":function(obj,_1f){
85
obj.uri=dojox.xml.parser.textContent(_1f);
86
},"generator":function(obj,_20){
87
obj.generator=new dojox.atom.io.model.Generator();
88
obj.generator.buildFromDom(_20);
89
}};
90
dojox.atom.io.model.util={createDate:function(_21){
91
var _22=dojox.xml.parser.textContent(_21);
92
if(_22){
93
return dojo.date.stamp.fromISOString(dojo.trim(_22));
94
}
95
return null;
96
},escapeHtml:function(str){
97
return str.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/"/gm,"&quot;").replace(/'/gm,"&#39;");
98
},unEscapeHtml:function(str){
99
return str.replace(/&lt;/gm,"<").replace(/&gt;/gm,">").replace(/&quot;/gm,"\"").replace(/&#39;/gm,"'").replace(/&amp;/gm,"&");
100
},getNodename:function(_23){
101
var _24=null;
102
if(_23!==null){
103
_24=_23.localName?_23.localName:_23.nodeName;
104
if(_24!==null){
105
var _25=_24.indexOf(":");
106
if(_25!==-1){
107
_24=_24.substring((_25+1),_24.length);
108
}
109
}
110
}
111
return _24;
112
}};
113
dojo.declare("dojox.atom.io.model.Node",null,{constructor:function(_26,_27,_28,_29,_2a){
114
this.name_space=_26;
115
this.name=_27;
116
this.attributes=[];
117
if(_28){
118
this.attributes=_28;
119
}
120
this.content=[];
121
this.rawNodes=[];
122
this.textContent=null;
123
if(_29){
124
this.content.push(_29);
125
}
126
this.shortNs=_2a;
127
this._objName="Node";
128
},buildFromDom:function(_2b){
129
this._saveAttributes(_2b);
130
this.name_space=_2b.namespaceURI;
131
this.shortNs=_2b.prefix;
132
this.name=dojox.atom.io.model.util.getNodename(_2b);
133
for(var x=0;x<_2b.childNodes.length;x++){
134
var c=_2b.childNodes[x];
135
if(dojox.atom.io.model.util.getNodename(c)!="#text"){
136
this.rawNodes.push(c);
137
var n=new dojox.atom.io.model.Node();
138
n.buildFromDom(c,true);
139
this.content.push(n);
140
}else{
141
this.content.push(c.nodeValue);
142
}
143
}
144
this.textContent=dojox.xml.parser.textContent(_2b);
145
},_saveAttributes:function(_2c){
146
if(!this.attributes){
147
this.attributes=[];
148
}
149
var _2d=function(_2e){
150
var _2f=_2e.attributes;
151
if(_2f===null){
152
return false;
153
}
154
return (_2f.length!==0);
155
};
156
if(_2d(_2c)&&this._getAttributeNames){
157
var _30=this._getAttributeNames(_2c);
158
if(_30&&_30.length>0){
159
for(var x in _30){
160
var _31=_2c.getAttribute(_30[x]);
161
if(_31){
162
this.attributes[_30[x]]=_31;
163
}
164
}
165
}
166
}
167
},addAttribute:function(_32,_33){
168
this.attributes[_32]=_33;
169
},getAttribute:function(_34){
170
return this.attributes[_34];
171
},_getAttributeNames:function(_35){
172
var _36=[];
173
for(var i=0;i<_35.attributes.length;i++){
174
_36.push(_35.attributes[i].nodeName);
175
}
176
return _36;
177
},toString:function(){
178
var xml=[];
179
var x;
180
var _37=(this.shortNs?this.shortNs+":":"")+this.name;
181
var _38=(this.name=="#cdata-section");
182
if(_38){
183
xml.push("<![CDATA[");
184
xml.push(this.textContent);
185
xml.push("]]>");
186
}else{
187
xml.push("<");
188
xml.push(_37);
189
if(this.name_space){
190
xml.push(" xmlns='"+this.name_space+"'");
191
}
192
if(this.attributes){
193
for(x in this.attributes){
194
xml.push(" "+x+"='"+this.attributes[x]+"'");
195
}
196
}
197
if(this.content){
198
xml.push(">");
199
for(x in this.content){
200
xml.push(this.content[x]);
201
}
202
xml.push("</"+_37+">\n");
203
}else{
204
xml.push("/>\n");
205
}
206
}
207
return xml.join("");
208
},addContent:function(_39){
209
this.content.push(_39);
210
}});
211
dojo.declare("dojox.atom.io.model.AtomItem",dojox.atom.io.model.Node,{constructor:function(_3a){
212
this.ATOM_URI=dojox.atom.io.model._Constants.ATOM_URI;
213
this.links=null;
214
this.authors=null;
215
this.categories=null;
216
this.contributors=null;
217
this.icon=this.id=this.logo=this.xmlBase=this.rights=null;
218
this.subtitle=this.title=null;
219
this.updated=this.published=null;
220
this.issued=this.modified=null;
221
this.content=null;
222
this.extensions=null;
223
this.entries=null;
224
this.name_spaces={};
225
this._objName="AtomItem";
226
},_getAttributeNames:function(){
227
return null;
228
},_accepts:{},accept:function(tag){
229
return Boolean(this._accepts[tag]);
230
},_postBuild:function(){
231
},buildFromDom:function(_3b){
232
var i,c,n;
233
for(i=0;i<_3b.attributes.length;i++){
234
c=_3b.attributes.item(i);
235
n=dojox.atom.io.model.util.getNodename(c);
236
if(c.prefix=="xmlns"&&c.prefix!=n){
237
this.addNamespace(c.nodeValue,n);
238
}
239
}
240
c=_3b.childNodes;
241
for(i=0;i<c.length;i++){
242
if(c[i].nodeType==1){
243
var _3c=dojox.atom.io.model.util.getNodename(c[i]);
244
if(!_3c){
245
continue;
246
}
247
if(c[i].namespaceURI!=dojox.atom.io.model._Constants.ATOM_NS&&_3c!="#text"){
248
if(!this.extensions){
249
this.extensions=[];
250
}
251
var _3d=new dojox.atom.io.model.Node();
252
_3d.buildFromDom(c[i]);
253
this.extensions.push(_3d);
254
}
255
if(!this.accept(_3c.toLowerCase())){
256
continue;
257
}
258
var fn=dojox.atom.io.model._actions[_3c];
259
if(fn){
260
fn(this,c[i]);
261
}
262
}
263
}
264
this._saveAttributes(_3b);
265
if(this._postBuild){
266
this._postBuild();
267
}
268
},addNamespace:function(_3e,_3f){
269
if(_3e&&_3f){
270
this.name_spaces[_3f]=_3e;
271
}
272
},addAuthor:function(_40,_41,uri){
273
if(!this.authors){
274
this.authors=[];
275
}
276
this.authors.push(new dojox.atom.io.model.Person("author",_40,_41,uri));
277
},addContributor:function(_42,_43,uri){
278
if(!this.contributors){
279
this.contributors=[];
280
}
281
this.contributors.push(new dojox.atom.io.model.Person("contributor",_42,_43,uri));
282
},addLink:function(_44,rel,_45,_46,_47){
283
if(!this.links){
284
this.links=[];
285
}
286
this.links.push(new dojox.atom.io.model.Link(_44,rel,_45,_46,_47));
287
},removeLink:function(_48,rel){
288
if(!this.links||!dojo.isArray(this.links)){
289
return;
290
}
291
var _49=0;
292
for(var i=0;i<this.links.length;i++){
293
if((!_48||this.links[i].href===_48)&&(!rel||this.links[i].rel===rel)){
294
this.links.splice(i,1);
295
_49++;
296
}
297
}
298
return _49;
299
},removeBasicLinks:function(){
300
if(!this.links){
301
return;
302
}
303
var _4a=0;
304
for(var i=0;i<this.links.length;i++){
305
if(!this.links[i].rel){
306
this.links.splice(i,1);
307
_4a++;
308
i--;
309
}
310
}
311
return _4a;
312
},addCategory:function(_4b,_4c,_4d){
313
if(!this.categories){
314
this.categories=[];
315
}
316
this.categories.push(new dojox.atom.io.model.Category(_4b,_4c,_4d));
317
},getCategories:function(_4e){
318
if(!_4e){
319
return this.categories;
320
}
321
var arr=[];
322
for(var x in this.categories){
323
if(this.categories[x].scheme===_4e){
324
arr.push(this.categories[x]);
325
}
326
}
327
return arr;
328
},removeCategories:function(_4f,_50){
329
if(!this.categories){
330
return;
331
}
332
var _51=0;
333
for(var i=0;i<this.categories.length;i++){
334
if((!_4f||this.categories[i].scheme===_4f)&&(!_50||this.categories[i].term===_50)){
335
this.categories.splice(i,1);
336
_51++;
337
i--;
338
}
339
}
340
return _51;
341
},setTitle:function(str,_52){
342
if(!str){
343
return;
344
}
345
this.title=new dojox.atom.io.model.Content("title");
346
this.title.value=str;
347
if(_52){
348
this.title.type=_52;
349
}
350
},addExtension:function(_53,_54,_55,_56,_57){
351
if(!this.extensions){
352
this.extensions=[];
353
}
354
this.extensions.push(new dojox.atom.io.model.Node(_53,_54,_55,_56,_57||"ns"+this.extensions.length));
355
},getExtensions:function(_58,_59){
356
var arr=[];
357
if(!this.extensions){
358
return arr;
359
}
360
for(var x in this.extensions){
361
if((this.extensions[x].name_space===_58||this.extensions[x].shortNs===_58)&&(!_59||this.extensions[x].name===_59)){
362
arr.push(this.extensions[x]);
363
}
364
}
365
return arr;
366
},removeExtensions:function(_5a,_5b){
367
if(!this.extensions){
368
return;
369
}
370
for(var i=0;i<this.extensions.length;i++){
371
if((this.extensions[i].name_space==_5a||this.extensions[i].shortNs===_5a)&&this.extensions[i].name===_5b){
372
this.extensions.splice(i,1);
373
i--;
374
}
375
}
376
},destroy:function(){
377
this.links=null;
378
this.authors=null;
379
this.categories=null;
380
this.contributors=null;
381
this.icon=this.id=this.logo=this.xmlBase=this.rights=null;
382
this.subtitle=this.title=null;
383
this.updated=this.published=null;
384
this.issued=this.modified=null;
385
this.content=null;
386
this.extensions=null;
387
this.entries=null;
388
}});
389
dojo.declare("dojox.atom.io.model.Category",dojox.atom.io.model.Node,{constructor:function(_5c,_5d,_5e){
390
this.scheme=_5c;
391
this.term=_5d;
392
this.label=_5e;
393
this._objName="Category";
394
},_postBuild:function(){
395
},_getAttributeNames:function(){
396
return ["label","scheme","term"];
397
},toString:function(){
398
var s=[];
399
s.push("<category ");
400
if(this.label){
401
s.push(" label=\""+this.label+"\" ");
402
}
403
if(this.scheme){
404
s.push(" scheme=\""+this.scheme+"\" ");
405
}
406
if(this.term){
407
s.push(" term=\""+this.term+"\" ");
408
}
409
s.push("/>\n");
410
return s.join("");
411
},buildFromDom:function(_5f){
412
this._saveAttributes(_5f);
413
this.label=this.attributes.label;
414
this.scheme=this.attributes.scheme;
415
this.term=this.attributes.term;
416
if(this._postBuild){
417
this._postBuild();
418
}
419
}});
420
dojo.declare("dojox.atom.io.model.Content",dojox.atom.io.model.Node,{constructor:function(_60,_61,src,_62,_63){
421
this.tagName=_60;
422
this.value=_61;
423
this.src=src;
424
this.type=_62;
425
this.xmlLang=_63;
426
this.HTML="html";
427
this.TEXT="text";
428
this.XHTML="xhtml";
429
this.XML="xml";
430
this._useTextContent="true";
431
},_getAttributeNames:function(){
432
return ["type","src"];
433
},_postBuild:function(){
434
},buildFromDom:function(_64){
435
var _65=_64.getAttribute("type");
436
if(_65){
437
_65=_65.toLowerCase();
438
if(_65=="xml"||"text/xml"){
439
_65=this.XML;
440
}
441
}else{
442
_65="text";
443
}
444
if(_65===this.XML){
445
if(_64.firstChild){
446
var i;
447
this.value="";
448
for(i=0;i<_64.childNodes.length;i++){
449
var c=_64.childNodes[i];
450
if(c){
451
this.value+=dojox.xml.parser.innerXML(c);
452
}
453
}
454
}
455
}else{
456
if(_64.innerHTML){
457
this.value=_64.innerHTML;
458
}else{
459
this.value=dojox.xml.parser.textContent(_64);
460
}
461
}
462
this._saveAttributes(_64);
463
if(this.attributes){
464
this.type=this.attributes.type;
465
this.scheme=this.attributes.scheme;
466
this.term=this.attributes.term;
467
}
468
if(!this.type){
469
this.type="text";
470
}
471
var _66=this.type.toLowerCase();
472
if(_66==="html"||_66==="text/html"||_66==="xhtml"||_66==="text/xhtml"){
473
this.value=this.value?dojox.atom.io.model.util.unEscapeHtml(this.value):"";
474
}
475
if(this._postBuild){
476
this._postBuild();
477
}
478
},toString:function(){
479
var s=[];
480
s.push("<"+this.tagName+" ");
481
if(!this.type){
482
this.type="text";
483
}
484
if(this.type){
485
s.push(" type=\""+this.type+"\" ");
486
}
487
if(this.xmlLang){
488
s.push(" xml:lang=\""+this.xmlLang+"\" ");
489
}
490
if(this.xmlBase){
491
s.push(" xml:base=\""+this.xmlBase+"\" ");
492
}
493
if(this.type.toLowerCase()==this.HTML){
494
s.push(">"+dojox.atom.io.model.util.escapeHtml(this.value)+"</"+this.tagName+">\n");
495
}else{
496
s.push(">"+this.value+"</"+this.tagName+">\n");
497
}
498
var ret=s.join("");
499
return ret;
500
}});
501
dojo.declare("dojox.atom.io.model.Link",dojox.atom.io.model.Node,{constructor:function(_67,rel,_68,_69,_6a){
502
this.href=_67;
503
this.hrefLang=_68;
504
this.rel=rel;
505
this.title=_69;
506
this.type=_6a;
507
},_getAttributeNames:function(){
508
return ["href","jrefLang","rel","title","type"];
509
},_postBuild:function(){
510
},buildFromDom:function(_6b){
511
this._saveAttributes(_6b);
512
this.href=this.attributes.href;
513
this.hrefLang=this.attributes.hreflang;
514
this.rel=this.attributes.rel;
515
this.title=this.attributes.title;
516
this.type=this.attributes.type;
517
if(this._postBuild){
518
this._postBuild();
519
}
520
},toString:function(){
521
var s=[];
522
s.push("<link ");
523
if(this.href){
524
s.push(" href=\""+this.href+"\" ");
525
}
526
if(this.hrefLang){
527
s.push(" hrefLang=\""+this.hrefLang+"\" ");
528
}
529
if(this.rel){
530
s.push(" rel=\""+this.rel+"\" ");
531
}
532
if(this.title){
533
s.push(" title=\""+this.title+"\" ");
534
}
535
if(this.type){
536
s.push(" type = \""+this.type+"\" ");
537
}
538
s.push("/>\n");
539
return s.join("");
540
}});
541
dojo.declare("dojox.atom.io.model.Person",dojox.atom.io.model.Node,{constructor:function(_6c,_6d,_6e,uri){
542
this.author="author";
543
this.contributor="contributor";
544
if(!_6c){
545
_6c=this.author;
546
}
547
this.personType=_6c;
548
this.name=_6d||"";
549
this.email=_6e||"";
550
this.uri=uri||"";
551
this._objName="Person";
552
},_getAttributeNames:function(){
553
return null;
554
},_postBuild:function(){
555
},accept:function(tag){
556
return Boolean(this._accepts[tag]);
557
},buildFromDom:function(_6f){
558
var c=_6f.childNodes;
559
for(var i=0;i<c.length;i++){
560
var _70=dojox.atom.io.model.util.getNodename(c[i]);
561
if(!_70){
562
continue;
563
}
564
if(c[i].namespaceURI!=dojox.atom.io.model._Constants.ATOM_NS&&_70!="#text"){
565
if(!this.extensions){
566
this.extensions=[];
567
}
568
var _71=new dojox.atom.io.model.Node();
569
_71.buildFromDom(c[i]);
570
this.extensions.push(_71);
571
}
572
if(!this.accept(_70.toLowerCase())){
573
continue;
574
}
575
var fn=dojox.atom.io.model._actions[_70];
576
if(fn){
577
fn(this,c[i]);
578
}
579
}
580
this._saveAttributes(_6f);
581
if(this._postBuild){
582
this._postBuild();
583
}
584
},_accepts:{"name":true,"uri":true,"email":true},toString:function(){
585
var s=[];
586
s.push("<"+this.personType+">\n");
587
if(this.name){
588
s.push("\t<name>"+this.name+"</name>\n");
589
}
590
if(this.email){
591
s.push("\t<email>"+this.email+"</email>\n");
592
}
593
if(this.uri){
594
s.push("\t<uri>"+this.uri+"</uri>\n");
595
}
596
s.push("</"+this.personType+">\n");
597
return s.join("");
598
}});
599
dojo.declare("dojox.atom.io.model.Generator",dojox.atom.io.model.Node,{constructor:function(uri,_72,_73){
600
this.uri=uri;
601
this.version=_72;
602
this.value=_73;
603
},_postBuild:function(){
604
},buildFromDom:function(_74){
605
this.value=dojox.xml.parser.textContent(_74);
606
this._saveAttributes(_74);
607
this.uri=this.attributes.uri;
608
this.version=this.attributes.version;
609
if(this._postBuild){
610
this._postBuild();
611
}
612
},toString:function(){
613
var s=[];
614
s.push("<generator ");
615
if(this.uri){
616
s.push(" uri=\""+this.uri+"\" ");
617
}
618
if(this.version){
619
s.push(" version=\""+this.version+"\" ");
620
}
621
s.push(">"+this.value+"</generator>\n");
622
var ret=s.join("");
623
return ret;
624
}});
625
dojo.declare("dojox.atom.io.model.Entry",dojox.atom.io.model.AtomItem,{constructor:function(id){
626
this.id=id;
627
this._objName="Entry";
628
this.feedUrl=null;
629
},_getAttributeNames:function(){
630
return null;
631
},_accepts:{"author":true,"content":true,"category":true,"contributor":true,"created":true,"id":true,"link":true,"published":true,"rights":true,"summary":true,"title":true,"updated":true,"xmlbase":true,"issued":true,"modified":true},toString:function(_75){
632
var s=[];
633
var i;
634
if(_75){
635
s.push("<?xml version='1.0' encoding='UTF-8'?>");
636
s.push("<entry xmlns='"+dojox.atom.io.model._Constants.ATOM_URI+"'");
637
}else{
638
s.push("<entry");
639
}
640
if(this.xmlBase){
641
s.push(" xml:base=\""+this.xmlBase+"\" ");
642
}
643
for(i in this.name_spaces){
644
s.push(" xmlns:"+i+"=\""+this.name_spaces[i]+"\"");
645
}
646
s.push(">\n");
647
s.push("<id>"+(this.id?this.id:"")+"</id>\n");
648
if(this.issued&&!this.published){
649
this.published=this.issued;
650
}
651
if(this.published){
652
s.push("<published>"+dojo.date.stamp.toISOString(this.published)+"</published>\n");
653
}
654
if(this.created){
655
s.push("<created>"+dojo.date.stamp.toISOString(this.created)+"</created>\n");
656
}
657
if(this.issued){
658
s.push("<issued>"+dojo.date.stamp.toISOString(this.issued)+"</issued>\n");
659
}
660
if(this.modified){
661
s.push("<modified>"+dojo.date.stamp.toISOString(this.modified)+"</modified>\n");
662
}
663
if(this.modified&&!this.updated){
664
this.updated=this.modified;
665
}
666
if(this.updated){
667
s.push("<updated>"+dojo.date.stamp.toISOString(this.updated)+"</updated>\n");
668
}
669
if(this.rights){
670
s.push("<rights>"+this.rights+"</rights>\n");
671
}
672
if(this.title){
673
s.push(this.title.toString());
674
}
675
if(this.summary){
676
s.push(this.summary.toString());
677
}
678
var _76=[this.authors,this.categories,this.links,this.contributors,this.extensions];
679
for(var x in _76){
680
if(_76[x]){
681
for(var y in _76[x]){
682
s.push(_76[x][y]);
683
}
684
}
685
}
686
if(this.content){
687
s.push(this.content.toString());
688
}
689
s.push("</entry>\n");
690
return s.join("");
691
},getEditHref:function(){
692
if(this.links===null||this.links.length===0){
693
return null;
694
}
695
for(var x in this.links){
696
if(this.links[x].rel&&this.links[x].rel=="edit"){
697
return this.links[x].href;
698
}
699
}
700
return null;
701
},setEditHref:function(url){
702
if(this.links===null){
703
this.links=[];
704
}
705
for(var x in this.links){
706
if(this.links[x].rel&&this.links[x].rel=="edit"){
707
this.links[x].href=url;
708
return;
709
}
710
}
711
this.addLink(url,"edit");
712
}});
713
dojo.declare("dojox.atom.io.model.Feed",dojox.atom.io.model.AtomItem,{_accepts:{"author":true,"content":true,"category":true,"contributor":true,"created":true,"id":true,"link":true,"published":true,"rights":true,"summary":true,"title":true,"updated":true,"xmlbase":true,"entry":true,"logo":true,"issued":true,"modified":true,"icon":true,"subtitle":true},addEntry:function(_77){
714
if(!_77.id){
715
throw new Error("The entry object must be assigned an ID attribute.");
716
}
717
if(!this.entries){
718
this.entries=[];
719
}
720
_77.feedUrl=this.getSelfHref();
721
this.entries.push(_77);
722
},getFirstEntry:function(){
723
if(!this.entries||this.entries.length===0){
724
return null;
725
}
726
return this.entries[0];
727
},getEntry:function(_78){
728
if(!this.entries){
729
return null;
730
}
731
for(var x in this.entries){
732
if(this.entries[x].id==_78){
733
return this.entries[x];
734
}
735
}
736
return null;
737
},removeEntry:function(_79){
738
if(!this.entries){
739
return;
740
}
741
var _7a=0;
742
for(var i=0;i<this.entries.length;i++){
743
if(this.entries[i]===_79){
744
this.entries.splice(i,1);
745
_7a++;
746
}
747
}
748
return _7a;
749
},setEntries:function(_7b){
750
for(var x in _7b){
751
this.addEntry(_7b[x]);
752
}
753
},toString:function(){
754
var s=[];
755
var i;
756
s.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
757
s.push("<feed xmlns=\""+dojox.atom.io.model._Constants.ATOM_URI+"\"");
758
if(this.xmlBase){
759
s.push(" xml:base=\""+this.xmlBase+"\"");
760
}
761
for(i in this.name_spaces){
762
s.push(" xmlns:"+i+"=\""+this.name_spaces[i]+"\"");
763
}
764
s.push(">\n");
765
s.push("<id>"+(this.id?this.id:"")+"</id>\n");
766
if(this.title){
767
s.push(this.title);
768
}
769
if(this.copyright&&!this.rights){
770
this.rights=this.copyright;
771
}
772
if(this.rights){
773
s.push("<rights>"+this.rights+"</rights>\n");
774
}
775
if(this.issued){
776
s.push("<issued>"+dojo.date.stamp.toISOString(this.issued)+"</issued>\n");
777
}
778
if(this.modified){
779
s.push("<modified>"+dojo.date.stamp.toISOString(this.modified)+"</modified>\n");
780
}
781
if(this.modified&&!this.updated){
782
this.updated=this.modified;
783
}
784
if(this.updated){
785
s.push("<updated>"+dojo.date.stamp.toISOString(this.updated)+"</updated>\n");
786
}
787
if(this.published){
788
s.push("<published>"+dojo.date.stamp.toISOString(this.published)+"</published>\n");
789
}
790
if(this.icon){
791
s.push("<icon>"+this.icon+"</icon>\n");
792
}
793
if(this.language){
794
s.push("<language>"+this.language+"</language>\n");
795
}
796
if(this.logo){
797
s.push("<logo>"+this.logo+"</logo>\n");
798
}
799
if(this.subtitle){
800
s.push(this.subtitle.toString());
801
}
802
if(this.tagline){
803
s.push(this.tagline.toString());
804
}
805
var _7c=[this.alternateLinks,this.authors,this.categories,this.contributors,this.otherLinks,this.extensions,this.entries];
806
for(i in _7c){
807
if(_7c[i]){
808
for(var x in _7c[i]){
809
s.push(_7c[i][x]);
810
}
811
}
812
}
813
s.push("</feed>");
814
return s.join("");
815
},createEntry:function(){
816
var _7d=new dojox.atom.io.model.Entry();
817
_7d.feedUrl=this.getSelfHref();
818
return _7d;
819
},getSelfHref:function(){
820
if(this.links===null||this.links.length===0){
821
return null;
822
}
823
for(var x in this.links){
824
if(this.links[x].rel&&this.links[x].rel=="self"){
825
return this.links[x].href;
826
}
827
}
828
return null;
829
}});
830
dojo.declare("dojox.atom.io.model.Service",dojox.atom.io.model.AtomItem,{constructor:function(_7e){
831
this.href=_7e;
832
},buildFromDom:function(_7f){
833
var i;
834
this.workspaces=[];
835
if(_7f.tagName!="service"){
836
return;
837
}
838
if(_7f.namespaceURI!=dojox.atom.io.model._Constants.PURL_NS&&_7f.namespaceURI!=dojox.atom.io.model._Constants.APP_NS){
839
return;
840
}
841
var ns=_7f.namespaceURI;
842
this.name_space=_7f.namespaceURI;
843
var _80;
844
if(typeof (_7f.getElementsByTagNameNS)!="undefined"){
845
_80=_7f.getElementsByTagNameNS(ns,"workspace");
846
}else{
847
_80=[];
848
var _81=_7f.getElementsByTagName("workspace");
849
for(i=0;i<_81.length;i++){
850
if(_81[i].namespaceURI==ns){
851
_80.push(_81[i]);
852
}
853
}
854
}
855
if(_80&&_80.length>0){
856
var _82=0;
857
var _83;
858
for(i=0;i<_80.length;i++){
859
_83=(typeof (_80.item)==="undefined"?_80[i]:_80.item(i));
860
var _84=new dojox.atom.io.model.Workspace();
861
_84.buildFromDom(_83);
862
this.workspaces[_82++]=_84;
863
}
864
}
865
},getCollection:function(url){
866
for(var i=0;i<this.workspaces.length;i++){
867
var _85=this.workspaces[i].collections;
868
for(var j=0;j<_85.length;j++){
869
if(_85[j].href==url){
870
return _85;
871
}
872
}
873
}
874
return null;
875
}});
876
dojo.declare("dojox.atom.io.model.Workspace",dojox.atom.io.model.AtomItem,{constructor:function(_86){
877
this.title=_86;
878
this.collections=[];
879
},buildFromDom:function(_87){
880
var _88=dojox.atom.io.model.util.getNodename(_87);
881
if(_88!="workspace"){
882
return;
883
}
884
var c=_87.childNodes;
885
var len=0;
886
for(var i=0;i<c.length;i++){
887
var _89=c[i];
888
if(_89.nodeType===1){
889
_88=dojox.atom.io.model.util.getNodename(_89);
890
if(_89.namespaceURI==dojox.atom.io.model._Constants.PURL_NS||_89.namespaceURI==dojox.atom.io.model._Constants.APP_NS){
891
if(_88==="collection"){
892
var _8a=new dojox.atom.io.model.Collection();
893
_8a.buildFromDom(_89);
894
this.collections[len++]=_8a;
895
}
896
}else{
897
if(_89.namespaceURI===dojox.atom.io.model._Constants.ATOM_NS){
898
if(_88==="title"){
899
this.title=dojox.xml.parser.textContent(_89);
900
}
901
}
902
}
903
}
904
}
905
}});
906
dojo.declare("dojox.atom.io.model.Collection",dojox.atom.io.model.AtomItem,{constructor:function(_8b,_8c){
907
this.href=_8b;
908
this.title=_8c;
909
this.attributes=[];
910
this.features=[];
911
this.children=[];
912
this.memberType=null;
913
this.id=null;
914
},buildFromDom:function(_8d){
915
this.href=_8d.getAttribute("href");
916
var c=_8d.childNodes;
917
for(var i=0;i<c.length;i++){
918
var _8e=c[i];
919
if(_8e.nodeType===1){
920
var _8f=dojox.atom.io.model.util.getNodename(_8e);
921
if(_8e.namespaceURI==dojox.atom.io.model._Constants.PURL_NS||_8e.namespaceURI==dojox.atom.io.model._Constants.APP_NS){
922
if(_8f==="member-type"){
923
this.memberType=dojox.xml.parser.textContent(_8e);
924
}else{
925
if(_8f=="feature"){
926
if(_8e.getAttribute("id")){
927
this.features.push(_8e.getAttribute("id"));
928
}
929
}else{
930
var _90=new dojox.atom.io.model.Node();
931
_90.buildFromDom(_8e);
932
this.children.push(_90);
933
}
934
}
935
}else{
936
if(_8e.namespaceURI===dojox.atom.io.model._Constants.ATOM_NS){
937
if(_8f==="id"){
938
this.id=dojox.xml.parser.textContent(_8e);
939
}else{
940
if(_8f==="title"){
941
this.title=dojox.xml.parser.textContent(_8e);
942
}
943
}
944
}
945
}
946
}
947
}
948
}});
949
}