/* Copyright (c) 2004-2011, 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*/// BUG: CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')// if(!dojo._hasResource["dojox.data.AndOrReadStore"]){dojo._hasResource["dojox.data.AndOrReadStore"]=true;dojo.provide("dojox.data.AndOrReadStore");dojo.require("dojo.data.util.filter");dojo.require("dojo.data.util.simpleFetch");dojo.require("dojo.date.stamp");dojo.declare("dojox.data.AndOrReadStore",null,{constructor:function(_1){this._arrayOfAllItems=[];this._arrayOfTopLevelItems=[];this._loadFinished=false;this._jsonFileUrl=_1.url;this._ccUrl=_1.url;this.url=_1.url;this._jsonData=_1.data;this.data=null;this._datatypeMap=_1.typeMap||{};if(!this._datatypeMap["Date"]){this._datatypeMap["Date"]={type:Date,deserialize:function(_2){return dojo.date.stamp.fromISOString(_2);}};}this._features={"dojo.data.api.Read":true,"dojo.data.api.Identity":true};this._itemsByIdentity=null;this._storeRefPropName="_S";this._itemNumPropName="_0";this._rootItemPropName="_RI";this._reverseRefMap="_RRM";this._loadInProgress=false;this._queuedFetches=[];if(_1.urlPreventCache!==undefined){this.urlPreventCache=_1.urlPreventCache?true:false;}if(_1.hierarchical!==undefined){this.hierarchical=_1.hierarchical?true:false;}if(_1.clearOnClose){this.clearOnClose=true;}},url:"",_ccUrl:"",data:null,typeMap:null,clearOnClose:false,urlPreventCache:false,hierarchical:true,_assertIsItem:function(_3){if(!this.isItem(_3)){throw new Error("dojox.data.AndOrReadStore: Invalid item argument.");}},_assertIsAttribute:function(_4){if(typeof _4!=="string"){throw new Error("dojox.data.AndOrReadStore: Invalid attribute argument.");}},getValue:function(_5,_6,_7){var _8=this.getValues(_5,_6);return (_8.length>0)?_8[0]:_7;},getValues:function(_9,_a){this._assertIsItem(_9);this._assertIsAttribute(_a);var _b=_9[_a]||[];return _b.slice(0,_b.length);},getAttributes:function(_c){this._assertIsItem(_c);var _d=[];for(var _e in _c){if((_e!==this._storeRefPropName)&&(_e!==this._itemNumPropName)&&(_e!==this._rootItemPropName)&&(_e!==this._reverseRefMap)){_d.push(_e);}}return _d;},hasAttribute:function(_f,_10){this._assertIsItem(_f);this._assertIsAttribute(_10);return (_10 in _f);},containsValue:function(_11,_12,_13){var _14=undefined;if(typeof _13==="string"){_14=dojo.data.util.filter.patternToRegExp(_13,false);}return this._containsValue(_11,_12,_13,_14);},_containsValue:function(_15,_16,_17,_18){return dojo.some(this.getValues(_15,_16),function(_19){if(_19!==null&&!dojo.isObject(_19)&&_18){if(_19.toString().match(_18)){return true;}}else{if(_17===_19){return true;}}});},isItem:function(_1a){if(_1a&&_1a[this._storeRefPropName]===this){if(this._arrayOfAllItems[_1a[this._itemNumPropName]]===_1a){return true;}}return false;},isItemLoaded:function(_1b){return this.isItem(_1b);},loadItem:function(_1c){this._assertIsItem(_1c.item);},getFeatures:function(){return this._features;},getLabel:function(_1d){if(this._labelAttr&&this.isItem(_1d)){return this.getValue(_1d,this._labelAttr);}return undefined;},getLabelAttributes:function(_1e){if(this._labelAttr){return [this._labelAttr];}return null;},_fetchItems:function(_1f,_20,_21){var _22=this;var _23=function(_24,_25){var _26=[];if(_24.query){var _27=dojo.fromJson(dojo.toJson(_24.query));if(typeof _27=="object"){var _28=0;var p;for(p in _27){_28++;}if(_28>1&&_27.complexQuery){var cq=_27.complexQuery;var _29=false;for(p in _27){if(p!=="complexQuery"){if(!_29){cq="( "+cq+" )";_29=true;}var v=_24.query[p];if(dojo.isString(v)){v="'"+v+"'";}cq+=" AND "+p+":"+v;delete _27[p];}}_27.complexQuery=cq;}}var _2a=_24.queryOptions?_24.queryOptions.ignoreCase:false;if(typeof _27!="string"){_27=dojo.toJson(_27);_27=_27.replace(/\\\\/g,"\\");}_27=_27.replace(/\\"/g,"\"");var _2b=dojo.trim(_27.replace(/{|}/g,""));var _2c,i;if(_2b.match(/"? *complexQuery *"?:/)){_2b=dojo.trim(_2b.replace(/"?\s*complexQuery\s*"?:/,""));var _2d=["'","\""];var _2e,_2f;var _30=false;for(i=0;i<_2d.length;i++){_2e=_2b.indexOf(_2d[i]);_2c=_2b.indexOf(_2d[i],1);_2f=_2b.indexOf(":",1);if(_2e===0&&_2c!=-1&&_2f<_2c){_30=true;break;}}if(_30){_2b=_2b.replace(/^\"|^\'|\"$|\'$/g,"");}}var _31=_2b;var _32=/^,|^NOT |^AND |^OR |^\(|^\)|^!|^&&|^\|\|/i;var _33="";var op="";var val="";var pos=-1;var err=false;var key="";var _34="";var tok="";_2c=-1;for(i=0;i<_25.length;++i){var _35=true;var _36=_25[i];if(_36===null){_35=false;}else{_2b=_31;_33="";while(_2b.length>0&&!err){op=_2b.match(_32);while(op&&!err){_2b=dojo.trim(_2b.replace(op[0],""));op=dojo.trim(op[0]).toUpperCase();op=op=="NOT"?"!":op=="AND"||op==","?"&&":op=="OR"?"||":op;op=" "+op+" ";_33+=op;op=_2b.match(_32);}if(_2b.length>0){pos=_2b.indexOf(":");if(pos==-1){err=true;break;}else{key=dojo.trim(_2b.substring(0,pos).replace(/\"|\'/g,""));_2b=dojo.trim(_2b.substring(pos+1));tok=_2b.match(/^\'|^\"/);if(tok){tok=tok[0];pos=_2b.indexOf(tok);_2c=_2b.indexOf(tok,pos+1);if(_2c==-1){err=true;break;}_34=_2b.substring(pos+1,_2c);if(_2c==_2b.length-1){_2b="";}else{_2b=dojo.trim(_2b.substring(_2c+1));}_33+=_22._containsValue(_36,key,_34,dojo.data.util.filter.patternToRegExp(_34,_2a));}else{tok=_2b.match(/\s|\)|,/);if(tok){var _37=new Array(tok.length);for(var j=0;j1){for(var j=1;j<_37.length;j++){pos=Math.min(pos,_37[j]);}}_34=dojo.trim(_2b.substring(0,pos));_2b=dojo.trim(_2b.substring(pos));}else{_34=dojo.trim(_2b);_2b="";}_33+=_22._containsValue(_36,key,_34,dojo.data.util.filter.patternToRegExp(_34,_2a));}}}}_35=eval(_33);}if(_35){_26.push(_36);}}if(err){_26=[];}_20(_26,_24);}else{for(var i=0;i<_25.length;++i){var _38=_25[i];if(_38!==null){_26.push(_38);}}_20(_26,_24);}};if(this._loadFinished){_23(_1f,this._getItemsArray(_1f.queryOptions));}else{if(this._jsonFileUrl!==this._ccUrl){dojo.deprecated("dojox.data.AndOrReadStore: ","To change the url, set the url property of the store,"+" not _jsonFileUrl. _jsonFileUrl support will be removed in 2.0");this._ccUrl=this._jsonFileUrl;this.url=this._jsonFileUrl;}else{if(this.url!==this._ccUrl){this._jsonFileUrl=this.url;this._ccUrl=this.url;}}if(this.data!=null&&this._jsonData==null){this._jsonData=this.data;this.data=null;}if(this._jsonFileUrl){if(this._loadInProgress){this._queuedFetches.push({args:_1f,filter:_23});}else{this._loadInProgress=true;var _39={url:_22._jsonFileUrl,handleAs:"json-comment-optional",preventCache:this.urlPreventCache};var _3a=dojo.xhrGet(_39);_3a.addCallback(function(_3b){try{_22._getItemsFromLoadedData(_3b);_22._loadFinished=true;_22._loadInProgress=false;_23(_1f,_22._getItemsArray(_1f.queryOptions));_22._handleQueuedFetches();}catch(e){_22._loadFinished=true;_22._loadInProgress=false;_21(e,_1f);}});_3a.addErrback(function(_3c){_22._loadInProgress=false;_21(_3c,_1f);});var _3d=null;if(_1f.abort){_3d=_1f.abort;}_1f.abort=function(){var df=_3a;if(df&&df.fired===-1){df.cancel();df=null;}if(_3d){_3d.call(_1f);}};}}else{if(this._jsonData){try{this._loadFinished=true;this._getItemsFromLoadedData(this._jsonData);this._jsonData=null;_23(_1f,this._getItemsArray(_1f.queryOptions));}catch(e){_21(e,_1f);}}else{_21(new Error("dojox.data.AndOrReadStore: No JSON source data was provided as either URL or a nested Javascript object."),_1f);}}}},_handleQueuedFetches:function(){if(this._queuedFetches.length>0){for(var i=0;i