model.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /*
  2. Copyright (c) 2004-2012, 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. if(!dojo._hasResource["dojox.atom.io.model"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.atom.io.model"] = true;
  8. dojo.provide("dojox.atom.io.model");
  9. dojo.require("dojox.xml.parser");
  10. dojo.require("dojo.string");
  11. dojo.require("dojo.date.stamp");
  12. dojox.atom.io.model._Constants = {
  13. // summary:
  14. // Container for general constants.
  15. // description:
  16. // Container for general constants.
  17. "ATOM_URI": "http://www.w3.org/2005/Atom",
  18. "ATOM_NS": "http://www.w3.org/2005/Atom",
  19. "PURL_NS": "http://purl.org/atom/app#",
  20. "APP_NS": "http://www.w3.org/2007/app"
  21. };
  22. dojox.atom.io.model._actions = {
  23. // summary:
  24. // Container for tag handling functions.
  25. // description:
  26. // Container for tag handling functions. Each child of this container is
  27. // a handler function for the given type of node. Each accepts two parameters:
  28. // obj: Object.
  29. // The object to insert data into.
  30. // node: DOM Node.
  31. // The dom node containing the data
  32. "link": function(obj,node){
  33. if(obj.links === null){obj.links = [];}
  34. var link = new dojox.atom.io.model.Link();
  35. link.buildFromDom(node);
  36. obj.links.push(link);
  37. },
  38. "author": function(obj,node){
  39. if(obj.authors === null){obj.authors = [];}
  40. var person = new dojox.atom.io.model.Person("author");
  41. person.buildFromDom(node);
  42. obj.authors.push(person);
  43. },
  44. "contributor": function(obj,node){
  45. if(obj.contributors === null){obj.contributors = [];}
  46. var person = new dojox.atom.io.model.Person("contributor");
  47. person.buildFromDom(node);
  48. obj.contributors.push(person);
  49. },
  50. "category": function(obj,node){
  51. if(obj.categories === null){obj.categories = [];}
  52. var cat = new dojox.atom.io.model.Category();
  53. cat.buildFromDom(node);
  54. obj.categories.push(cat);
  55. },
  56. "icon": function(obj,node){
  57. obj.icon = dojox.xml.parser.textContent(node);
  58. },
  59. "id": function(obj,node){
  60. obj.id = dojox.xml.parser.textContent(node);
  61. },
  62. "rights": function(obj,node){
  63. obj.rights = dojox.xml.parser.textContent(node);
  64. },
  65. "subtitle": function(obj,node){
  66. var cnt = new dojox.atom.io.model.Content("subtitle");
  67. cnt.buildFromDom(node);
  68. obj.subtitle = cnt;
  69. },
  70. "title": function(obj,node){
  71. var cnt = new dojox.atom.io.model.Content("title");
  72. cnt.buildFromDom(node);
  73. obj.title = cnt;
  74. },
  75. "updated": function(obj,node){
  76. obj.updated = dojox.atom.io.model.util.createDate(node);
  77. },
  78. // Google news
  79. "issued": function(obj,node){
  80. obj.issued = dojox.atom.io.model.util.createDate(node);
  81. },
  82. // Google news
  83. "modified": function(obj,node){
  84. obj.modified = dojox.atom.io.model.util.createDate(node);
  85. },
  86. "published": function(obj,node){
  87. obj.published = dojox.atom.io.model.util.createDate(node);
  88. },
  89. "entry": function(obj,node){
  90. if(obj.entries === null){obj.entries = [];}
  91. //The object passed in should be a Feed object, since only feeds can contain Entries
  92. var entry = obj.createEntry ? obj.createEntry() : new dojox.atom.io.model.Entry();
  93. entry.buildFromDom(node);
  94. obj.entries.push(entry);
  95. },
  96. "content": function(obj, node){
  97. var cnt = new dojox.atom.io.model.Content("content");
  98. cnt.buildFromDom(node);
  99. obj.content = cnt;
  100. },
  101. "summary": function(obj, node){
  102. var summary = new dojox.atom.io.model.Content("summary");
  103. summary.buildFromDom(node);
  104. obj.summary = summary;
  105. },
  106. "name": function(obj,node){
  107. obj.name = dojox.xml.parser.textContent(node);
  108. },
  109. "email" : function(obj,node){
  110. obj.email = dojox.xml.parser.textContent(node);
  111. },
  112. "uri" : function(obj,node){
  113. obj.uri = dojox.xml.parser.textContent(node);
  114. },
  115. "generator" : function(obj,node){
  116. obj.generator = new dojox.atom.io.model.Generator();
  117. obj.generator.buildFromDom(node);
  118. }
  119. };
  120. dojox.atom.io.model.util = {
  121. createDate: function(/*DOM node*/node){
  122. // summary:
  123. // Utility function to create a date from a DOM node's text content.
  124. // description:
  125. // Utility function to create a date from a DOM node's text content.
  126. //
  127. // node:
  128. // The DOM node to inspect.
  129. // returns:
  130. // Date object from a DOM Node containing a ISO-8610 string.
  131. var textContent = dojox.xml.parser.textContent(node);
  132. if(textContent){
  133. return dojo.date.stamp.fromISOString(dojo.trim(textContent));
  134. }
  135. return null;
  136. },
  137. escapeHtml: function(/*String*/str){
  138. // summary:
  139. // Utility function to escape XML special characters in an HTML string.
  140. // description:
  141. // Utility function to escape XML special characters in an HTML string.
  142. //
  143. // str:
  144. // The string to escape
  145. // returns:
  146. // HTML String with special characters (<,>,&, ", etc,) escaped.
  147. return str.replace(/&/gm, "&amp;").replace(/</gm, "&lt;").replace(/>/gm, "&gt;").replace(/"/gm, "&quot;")
  148. .replace(/'/gm, "&#39;"); // String
  149. },
  150. unEscapeHtml: function(/*String*/str){
  151. // summary:
  152. // Utility function to un-escape XML special characters in an HTML string.
  153. // description:
  154. // Utility function to un-escape XML special characters in an HTML string.
  155. //
  156. // str:
  157. // The string to un-escape.
  158. // returns:
  159. // HTML String converted back to the normal text (unescaped) characters (<,>,&, ", etc,).
  160. return str.replace(/&lt;/gm, "<").replace(/&gt;/gm, ">").replace(/&quot;/gm, "\"")
  161. .replace(/&#39;/gm, "'").replace(/&amp;/gm, "&"); // String
  162. },
  163. getNodename: function(/*DOM node*/node){
  164. // summary:
  165. // Utility function to get a node name and deal with IE's bad handling of namespaces
  166. // on tag names.
  167. // description:
  168. // Utility function to get a node name and deal with IE's bad handling of namespaces
  169. // on tag names.
  170. //
  171. // node:
  172. // The DOM node whose name to retrieve.
  173. // returns:
  174. // String
  175. // The name without namespace prefixes.
  176. var name = null;
  177. if(node !== null){
  178. name = node.localName ? node.localName: node.nodeName;
  179. if(name !== null){
  180. var nsSep = name.indexOf(":");
  181. if(nsSep !== -1){
  182. name = name.substring((nsSep + 1), name.length);
  183. }
  184. }
  185. }
  186. return name;
  187. }
  188. };
  189. dojo.declare('dojox.atom.io.model.Node', null, {
  190. constructor: function(name_space,name, attributes,content, shortNs){
  191. this.name_space = name_space;
  192. this.name = name;
  193. this.attributes = [];
  194. if(attributes){
  195. this.attributes = attributes;
  196. }
  197. this.content = [];
  198. this.rawNodes = [];
  199. this.textContent = null;
  200. if(content){
  201. this.content.push(content);
  202. }
  203. this.shortNs = shortNs;
  204. this._objName = "Node";//for debugging purposes
  205. },
  206. buildFromDom: function(node){
  207. this._saveAttributes(node);
  208. this.name_space = node.namespaceURI;
  209. this.shortNs = node.prefix;
  210. this.name = dojox.atom.io.model.util.getNodename(node);
  211. for(var x=0; x < node.childNodes.length; x++){
  212. var c = node.childNodes[x];
  213. if(dojox.atom.io.model.util.getNodename(c) != "#text" ){
  214. this.rawNodes.push(c);
  215. var n = new dojox.atom.io.model.Node();
  216. n.buildFromDom(c, true);
  217. this.content.push(n);
  218. }else{
  219. this.content.push(c.nodeValue);
  220. }
  221. }
  222. this.textContent = dojox.xml.parser.textContent(node);
  223. },
  224. _saveAttributes: function(node){
  225. if(!this.attributes){this.attributes = [];}
  226. // Work around lack of hasAttributes() in IE
  227. var hasAttributes = function(node){
  228. var attrs = node.attributes;
  229. if(attrs === null){return false;}
  230. return (attrs.length !== 0);
  231. };
  232. if(hasAttributes(node) && this._getAttributeNames){
  233. var names = this._getAttributeNames(node);
  234. if(names && names.length > 0){
  235. for(var x in names){
  236. var attrib = node.getAttribute(names[x]);
  237. if(attrib){this.attributes[names[x]] = attrib;}
  238. }
  239. }
  240. }
  241. },
  242. addAttribute: function(name, value){
  243. this.attributes[name]=value;
  244. },
  245. getAttribute: function(name){
  246. return this.attributes[name];
  247. },
  248. //if child objects want their attributes parsed, they should override
  249. //to return an array of attrib names
  250. _getAttributeNames: function(node){
  251. var names = [];
  252. for(var i =0; i<node.attributes.length; i++){
  253. names.push(node.attributes[i].nodeName);
  254. }
  255. return names;
  256. },
  257. toString: function(){
  258. var xml = [];
  259. var x;
  260. var name = (this.shortNs?this.shortNs+":":'')+this.name;
  261. var cdata = (this.name == "#cdata-section");
  262. if(cdata){
  263. xml.push("<![CDATA[");
  264. xml.push(this.textContent);
  265. xml.push("]]>");
  266. }else{
  267. xml.push("<");
  268. xml.push(name);
  269. if(this.name_space){
  270. xml.push(" xmlns='" + this.name_space + "'");
  271. }
  272. if(this.attributes){
  273. for(x in this.attributes){
  274. xml.push(" " + x + "='" + this.attributes[x] + "'");
  275. }
  276. }
  277. if(this.content){
  278. xml.push(">");
  279. for(x in this.content){
  280. xml.push(this.content[x]);
  281. }
  282. xml.push("</" + name + ">\n");
  283. }else{
  284. xml.push("/>\n");
  285. }
  286. }
  287. return xml.join('');
  288. },
  289. addContent: function(content){
  290. this.content.push(content);
  291. }
  292. });
  293. //Types are as follows: links: array of Link, authors: array of Person, categories: array of Category
  294. //contributors: array of Person, ico
  295. dojo.declare("dojox.atom.io.model.AtomItem",dojox.atom.io.model.Node,{
  296. constructor: function(args){
  297. this.ATOM_URI = dojox.atom.io.model._Constants.ATOM_URI;
  298. this.links = null; //Array of Link
  299. this.authors = null; //Array of Person
  300. this.categories = null; //Array of Category
  301. this.contributors = null; //Array of Person
  302. this.icon = this.id = this.logo = this.xmlBase = this.rights = null; //String
  303. this.subtitle = this.title = null; //Content
  304. this.updated = this.published = null; //Date
  305. // Google news
  306. this.issued = this.modified = null; //Date
  307. this.content = null; //Content
  308. this.extensions = null; //Array of Node, non atom based
  309. this.entries = null; //Array of Entry
  310. this.name_spaces = {};
  311. this._objName = "AtomItem"; //for debugging purposes
  312. },
  313. // summary: Class container for generic Atom items.
  314. // description: Class container for generic Atom items.
  315. _getAttributeNames: function(){return null;},
  316. _accepts: {},
  317. accept: function(tag){return Boolean(this._accepts[tag]);},
  318. _postBuild: function(){},//child objects can override this if they want to be called after a Dom build
  319. buildFromDom: function(node){
  320. var i, c, n;
  321. for(i=0; i<node.attributes.length; i++){
  322. c = node.attributes.item(i);
  323. n = dojox.atom.io.model.util.getNodename(c);
  324. if(c.prefix == "xmlns" && c.prefix != n){
  325. this.addNamespace(c.nodeValue, n);
  326. }
  327. }
  328. c = node.childNodes;
  329. for(i = 0; i< c.length; i++){
  330. if(c[i].nodeType == 1) {
  331. var name = dojox.atom.io.model.util.getNodename(c[i]);
  332. if(!name){continue;}
  333. if(c[i].namespaceURI != dojox.atom.io.model._Constants.ATOM_NS && name != "#text"){
  334. if(!this.extensions){this.extensions = [];}
  335. var extensionNode = new dojox.atom.io.model.Node();
  336. extensionNode.buildFromDom(c[i]);
  337. this.extensions.push(extensionNode);
  338. }
  339. if(!this.accept(name.toLowerCase())){
  340. continue;
  341. }
  342. var fn = dojox.atom.io.model._actions[name];
  343. if(fn) {
  344. fn(this,c[i]);
  345. }
  346. }
  347. }
  348. this._saveAttributes(node);
  349. if(this._postBuild){this._postBuild();}
  350. },
  351. addNamespace: function(fullName, shortName){
  352. if(fullName && shortName){
  353. this.name_spaces[shortName] = fullName;
  354. }
  355. },
  356. addAuthor: function(/*String*/name, /*String*/email, /*String*/uri){
  357. // summary:
  358. // Function to add in an author to the list of authors.
  359. // description:
  360. // Function to add in an author to the list of authors.
  361. //
  362. // name:
  363. // The author's name.
  364. // email:
  365. // The author's e-mail address.
  366. // uri:
  367. // A URI associated with the author.
  368. if(!this.authors){this.authors = [];}
  369. this.authors.push(new dojox.atom.io.model.Person("author",name,email,uri));
  370. },
  371. addContributor: function(/*String*/name, /*String*/email, /*String*/uri){
  372. // summary:
  373. // Function to add in an author to the list of authors.
  374. // description:
  375. // Function to add in an author to the list of authors.
  376. //
  377. // name:
  378. // The author's name.
  379. // email:
  380. // The author's e-mail address.
  381. // uri:
  382. // A URI associated with the author.
  383. if(!this.contributors){this.contributors = [];}
  384. this.contributors.push(new dojox.atom.io.model.Person("contributor",name,email,uri));
  385. },
  386. addLink: function(/*String*/href,/*String*/rel,/*String*/hrefLang,/*String*/title,/*String*/type){
  387. // summary:
  388. // Function to add in a link to the list of links.
  389. // description:
  390. // Function to add in a link to the list of links.
  391. //
  392. // href:
  393. // The href.
  394. // rel:
  395. // String
  396. // hrefLang:
  397. // String
  398. // title:
  399. // A title to associate with the link.
  400. // type:
  401. // The type of link is is.
  402. if(!this.links){this.links=[];}
  403. this.links.push(new dojox.atom.io.model.Link(href,rel,hrefLang,title,type));
  404. },
  405. removeLink: function(/*String*/href, /*String*/rel){
  406. // summary:
  407. // Function to remove a link from the list of links.
  408. // description:
  409. // Function to remove a link from the list of links.
  410. //
  411. // href:
  412. // The href.
  413. // rel:
  414. // String
  415. if(!this.links || !dojo.isArray(this.links)){return;}
  416. var count = 0;
  417. for(var i = 0; i < this.links.length; i++){
  418. if((!href || this.links[i].href === href) && (!rel || this.links[i].rel === rel)){
  419. this.links.splice(i,1); count++;
  420. }
  421. }
  422. return count;
  423. },
  424. removeBasicLinks: function(){
  425. // summary:
  426. // Function to remove all basic links from the list of links.
  427. // description:
  428. // Function to remove all basic link from the list of links.
  429. if(!this.links){return;}
  430. var count = 0;
  431. for(var i = 0; i < this.links.length; i++){
  432. if(!this.links[i].rel){this.links.splice(i,1); count++; i--;}
  433. }
  434. return count;
  435. },
  436. addCategory: function(/*String*/scheme, /*String*/term, /*String*/label){
  437. // summary:
  438. // Function to add in a category to the list of categories.
  439. // description:
  440. // Function to add in a category to the list of categories.
  441. //
  442. // scheme:
  443. // String
  444. // term:
  445. // String
  446. // label:
  447. // String
  448. if(!this.categories){this.categories = [];}
  449. this.categories.push(new dojox.atom.io.model.Category(scheme,term,label));
  450. },
  451. getCategories: function(/*String*/scheme){
  452. // summary:
  453. // Function to get all categories that match a particular scheme.
  454. // description:
  455. // Function to get all categories that match a particular scheme.
  456. //
  457. // scheme:
  458. // String
  459. // The scheme to filter on.
  460. if(!scheme){return this.categories;}
  461. //If categories belonging to a particular scheme are required, then create a new array containing these
  462. var arr = [];
  463. for(var x in this.categories){
  464. if(this.categories[x].scheme === scheme){arr.push(this.categories[x]);}
  465. }
  466. return arr;
  467. },
  468. removeCategories: function(/*String*/scheme, /*String*/term){
  469. // summary:
  470. // Function to remove all categories that match a particular scheme and term.
  471. // description:
  472. // Function to remove all categories that match a particular scheme and term.
  473. //
  474. // scheme:
  475. // The scheme to filter on.
  476. // term:
  477. // The term to filter on.
  478. if(!this.categories){return;}
  479. var count = 0;
  480. for(var i=0; i<this.categories.length; i++){
  481. if((!scheme || this.categories[i].scheme === scheme) && (!term || this.categories[i].term === term)){
  482. this.categories.splice(i, 1); count++; i--;
  483. }
  484. }
  485. return count;
  486. },
  487. setTitle: function(/*String*/str, /*String*/type){
  488. // summary:
  489. // Function to set the title of the item.
  490. // description:
  491. // Function to set the title of the item.
  492. //
  493. // str:
  494. // The title to set.
  495. // type:
  496. // The type of title format, text, xml, xhtml, etc.
  497. if(!str){return;}
  498. this.title = new dojox.atom.io.model.Content("title");
  499. this.title.value = str;
  500. if(type){this.title.type = type;}
  501. },
  502. addExtension: function(/*String*/name_space,/*String*/name, /*Array*/attributes, /*String*/content, /*String*/shortNS){
  503. // summary:
  504. // Function to add in an extension namespace into the item.
  505. // description:
  506. // Function to add in an extension namespace into the item.
  507. //
  508. // name_space:
  509. // The namespace of the extension.
  510. // name:
  511. // The name of the extension
  512. // attributes:
  513. // The attributes associated with the extension.
  514. // content:
  515. // The content of the extension.
  516. if(!this.extensions){this.extensions=[];}
  517. this.extensions.push(new dojox.atom.io.model.Node(name_space,name,attributes,content, shortNS || "ns"+this.extensions.length));
  518. },
  519. getExtensions: function(/*String*/name_space, /*String*/name){
  520. // summary:
  521. // Function to get extensions that match a namespace and name.
  522. // description:
  523. // Function to get extensions that match a namespace and name.
  524. //
  525. // name_space:
  526. // The namespace of the extension.
  527. // name:
  528. // The name of the extension
  529. var arr = [];
  530. if(!this.extensions){return arr;}
  531. for(var x in this.extensions){
  532. if((this.extensions[x].name_space === name_space || this.extensions[x].shortNs === name_space) && (!name || this.extensions[x].name === name)){
  533. arr.push(this.extensions[x]);
  534. }
  535. }
  536. return arr;
  537. },
  538. removeExtensions: function(/*String*/name_space, /*String*/name){
  539. // summary:
  540. // Function to remove extensions that match a namespace and name.
  541. // description:
  542. // Function to remove extensions that match a namespace and name.
  543. //
  544. // name_space:
  545. // The namespace of the extension.
  546. // name:
  547. // The name of the extension
  548. if(!this.extensions){return;}
  549. for(var i=0; i< this.extensions.length; i++){
  550. if((this.extensions[i].name_space == name_space || this.extensions[i].shortNs === name_space) && this.extensions[i].name === name){
  551. this.extensions.splice(i,1);
  552. i--;
  553. }
  554. }
  555. },
  556. destroy: function() {
  557. this.links = null;
  558. this.authors = null;
  559. this.categories = null;
  560. this.contributors = null;
  561. this.icon = this.id = this.logo = this.xmlBase = this.rights = null;
  562. this.subtitle = this.title = null;
  563. this.updated = this.published = null;
  564. // Google news
  565. this.issued = this.modified = null;
  566. this.content = null;
  567. this.extensions = null;
  568. this.entries = null;
  569. }
  570. });
  571. dojo.declare("dojox.atom.io.model.Category",dojox.atom.io.model.Node,{
  572. // summary:
  573. // Class container for 'Category' types.
  574. // description:
  575. // Class container for 'Category' types.
  576. constructor: function(/*String*/scheme, /*String*/term, /*String*/label){
  577. this.scheme = scheme; this.term = term; this.label = label;
  578. this._objName = "Category";//for debugging
  579. },
  580. _postBuild: function(){},
  581. _getAttributeNames: function(){
  582. return ["label","scheme","term"];
  583. },
  584. toString: function(){
  585. // summary:
  586. // Function to construct string form of the category tag, which is an XML structure.
  587. // description:
  588. // Function to construct string form of the category tag, which is an XML structure.
  589. var s = [];
  590. s.push('<category ');
  591. if(this.label){s.push(' label="'+this.label+'" ');}
  592. if(this.scheme){s.push(' scheme="'+this.scheme+'" ');}
  593. if(this.term){s.push(' term="'+this.term+'" ');}
  594. s.push('/>\n');
  595. return s.join('');
  596. },
  597. buildFromDom: function(/*DOM node*/node){
  598. // summary:
  599. // Function to do construction of the Category data from the DOM node containing it.
  600. // description:
  601. // Function to do construction of the Category data from the DOM node containing it.
  602. //
  603. // node:
  604. // The DOM node to process for content.
  605. this._saveAttributes(node);//just get the attributes from the node
  606. this.label = this.attributes.label;
  607. this.scheme = this.attributes.scheme;
  608. this.term = this.attributes.term;
  609. if(this._postBuild){this._postBuild();}
  610. }
  611. });
  612. dojo.declare("dojox.atom.io.model.Content",dojox.atom.io.model.Node,{
  613. // summary:
  614. // Class container for 'Content' types. Such as summary, content, username, and so on types of data.
  615. // description:
  616. // Class container for 'Content' types. Such as summary, content, username, and so on types of data.
  617. constructor: function(tagName, value, src, type,xmlLang){
  618. this.tagName = tagName; this.value = value; this.src = src; this.type=type; this.xmlLang = xmlLang;
  619. this.HTML = "html"; this.TEXT = "text"; this.XHTML = "xhtml"; this.XML="xml";
  620. this._useTextContent = "true";
  621. },
  622. _getAttributeNames: function(){return ["type","src"];},
  623. _postBuild: function(){},
  624. buildFromDom: function(/*DOM node*/node){
  625. // summary:
  626. // Function to do construction of the Content data from the DOM node containing it.
  627. // description:
  628. // Function to do construction of the Content data from the DOM node containing it.
  629. //
  630. // node:
  631. // The DOM node to process for content.
  632. //Handle checking for XML content as the content type
  633. var type = node.getAttribute("type");
  634. if(type){
  635. type = type.toLowerCase();
  636. if(type == "xml" || "text/xml"){
  637. type = this.XML;
  638. }
  639. }else{
  640. type="text";
  641. }
  642. if(type === this.XML){
  643. if(node.firstChild){
  644. var i;
  645. this.value = "";
  646. for(i = 0; i < node.childNodes.length; i++){
  647. var c = node.childNodes[i];
  648. if(c){
  649. this.value += dojox.xml.parser.innerXML(c);
  650. }
  651. }
  652. }
  653. } else if(node.innerHTML){
  654. this.value = node.innerHTML;
  655. }else{
  656. this.value = dojox.xml.parser.textContent(node);
  657. }
  658. this._saveAttributes(node);
  659. if(this.attributes){
  660. this.type = this.attributes.type;
  661. this.scheme = this.attributes.scheme;
  662. this.term = this.attributes.term;
  663. }
  664. if(!this.type){this.type = "text";}
  665. //We need to unescape the HTML content here so that it can be displayed correctly when the value is fetched.
  666. var lowerType = this.type.toLowerCase();
  667. if(lowerType === "html" || lowerType === "text/html" || lowerType === "xhtml" || lowerType === "text/xhtml"){
  668. this.value = this.value?dojox.atom.io.model.util.unEscapeHtml(this.value):"";
  669. }
  670. if(this._postBuild){this._postBuild();}
  671. },
  672. toString: function(){
  673. // summary:
  674. // Function to construct string form of the content tag, which is an XML structure.
  675. // description:
  676. // Function to construct string form of the content tag, which is an XML structure.
  677. var s = [];
  678. s.push('<'+this.tagName+' ');
  679. if(!this.type){this.type = "text";}
  680. if(this.type){s.push(' type="'+this.type+'" ');}
  681. if(this.xmlLang){s.push(' xml:lang="'+this.xmlLang+'" ');}
  682. if(this.xmlBase){s.push(' xml:base="'+this.xmlBase+'" ');}
  683. //all HTML must be escaped
  684. if(this.type.toLowerCase() == this.HTML){
  685. s.push('>'+dojox.atom.io.model.util.escapeHtml(this.value)+'</'+this.tagName+'>\n');
  686. }else{
  687. s.push('>'+this.value+'</'+this.tagName+'>\n');
  688. }
  689. var ret = s.join('');
  690. return ret;
  691. }
  692. });
  693. dojo.declare("dojox.atom.io.model.Link",dojox.atom.io.model.Node,{
  694. // summary:
  695. // Class container for 'link' types.
  696. // description:
  697. // Class container for 'link' types.
  698. constructor: function(href,rel,hrefLang,title,type){
  699. this.href = href; this.hrefLang = hrefLang; this.rel = rel; this.title = title;this.type = type;
  700. },
  701. _getAttributeNames: function(){return ["href","jrefLang","rel","title","type"];},
  702. _postBuild: function(){},
  703. buildFromDom: function(node){
  704. // summary:
  705. // Function to do construction of the link data from the DOM node containing it.
  706. // description:
  707. // Function to do construction of the link data from the DOM node containing it.
  708. //
  709. // node:
  710. // The DOM node to process for link data.
  711. this._saveAttributes(node);//just get the attributes from the node
  712. this.href = this.attributes.href;
  713. this.hrefLang = this.attributes.hreflang;
  714. this.rel = this.attributes.rel;
  715. this.title = this.attributes.title;
  716. this.type = this.attributes.type;
  717. if(this._postBuild){this._postBuild();}
  718. },
  719. toString: function(){
  720. // summary:
  721. // Function to construct string form of the link tag, which is an XML structure.
  722. // description:
  723. // Function to construct string form of the link tag, which is an XML structure.
  724. var s = [];
  725. s.push('<link ');
  726. if(this.href){s.push(' href="'+this.href+'" ');}
  727. if(this.hrefLang){s.push(' hrefLang="'+this.hrefLang+'" ');}
  728. if(this.rel){s.push(' rel="'+this.rel+'" ');}
  729. if(this.title){s.push(' title="'+this.title+'" ');}
  730. if(this.type){s.push(' type = "'+this.type+'" ');}
  731. s.push('/>\n');
  732. return s.join('');
  733. }
  734. });
  735. dojo.declare("dojox.atom.io.model.Person",dojox.atom.io.model.Node,{
  736. // summary:
  737. // Class container for 'person' types, such as Author, controbutors, and so on.
  738. // description:
  739. // Class container for 'person' types, such as Author, controbutors, and so on.
  740. constructor: function(personType, name, email, uri){
  741. this.author = "author";
  742. this.contributor = "contributor";
  743. if(!personType){
  744. personType = this.author;
  745. }
  746. this.personType = personType;
  747. this.name = name || '';
  748. this.email = email || '';
  749. this.uri = uri || '';
  750. this._objName = "Person";//for debugging
  751. },
  752. _getAttributeNames: function(){return null;},
  753. _postBuild: function(){},
  754. accept: function(tag){return Boolean(this._accepts[tag]);},
  755. buildFromDom: function(node){
  756. // summary:
  757. // Function to do construction of the person data from the DOM node containing it.
  758. // description:
  759. // Function to do construction of the person data from the DOM node containing it.
  760. //
  761. // node:
  762. // The DOM node to process for person data.
  763. var c = node.childNodes;
  764. for(var i = 0; i< c.length; i++){
  765. var name = dojox.atom.io.model.util.getNodename(c[i]);
  766. if(!name){continue;}
  767. if(c[i].namespaceURI != dojox.atom.io.model._Constants.ATOM_NS && name != "#text"){
  768. if(!this.extensions){this.extensions = [];}
  769. var extensionNode = new dojox.atom.io.model.Node();
  770. extensionNode.buildFromDom(c[i]);
  771. this.extensions.push(extensionNode);
  772. }
  773. if(!this.accept(name.toLowerCase())){
  774. continue;
  775. }
  776. var fn = dojox.atom.io.model._actions[name];
  777. if(fn) {
  778. fn(this,c[i]);
  779. }
  780. }
  781. this._saveAttributes(node);
  782. if(this._postBuild){this._postBuild();}
  783. },
  784. _accepts: {
  785. 'name': true,
  786. 'uri': true,
  787. 'email': true
  788. },
  789. toString: function(){
  790. // summary:
  791. // Function to construct string form of the Person tag, which is an XML structure.
  792. // description:
  793. // Function to construct string form of the Person tag, which is an XML structure.
  794. var s = [];
  795. s.push('<'+this.personType+'>\n');
  796. if(this.name){s.push('\t<name>'+this.name+'</name>\n');}
  797. if(this.email){s.push('\t<email>'+this.email+'</email>\n');}
  798. if(this.uri){s.push('\t<uri>'+this.uri+'</uri>\n');}
  799. s.push('</'+this.personType+'>\n');
  800. return s.join('');
  801. }
  802. });
  803. dojo.declare("dojox.atom.io.model.Generator",dojox.atom.io.model.Node,{
  804. // summary:
  805. // Class container for 'Generator' types.
  806. // description:
  807. // Class container for 'Generator' types.
  808. constructor: function(/*String*/uri, /*String*/version, /*String*/value){
  809. this.uri = uri;
  810. this.version = version;
  811. this.value = value;
  812. },
  813. _postBuild: function(){},
  814. buildFromDom: function(node){
  815. // summary:
  816. // Function to do construction of the generator data from the DOM node containing it.
  817. // description:
  818. // Function to do construction of the generator data from the DOM node containing it.
  819. //
  820. // node:
  821. // The DOM node to process for link data.
  822. this.value = dojox.xml.parser.textContent(node);
  823. this._saveAttributes(node);
  824. this.uri = this.attributes.uri;
  825. this.version = this.attributes.version;
  826. if(this._postBuild){this._postBuild();}
  827. },
  828. toString: function(){
  829. // summary:
  830. // Function to construct string form of the Generator tag, which is an XML structure.
  831. // description:
  832. // Function to construct string form of the Generator tag, which is an XML structure.
  833. var s = [];
  834. s.push('<generator ');
  835. if(this.uri){s.push(' uri="'+this.uri+'" ');}
  836. if(this.version){s.push(' version="'+this.version+'" ');}
  837. s.push('>'+this.value+'</generator>\n');
  838. var ret = s.join('');
  839. return ret;
  840. }
  841. });
  842. dojo.declare("dojox.atom.io.model.Entry",dojox.atom.io.model.AtomItem,{
  843. // summary:
  844. // Class container for 'Entry' types.
  845. // description:
  846. // Class container for 'Entry' types.
  847. constructor: function(/*String*/id){
  848. this.id = id; this._objName = "Entry"; this.feedUrl = null;
  849. },
  850. _getAttributeNames: function(){return null;},
  851. _accepts: {
  852. 'author': true,
  853. 'content': true,
  854. 'category': true,
  855. 'contributor': true,
  856. 'created': true,
  857. 'id': true,
  858. 'link': true,
  859. 'published': true,
  860. 'rights': true,
  861. 'summary': true,
  862. 'title': true,
  863. 'updated': true,
  864. 'xmlbase': true,
  865. 'issued': true,
  866. 'modified': true
  867. },
  868. toString: function(amPrimary){
  869. // summary:
  870. // Function to construct string form of the entry tag, which is an XML structure.
  871. // description:
  872. // Function to construct string form of the entry tag, which is an XML structure.
  873. var s = [];
  874. var i;
  875. if(amPrimary){
  876. s.push("<?xml version='1.0' encoding='UTF-8'?>");
  877. s.push("<entry xmlns='"+dojox.atom.io.model._Constants.ATOM_URI+"'");
  878. }else{s.push("<entry");}
  879. if(this.xmlBase){s.push(' xml:base="'+this.xmlBase+'" ');}
  880. for(i in this.name_spaces){s.push(' xmlns:'+i+'="'+this.name_spaces[i]+'"');}
  881. s.push('>\n');
  882. s.push('<id>' + (this.id ? this.id: '') + '</id>\n');
  883. if(this.issued && !this.published){this.published = this.issued;}
  884. if(this.published){s.push('<published>'+dojo.date.stamp.toISOString(this.published)+'</published>\n');}
  885. if(this.created){s.push('<created>'+dojo.date.stamp.toISOString(this.created)+'</created>\n');}
  886. //Google News
  887. if(this.issued){s.push('<issued>'+dojo.date.stamp.toISOString(this.issued)+'</issued>\n');}
  888. //Google News
  889. if(this.modified){s.push('<modified>'+dojo.date.stamp.toISOString(this.modified)+'</modified>\n');}
  890. if(this.modified && !this.updated){this.updated = this.modified;}
  891. if(this.updated){s.push('<updated>'+dojo.date.stamp.toISOString(this.updated)+'</updated>\n');}
  892. if(this.rights){s.push('<rights>'+this.rights+'</rights>\n');}
  893. if(this.title){s.push(this.title.toString());}
  894. if(this.summary){s.push(this.summary.toString());}
  895. var arrays = [this.authors,this.categories,this.links,this.contributors,this.extensions];
  896. for(var x in arrays){
  897. if(arrays[x]){
  898. for(var y in arrays[x]){
  899. s.push(arrays[x][y]);
  900. }
  901. }
  902. }
  903. if(this.content){s.push(this.content.toString());}
  904. s.push("</entry>\n");
  905. return s.join(''); //string
  906. },
  907. getEditHref: function(){
  908. // summary:
  909. // Function to get the href that allows editing of this feed entry.
  910. // description:
  911. // Function to get the href that allows editing of this feed entry.
  912. //
  913. // returns:
  914. // The href that specifies edit capability.
  915. if(this.links === null || this.links.length === 0){
  916. return null;
  917. }
  918. for(var x in this.links){
  919. if(this.links[x].rel && this.links[x].rel == "edit"){
  920. return this.links[x].href; //string
  921. }
  922. }
  923. return null;
  924. },
  925. setEditHref: function(url){
  926. if(this.links === null){
  927. this.links = [];
  928. }
  929. for(var x in this.links){
  930. if(this.links[x].rel && this.links[x].rel == "edit"){
  931. this.links[x].href = url;
  932. return;
  933. }
  934. }
  935. this.addLink(url, 'edit');
  936. }
  937. });
  938. dojo.declare("dojox.atom.io.model.Feed",dojox.atom.io.model.AtomItem,{
  939. // summary:
  940. // Class container for 'Feed' types.
  941. // description:
  942. // Class container for 'Feed' types.
  943. _accepts: {
  944. 'author': true,
  945. 'content': true,
  946. 'category': true,
  947. 'contributor': true,
  948. 'created': true,
  949. 'id': true,
  950. 'link': true,
  951. 'published': true,
  952. 'rights': true,
  953. 'summary': true,
  954. 'title': true,
  955. 'updated': true,
  956. 'xmlbase': true,
  957. 'entry': true,
  958. 'logo': true,
  959. 'issued': true,
  960. 'modified': true,
  961. 'icon': true,
  962. 'subtitle': true
  963. },
  964. addEntry: function(/*object*/entry){
  965. // summary:
  966. // Function to add an entry to this feed.
  967. // description:
  968. // Function to add an entry to this feed.
  969. // entry:
  970. // The entry object to add.
  971. if(!entry.id){
  972. throw new Error("The entry object must be assigned an ID attribute.");
  973. }
  974. if(!this.entries){this.entries = [];}
  975. entry.feedUrl = this.getSelfHref();
  976. this.entries.push(entry);
  977. },
  978. getFirstEntry: function(){
  979. // summary:
  980. // Function to get the first entry of the feed.
  981. // description:
  982. // Function to get the first entry of the feed.
  983. //
  984. // returns:
  985. // The first entry in the feed.
  986. if(!this.entries || this.entries.length === 0){return null;}
  987. return this.entries[0]; //object
  988. },
  989. getEntry: function(/*String*/entryId){
  990. // summary:
  991. // Function to get an entry by its id.
  992. // description:
  993. // Function to get an entry by its id.
  994. //
  995. // returns:
  996. // The entry desired, or null if none.
  997. if(!this.entries){return null;}
  998. for(var x in this.entries){
  999. if(this.entries[x].id == entryId){
  1000. return this.entries[x];
  1001. }
  1002. }
  1003. return null;
  1004. },
  1005. removeEntry: function(/*object*/entry){
  1006. // summary:
  1007. // Function to remove an entry from the list of links.
  1008. // description:
  1009. // Function to remove an entry from the list of links.
  1010. //
  1011. // entry:
  1012. // The entry.
  1013. if(!this.entries){return;}
  1014. var count = 0;
  1015. for(var i = 0; i < this.entries.length; i++){
  1016. if(this.entries[i] === entry){
  1017. this.entries.splice(i,1);
  1018. count++;
  1019. }
  1020. }
  1021. return count;
  1022. },
  1023. setEntries: function(/*array*/arrayOfEntry){
  1024. // summary:
  1025. // Function to add a set of entries to the feed.
  1026. // description:
  1027. // Function to get an entry by its id.
  1028. //
  1029. // arrayOfEntry:
  1030. // An array of entry objects to add to the feed.
  1031. for(var x in arrayOfEntry){
  1032. this.addEntry(arrayOfEntry[x]);
  1033. }
  1034. },
  1035. toString: function(){
  1036. // summary:
  1037. // Function to construct string form of the feed tag, which is an XML structure.
  1038. // description:
  1039. // Function to construct string form of the feed tag, which is an XML structure.
  1040. var s = [];
  1041. var i;
  1042. s.push('<?xml version="1.0" encoding="utf-8"?>\n');
  1043. s.push('<feed xmlns="'+dojox.atom.io.model._Constants.ATOM_URI+'"');
  1044. if(this.xmlBase){s.push(' xml:base="'+this.xmlBase+'"');}
  1045. for(i in this.name_spaces){s.push(' xmlns:'+i+'="'+this.name_spaces[i]+'"');}
  1046. s.push('>\n');
  1047. s.push('<id>' + (this.id ? this.id: '') + '</id>\n');
  1048. if(this.title){s.push(this.title);}
  1049. if(this.copyright && !this.rights){this.rights = this.copyright;}
  1050. if(this.rights){s.push('<rights>' + this.rights + '</rights>\n');}
  1051. // Google news
  1052. if(this.issued){s.push('<issued>'+dojo.date.stamp.toISOString(this.issued)+'</issued>\n');}
  1053. if(this.modified){s.push('<modified>'+dojo.date.stamp.toISOString(this.modified)+'</modified>\n');}
  1054. if(this.modified && !this.updated){this.updated=this.modified;}
  1055. if(this.updated){s.push('<updated>'+dojo.date.stamp.toISOString(this.updated)+'</updated>\n');}
  1056. if(this.published){s.push('<published>'+dojo.date.stamp.toISOString(this.published)+'</published>\n');}
  1057. if(this.icon){s.push('<icon>'+this.icon+'</icon>\n');}
  1058. if(this.language){s.push('<language>'+this.language+'</language>\n');}
  1059. if(this.logo){s.push('<logo>'+this.logo+'</logo>\n');}
  1060. if(this.subtitle){s.push(this.subtitle.toString());}
  1061. if(this.tagline){s.push(this.tagline.toString());}
  1062. //TODO: need to figure out what to do with xmlBase
  1063. var arrays = [this.alternateLinks,this.authors,this.categories,this.contributors,this.otherLinks,this.extensions,this.entries];
  1064. for(i in arrays){
  1065. if(arrays[i]){
  1066. for(var x in arrays[i]){
  1067. s.push(arrays[i][x]);
  1068. }
  1069. }
  1070. }
  1071. s.push('</feed>');
  1072. return s.join('');
  1073. },
  1074. createEntry: function(){
  1075. // summary:
  1076. // Function to Create a new entry object in the feed.
  1077. // description:
  1078. // Function to Create a new entry object in the feed.
  1079. // returns:
  1080. // An empty entry object in the feed.
  1081. var entry = new dojox.atom.io.model.Entry();
  1082. entry.feedUrl = this.getSelfHref();
  1083. return entry; //object
  1084. },
  1085. getSelfHref: function(){
  1086. // summary:
  1087. // Function to get the href that refers to this feed.
  1088. // description:
  1089. // Function to get the href that refers to this feed.
  1090. // returns:
  1091. // The href that refers to this feed or null if none.
  1092. if(this.links === null || this.links.length === 0){
  1093. return null;
  1094. }
  1095. for(var x in this.links){
  1096. if(this.links[x].rel && this.links[x].rel == "self"){
  1097. return this.links[x].href; //string
  1098. }
  1099. }
  1100. return null;
  1101. }
  1102. });
  1103. dojo.declare("dojox.atom.io.model.Service",dojox.atom.io.model.AtomItem,{
  1104. // summary:
  1105. // Class container for 'Feed' types.
  1106. // description:
  1107. // Class container for 'Feed' types.
  1108. constructor: function(href){
  1109. this.href = href;
  1110. },
  1111. //builds a Service document. each element of this, except for the namespace, is the href of
  1112. //a service that the server supports. Some of the common services are:
  1113. //"create-entry" , "user-prefs" , "search-entries" , "edit-template" , "categories"
  1114. buildFromDom: function(/*DOM node*/node){
  1115. // summary:
  1116. // Function to do construction of the Service data from the DOM node containing it.
  1117. // description:
  1118. // Function to do construction of the Service data from the DOM node containing it.
  1119. //
  1120. // node:
  1121. // The DOM node to process for content.
  1122. var i;
  1123. this.workspaces = [];
  1124. if(node.tagName != "service"){
  1125. // FIXME: Need 0.9 DOM util...
  1126. //node = dojox.xml.parser.firstElement(node,"service");
  1127. //if(!node){return;}
  1128. return;
  1129. }
  1130. if(node.namespaceURI != dojox.atom.io.model._Constants.PURL_NS && node.namespaceURI != dojox.atom.io.model._Constants.APP_NS){return;}
  1131. var ns = node.namespaceURI;
  1132. this.name_space = node.namespaceURI;
  1133. //find all workspaces, and create them
  1134. var workspaces ;
  1135. if(typeof(node.getElementsByTagNameNS)!= "undefined"){
  1136. workspaces = node.getElementsByTagNameNS(ns,"workspace");
  1137. }else{
  1138. // This block is IE only, which doesn't have a 'getElementsByTagNameNS' function
  1139. workspaces = [];
  1140. var temp = node.getElementsByTagName('workspace');
  1141. for(i=0; i<temp.length; i++){
  1142. if(temp[i].namespaceURI == ns){
  1143. workspaces.push(temp[i]);
  1144. }
  1145. }
  1146. }
  1147. if(workspaces && workspaces.length > 0){
  1148. var wkLen = 0;
  1149. var workspace;
  1150. for(i = 0; i< workspaces.length; i++){
  1151. workspace = (typeof(workspaces.item)==="undefined"?workspaces[i]:workspaces.item(i));
  1152. var wkspace = new dojox.atom.io.model.Workspace();
  1153. wkspace.buildFromDom(workspace);
  1154. this.workspaces[wkLen++] = wkspace;
  1155. }
  1156. }
  1157. },
  1158. getCollection: function(/*String*/url){
  1159. // summary:
  1160. // Function to collections that match a specific url.
  1161. // description:
  1162. // Function to collections that match a specific url.
  1163. //
  1164. // url:
  1165. // e URL to match collections against.
  1166. for(var i=0;i<this.workspaces.length;i++){
  1167. var coll=this.workspaces[i].collections;
  1168. for(var j=0;j<coll.length;j++){
  1169. if(coll[j].href == url){
  1170. return coll;
  1171. }
  1172. }
  1173. }
  1174. return null;
  1175. }
  1176. });
  1177. dojo.declare("dojox.atom.io.model.Workspace",dojox.atom.io.model.AtomItem,{
  1178. // summary:
  1179. // Class container for 'Workspace' types.
  1180. // description:
  1181. // Class container for 'Workspace' types.
  1182. constructor: function(title){
  1183. this.title = title;
  1184. this.collections = [];
  1185. },
  1186. buildFromDom: function(/*DOM node*/node){
  1187. // summary:
  1188. // Function to do construction of the Workspace data from the DOM node containing it.
  1189. // description:
  1190. // Function to do construction of the Workspace data from the DOM node containing it.
  1191. //
  1192. // node:
  1193. // The DOM node to process for content.
  1194. var name = dojox.atom.io.model.util.getNodename(node);
  1195. if(name != "workspace"){return;}
  1196. var c = node.childNodes;
  1197. var len = 0;
  1198. for(var i = 0; i< c.length; i++){
  1199. var child = c[i];
  1200. if(child.nodeType === 1){
  1201. name = dojox.atom.io.model.util.getNodename(child);
  1202. if(child.namespaceURI == dojox.atom.io.model._Constants.PURL_NS || child.namespaceURI == dojox.atom.io.model._Constants.APP_NS){
  1203. if(name === "collection"){
  1204. var coll = new dojox.atom.io.model.Collection();
  1205. coll.buildFromDom(child);
  1206. this.collections[len++] = coll;
  1207. }
  1208. }else if(child.namespaceURI === dojox.atom.io.model._Constants.ATOM_NS){
  1209. if(name === "title"){
  1210. this.title = dojox.xml.parser.textContent(child);
  1211. }
  1212. }
  1213. //FIXME: Add an extension point so others can impl different namespaces. For now just
  1214. //ignore unknown namespace tags.
  1215. }
  1216. }
  1217. }
  1218. });
  1219. dojo.declare("dojox.atom.io.model.Collection",dojox.atom.io.model.AtomItem,{
  1220. // summary:
  1221. // Class container for 'Collection' types.
  1222. // description:
  1223. // Class container for 'Collection' types.
  1224. constructor: function(href, title){
  1225. this.href = href;
  1226. this.title = title;
  1227. this.attributes = [];
  1228. this.features = [];
  1229. this.children = [];
  1230. this.memberType = null;
  1231. this.id = null;
  1232. },
  1233. buildFromDom: function(/*DOM node*/node){
  1234. // summary:
  1235. // Function to do construction of the Collection data from the DOM node containing it.
  1236. // description:
  1237. // Function to do construction of the Collection data from the DOM node containing it.
  1238. //
  1239. // node:
  1240. // The DOM node to process for content.
  1241. this.href = node.getAttribute("href");
  1242. var c = node.childNodes;
  1243. for(var i = 0; i< c.length; i++){
  1244. var child = c[i];
  1245. if(child.nodeType === 1){
  1246. var name = dojox.atom.io.model.util.getNodename(child);
  1247. if(child.namespaceURI == dojox.atom.io.model._Constants.PURL_NS || child.namespaceURI == dojox.atom.io.model._Constants.APP_NS){
  1248. if(name === "member-type"){
  1249. this.memberType = dojox.xml.parser.textContent(child);
  1250. }else if(name == "feature"){//this IF stmt might need some more work
  1251. if(child.getAttribute("id")){this.features.push(child.getAttribute("id"));}
  1252. }else{
  1253. var unknownTypeChild = new dojox.atom.io.model.Node();
  1254. unknownTypeChild.buildFromDom(child);
  1255. this.children.push(unknownTypeChild);
  1256. }
  1257. }else if(child.namespaceURI === dojox.atom.io.model._Constants.ATOM_NS){
  1258. if(name === "id"){
  1259. this.id = dojox.xml.parser.textContent(child);
  1260. }else if(name === "title"){
  1261. this.title = dojox.xml.parser.textContent(child);
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. });
  1268. }