//>>built
define("dojox/data/AtomReadStore",["dojo","dojox","dojo/data/util/filter","dojo/data/util/simpleFetch","dojo/date/stamp"],function(g,p){g.experimental("dojox.data.AtomReadStore");var n=g.declare("dojox.data.AtomReadStore",null,{constructor:function(a){a&&(this.url=a.url,this.rewriteUrl=a.rewriteUrl,this.label=a.label||this.label,this.sendQuery=a.sendQuery||a.sendquery||this.sendQuery,this.unescapeHTML=a.unescapeHTML,"urlPreventCache"in a&&(this.urlPreventCache=a.urlPreventCache?!0:!1));if(!this.url)throw Error("AtomReadStore: a URL must be specified when creating the data store");
},url:"",label:"title",sendQuery:!1,unescapeHTML:!1,urlPreventCache:!1,getValue:function(a,b,e){this._assertIsItem(a);this._assertIsAttribute(b);this._initItem(a);b=b.toLowerCase();a._attribs[b]||a._parsed||(this._parseItem(a),a._parsed=!0);var c=a._attribs[b];c||"summary"!=b||(c=this.getValue(a,"content").text.replace(RegExp("/(\x3c([^\x3e]+)\x3e)/g","i"),""),c={text:c.substring(0,Math.min(400,c.length)),type:"text"},a._attribs[b]=c);!c||!this.unescapeHTML||"content"!=b&&"summary"!=b&&"subtitle"!=
b||a["_"+b+"Escaped"]||(c.text=this._unescapeHTML(c.text),a["_"+b+"Escaped"]=!0);return c?g.isArray(c)?c[0]:c:e},getValues:function(a,b){this._assertIsItem(a);this._assertIsAttribute(b);this._initItem(a);b=b.toLowerCase();a._attribs[b]||this._parseItem(a);var e=a._attribs[b];return e?void 0!==e.length&&"string"!==typeof e?e:[e]:void 0},getAttributes:function(a){this._assertIsItem(a);a._attribs||(this._initItem(a),this._parseItem(a));var b=[],e;for(e in a._attribs)b.push(e);return b},hasAttribute:function(a,
b){return void 0!==this.getValue(a,b)},containsValue:function(a,b,e){a=this.getValues(a,b);for(b=0;b<a.length;b++)if("string"===typeof e){if(a[b].toString&&a[b].toString()===e)return!0}else if(a[b]===e)return!0;return!1},isItem:function(a){return a&&a.element&&a.store&&a.store===this?!0:!1},isItemLoaded:function(a){return this.isItem(a)},loadItem:function(a){},getFeatures:function(){return{"dojo.data.api.Read":!0}},getLabel:function(a){if(""!==this.label&&this.isItem(a)){if((a=this.getValue(a,this.label))&&
a.text)return a.text;if(a)return a.toString()}},getLabelAttributes:function(a){return""!==this.label?[this.label]:null},getFeedValue:function(a,b){var e=this.getFeedValues(a,b);return g.isArray(e)?e[0]:e},getFeedValues:function(a,b){if(!this.doc)return b;this._feedMetaData||(this._feedMetaData={element:this.doc.getElementsByTagName("feed")[0],store:this,_attribs:{}},this._parseItem(this._feedMetaData));return this._feedMetaData._attribs[a]||b},_initItem:function(a){a._attribs||(a._attribs={})},_fetchItems:function(a,
b,e){var c=this._getFetchUrl(a);if(c){var d=this.sendQuery?null:a,f=this,k=function(h){f.doc=h;h=f._getItems(h,d);var l=a.query;l&&(l.id?h=g.filter(h,function(m){return f.getValue(m,"id")==l.id}):l.category&&(h=g.filter(h,function(m){return(m=f.getValues(m,"category"))?g.some(m,"return item.term\x3d\x3d'"+l.category+"'"):!1})));h&&0<h.length?b(h,a):b([],a)};this.doc?k(this.doc):(c=g.xhrGet({url:c,handleAs:"xml",preventCache:this.urlPreventCache}),c.addCallback(k),c.addErrback(function(h){e(h,a)}))}else e(Error("No URL specified."))},
_getFetchUrl:function(a){if(!this.sendQuery)return this.url;var b=a.query;if(!b)return this.url;if(g.isString(b))return this.url+b;a="";for(var e in b){var c=b[e];c&&(a&&(a+="\x26"),a+=e+"\x3d"+c)}if(!a)return this.url;e=this.url;e=0>e.indexOf("?")?e+"?":e+"\x26";return e+a},_getItems:function(a,b){if(this._items)return this._items;var e=[],c=[];if(1>a.childNodes.length)return this._items=e;c=g.filter(a.childNodes,"return item.tagName \x26\x26 item.tagName.toLowerCase() \x3d\x3d 'feed'");if(!c||1!=
c.length)return e;c=g.filter(c[0].childNodes,"return item.tagName \x26\x26 item.tagName.toLowerCase() \x3d\x3d 'entry'");if(b.onBegin)b.onBegin(c.length,this.sendQuery?b:{});for(var d=0;d<c.length;d++){var f=c[d];1==f.nodeType&&e.push(this._getItem(f))}return this._items=e},close:function(a){},_getItem:function(a){return{element:a,store:this}},_parseItem:function(a){function b(d){var f=d.textContent||d.innerHTML||d.innerXML;if(!f&&d.childNodes[0]){var k=d.childNodes[0];!k||3!=k.nodeType&&4!=k.nodeType||
(f=d.childNodes[0].nodeValue)}return f}function e(d){return{text:b(d),type:d.getAttribute("type")}}var c=a._attribs;g.forEach(a.element.childNodes,function(d){var f=d.tagName?d.tagName.toLowerCase():"";switch(f){case "title":c[f]={text:b(d),type:d.getAttribute("type")};break;case "subtitle":case "summary":case "content":c[f]=e(d);break;case "author":var k,h;g.forEach(d.childNodes,function(l){if(l.tagName)switch(l.tagName.toLowerCase()){case "name":k=l;break;case "uri":h=l}});d={};k&&1==k.length&&
(d.name=b(k[0]));h&&1==h.length&&(d.uri=b(h[0]));c[f]=d;break;case "id":c[f]=b(d);break;case "updated":c[f]=g.date.stamp.fromISOString(b(d));break;case "published":c[f]=g.date.stamp.fromISOString(b(d));break;case "category":c[f]||(c[f]=[]);c[f].push({scheme:d.getAttribute("scheme"),term:d.getAttribute("term")});break;case "link":c[f]||(c[f]=[]),d={rel:d.getAttribute("rel"),href:d.getAttribute("href"),type:d.getAttribute("type")},c[f].push(d),"alternate"==d.rel&&(c.alternate=d)}})},_unescapeHTML:function(a){return a=
a.replace(/&#8217;/m,"'").replace(/&#8243;/m,'"').replace(/&#60;/m,"\x3e").replace(/&#62;/m,"\x3c").replace(/&#38;/m,"\x26")},_assertIsItem:function(a){if(!this.isItem(a))throw Error("dojox.data.AtomReadStore: Invalid item argument.");},_assertIsAttribute:function(a){if("string"!==typeof a)throw Error("dojox.data.AtomReadStore: Invalid attribute argument.");}});g.extend(n,g.data.util.simpleFetch);return n});