📄 atomreadstore.js
字号:
if(!dojo._hasResource["dojox.data.AtomReadStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.data.AtomReadStore"] = true;dojo.provide("dojox.data.AtomReadStore");dojo.require("dojo.data.util.simpleFetch");dojo.require("dojo.data.util.filter");dojo.require("dojo.date.stamp");dojo.experimental("dojox.data.AtomReadStore");dojo.declare("dojox.data.AtomReadStore", null, { // summary: // A read only data store for Atom XML based services or documents // description: // A data store for Atom XML based services or documents. This store is still under development // and doesn't support wildcard filtering yet. Attribute filtering is limited to category or id. constructor: function(/* object */ args) { // summary: // Constructor for the AtomRead store. // args: // An anonymous object to initialize properties. It expects the following values: // url: The url to a service or an XML document that represents the store // unescapeHTML: A boolean to specify whether or not to unescape HTML text // sendQuery: A boolean indicate to add a query string to the service URL if(args){ this.url = args.url; this.rewriteUrl = args.rewriteUrl; this.label = args.label || this.label; this.sendQuery = (args.sendQuery || args.sendquery || this.sendQuery); this.unescapeHTML = args.unescapeHTML; } if(!this.url){ throw new Error("AtomReadStore: a URL must be specified when creating the data store"); } }, //Values that may be set by the parser. //Ergo, have to be instantiated to something //So the parser knows how to set them. url: "", label: "title", sendQuery: false, unescapeHTML: false, /* dojo.data.api.Read */ getValue: function(/* item */ item, /* attribute || attribute-name-string */ attribute, /* value? */ defaultValue){ // summary: // Return an attribute value // description: // 'item' must be an instance of an object created by the AtomReadStore instance. // Accepted attributes are id, subtitle, title, summary, content, author, updated, // published, category, link and alternate // item: // An item returned by a call to the 'fetch' method. // attribute: // A attribute of the Atom Entry // defaultValue: // A default value // returns: // An attribute value found, otherwise 'defaultValue' this._assertIsItem(item); this._assertIsAttribute(attribute); this._initItem(item); attribute = attribute.toLowerCase(); //If the attribute has previously been retrieved, then return it if(!item._attribs[attribute] && !item._parsed){ this._parseItem(item); item._parsed = true; } var retVal = item._attribs[attribute]; if(!retVal && attribute=="summary") { var content = this.getValue(item, "content"); var regexp = new RegExp("/(<([^>]+)>)/g", "i"); var text = content.text.replace(regexp,""); retVal = { text: text.substring(0, Math.min(400, text.length)), type: "text" }; item._attribs[attribute] = retVal; } if(retVal && this.unescapeHTML){ if ((attribute == "content" || attribute == "summary" || attribute == "subtitle") && !item["_"+attribute+"Escaped"]) { retVal.text = this._unescapeHTML(retVal.text); item["_"+attribute+"Escaped"] = true; } } return retVal ? dojo.isArray(retVal) ? retVal[0]: retVal : undefined; }, getValues: function(/* item */ item, /* attribute || attribute-name-string */ attribute){ // summary: // Return an attribute value // description: // 'item' must be an instance of an object created by the AtomReadStore instance. // Accepted attributes are id, subtitle, title, summary, content, author, updated, // published, category, link and alternate // item: // An item returned by a call to the 'fetch' method. // attribute: // A attribute of the Atom Entry // defaultValue: // A default value // returns: // An array of values for the attribute value found, otherwise 'defaultValue' this._assertIsItem(item); this._assertIsAttribute(attribute); this._initItem(item); attribute = attribute.toLowerCase(); //If the attribute has previously been retrieved, then return it if(!item._attribs[attribute]){ this._parseItem(item); } var retVal = item._attribs[attribute]; return retVal ? ((retVal.length !== undefined && typeof(retVal) !== "string") ? retVal : [retVal]) : undefined; }, getAttributes: function(/* item */ item) { // summary: // Return an array of attribute names // description: // 'item' must be have been created by the AtomReadStore instance. // tag names of child elements and XML attribute names of attributes // specified to the element are returned along with special attribute // names applicable to the element including "tagName", "childNodes" // if the element has child elements, "text()" if the element has // child text nodes, and attribute names in '_attributeMap' that match // the tag name of the element. // item: // An XML element // returns: // An array of attributes found this._assertIsItem(item); if(!item._attribs){ this._initItem(item); this._parseItem(item); } var attrNames = []; for(var x in item._attribs){ attrNames.push(x); } return attrNames; //array }, hasAttribute: function(/* item */ item, /* attribute || attribute-name-string */ attribute){ // summary: // Check whether an element has the attribute // item: // 'item' must be created by the AtomReadStore instance. // attribute: // An attribute of an Atom Entry item. // returns: // True if the element has the attribute, otherwise false return (this.getValue(item, attribute) !== undefined); //boolean }, containsValue: function(/* item */ item, /* attribute || attribute-name-string */ attribute, /* anything */ value){ // summary: // Check whether the attribute values contain the value // item: // 'item' must be an instance of a dojox.data.XmlItem from the store instance. // attribute: // A tag name of a child element, An XML attribute name or one of // special names // returns: // True if the attribute values contain the value, otherwise false var values = this.getValues(item, attribute); for(var i = 0; i < values.length; i++){ if((typeof value === "string")){ if(values[i].toString && values[i].toString() === value){ return true; } }else if (values[i] === value){ return true; //boolean } } return false;//boolean }, isItem: function(/* anything */ something){ // summary: // Check whether the object is an item (XML element) // item: // An object to check // returns: // True if the object is an XML element, otherwise false if(something && something.element && something.store && something.store === this){ return true; //boolean } return false; //boolran }, isItemLoaded: function(/* anything */ something){ // summary: // Check whether the object is an item (XML element) and loaded // item: // An object to check // returns: // True if the object is an XML element, otherwise false return this.isItem(something); //boolean }, loadItem: function(/* object */ keywordArgs){ // summary: // Load an item (XML element) // keywordArgs: // object containing the args for loadItem. See dojo.data.api.Read.loadItem() }, getFeatures: function() { // summary: // Return supported data APIs // returns: // "dojo.data.api.Read" and "dojo.data.api.Write" var features = { "dojo.data.api.Read": true }; return features; //array }, getLabel: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabel() if((this.label !== "") && this.isItem(item)){ var label = this.getValue(item,this.label); if(label && label.text){ return label.text; }else if (label){ return label.toString(); }else{ return undefined; } } return undefined; //undefined }, getLabelAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabelAttributes() if(this.label !== ""){ return [this.label]; //array } return null; //null }, getFeedValue: function(attribute, defaultValue){ // summary: // Non-API method for retrieving values regarding the Atom feed, // rather than the Atom entries. var values = this.getFeedValues(attribute, defaultValue); if(dojo.isArray(values)){ return values[0]; } return values; }, getFeedValues: function(attribute, defaultValue){ // summary: // Non-API method for retrieving values regarding the Atom feed, // rather than the Atom entries. if(!this.doc){ return defaultValue; } if(!this._feedMetaData){ this._feedMetaData = {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -