📄 opmlstore.js
字号:
if(!dojo._hasResource["dojox.data.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.data.OpmlStore"] = true;dojo.provide("dojox.data.OpmlStore");dojo.require("dojo.data.util.filter");dojo.require("dojo.data.util.simpleFetch");dojo.declare("dojox.data.OpmlStore", null, { /* summary: * The OpmlStore implements the dojo.data.api.Read API. */ /* examples: * var opmlStore = new dojo.data.OpmlStore({url:"geography.xml"}); * var opmlStore = new dojo.data.OpmlStore({url:"http://example.com/geography.xml"}); */ constructor: function(/* Object */ keywordParameters){ // summary: constructor // keywordParameters: {url: String, label: String} Where label is optional and configures what should be used as the return from getLabel() this._xmlData = null; this._arrayOfTopLevelItems = []; this._arrayOfAllItems = []; this._metadataNodes = null; this._loadFinished = false; this.url = keywordParameters.url; this._opmlData = keywordParameters.data; // XML DOM Document if(keywordParameters.label){ this.label = keywordParameters.label; } this._loadInProgress = false; //Got to track the initial load to prevent duelling loads of the dataset. this._queuedFetches = []; this._identityMap = {}; this._identCount = 0; this._idProp = "_I"; }, label: "text", url: "", _assertIsItem: function(/* item */ item){ if(!this.isItem(item)){ throw new Error("dojo.data.OpmlStore: a function was passed an item argument that was not an item"); } }, _assertIsAttribute: function(/* item || String */ attribute){ // summary: // This function tests whether the item passed in is indeed a valid 'attribute' like type for the store. // attribute: // The attribute to test for being contained by the store. if(!dojo.isString(attribute)){ throw new Error("dojox.data.OpmlStore: a function was passed an attribute argument that was not an attribute object nor an attribute name string"); } }, _removeChildNodesThatAreNotElementNodes: function(/* node */ node, /* boolean */ recursive){ var childNodes = node.childNodes; if(childNodes.length === 0){ return; } var nodesToRemove = []; var i, childNode; for(i = 0; i < childNodes.length; ++i){ childNode = childNodes[i]; if(childNode.nodeType != 1){ nodesToRemove.push(childNode); } } for(i = 0; i < nodesToRemove.length; ++i){ childNode = nodesToRemove[i]; node.removeChild(childNode); } if(recursive){ for(i = 0; i < childNodes.length; ++i){ childNode = childNodes[i]; this._removeChildNodesThatAreNotElementNodes(childNode, recursive); } } }, _processRawXmlTree: function(/* xmlDoc */ rawXmlTree){ this._loadFinished = true; this._xmlData = rawXmlTree; var headNodes = rawXmlTree.getElementsByTagName('head'); var headNode = headNodes[0]; if(headNode){ this._removeChildNodesThatAreNotElementNodes(headNode); this._metadataNodes = headNode.childNodes; } var bodyNodes = rawXmlTree.getElementsByTagName('body'); var bodyNode = bodyNodes[0]; if(bodyNode){ this._removeChildNodesThatAreNotElementNodes(bodyNode, true); var bodyChildNodes = bodyNodes[0].childNodes; for(var i = 0; i < bodyChildNodes.length; ++i){ var node = bodyChildNodes[i]; if(node.tagName == 'outline'){ this._identityMap[this._identCount] = node; this._identCount++; this._arrayOfTopLevelItems.push(node); this._arrayOfAllItems.push(node); this._checkChildNodes(node); } } } }, _checkChildNodes: function(node /*Node*/){ // summary: // Internal function to recurse over all child nodes from the store and add them // As non-toplevel items // description: // Internal function to recurse over all child nodes from the store and add them // As non-toplevel items // // node: // The child node to walk. if(node.firstChild){ for(var i = 0; i < node.childNodes.length; i++){ var child = node.childNodes[i]; if(child.tagName == 'outline'){ this._identityMap[this._identCount] = child; this._identCount++; this._arrayOfAllItems.push(child); this._checkChildNodes(child); } } } }, _getItemsArray: function(/*object?*/queryOptions){ // summary: // Internal function to determine which list of items to search over. // queryOptions: The query options parameter, if any. if(queryOptions && queryOptions.deep) { return this._arrayOfAllItems; } return this._arrayOfTopLevelItems; },/*************************************** dojo.data.api.Read API***************************************/ getValue: function( /* item */ item, /* attribute || attribute-name-string */ attribute, /* value? */ defaultValue){ // summary: // See dojo.data.api.Read.getValue() this._assertIsItem(item); this._assertIsAttribute(attribute); if(attribute == 'children'){ return (item.firstChild || defaultValue); //Object } else { var value = item.getAttribute(attribute); return (value !== undefined) ? value : defaultValue; //Object } }, getValues: function(/* item */ item, /* attribute || attribute-name-string */ attribute){ // summary: // See dojo.data.api.Read.getValues() this._assertIsItem(item); this._assertIsAttribute(attribute); var array = []; if(attribute == 'children'){ for(var i = 0; i < item.childNodes.length; ++i){ array.push(item.childNodes[i]); } } else if(item.getAttribute(attribute) !== null){ array.push(item.getAttribute(attribute)); } return array; // Array }, getAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getAttributes() this._assertIsItem(item); var attributes = []; var xmlNode = item; var xmlAttributes = xmlNode.attributes; for(var i = 0; i < xmlAttributes.length; ++i){ var xmlAttribute = xmlAttributes.item(i); attributes.push(xmlAttribute.nodeName); } if(xmlNode.childNodes.length > 0){ attributes.push('children'); } return attributes; //Array }, hasAttribute: function( /* item */ item, /* attribute || attribute-name-string */ attribute){ // summary: // See dojo.data.api.Read.hasAttribute() return (this.getValues(item, attribute).length > 0); //Boolean }, containsValue: function(/* item */ item, /* attribute || attribute-name-string */ attribute, /* anything */ value){ // summary: // See dojo.data.api.Read.containsValue() var regexp = undefined; if(typeof value === "string"){ regexp = dojo.data.util.filter.patternToRegExp(value, false); } return this._containsValue(item, attribute, value, regexp); //boolean. }, _containsValue: function( /* item */ item, /* attribute || attribute-name-string */ attribute, /* anything */ value, /* RegExp?*/ regexp){ // summary: // Internal function for looking at the values contained by the item. // description: // Internal function for looking at the values contained by the item. This // function allows for denoting if the comparison should be case sensitive for // strings or not (for handling filtering cases where string case should not matter) // // item: // The data item to examine for attribute values. // attribute: // The attribute to inspect. // value: // The value to match. // regexp: // Optional regular expression generated off value if value was of string type to handle wildcarding. // If present and attribute values are string, then it can be used for comparison instead of 'value' var values = this.getValues(item, attribute); for(var i = 0; i < values.length; ++i){ var possibleValue = values[i]; if(typeof possibleValue === "string" && regexp){ return (possibleValue.match(regexp) !== null); }else{ //Non-string matching. if(value === possibleValue){ return true; // Boolean } } } return false; // Boolean }, isItem: function(/* anything */ something){ // summary: // See dojo.data.api.Read.isItem() // description: // Four things are verified to ensure that "something" is an item: // something can not be null, the nodeType must be an XML Element, // the tagName must be "outline", and the node must be a member of // XML document for this datastore. return (something && something.nodeType == 1 &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -