source: [view]
dojo.provide("dojox.data.OpenSearchStore");
dojo.require("dojo.data.util.simpleFetch");
dojo.require("dojox.xml.DomParser");
dojo.require("dojox.xml.parser");
dojo.experimental("dojox.data.OpenSearchStore");
dojo.declare("dojox.data.OpenSearchStore", null, {
constructor: function(/*Object*/args){
// summary:
// Initializer for the OpenSearchStore store.
// description:
// The OpenSearchStore is a Datastore interface to any search
// engine that implements the open search specifications.
if(args){
this.label = args.label;
this.url = args.url;
this.itemPath = args.itemPath;
if("urlPreventCache" in args){
this.urlPreventCache = args.urlPreventCache?true:false;
}
}
var def = dojo.xhrGet({
url: this.url,
handleAs: "xml",
sync: true,
preventCache: this.urlPreventCache
});
def.addCallback(this, "_processOsdd");
def.addErrback(function(){
throw new Error("Unable to load OpenSearch Description document from " . args.url);
});
},
// URL to the open search description document
url: "",
itemPath: "",
_storeRef: "_S",
urlElement: null,
iframeElement: null,
//urlPreventCache: boolean
//Flag denoting if xhrGet calls should use the preventCache option.
urlPreventCache: true,
ATOM_CONTENT_TYPE: 3,
ATOM_CONTENT_TYPE_STRING: "atom",
RSS_CONTENT_TYPE: 2,
RSS_CONTENT_TYPE_STRING: "rss",
XML_CONTENT_TYPE: 1,
XML_CONTENT_TYPE_STRING: "xml",
_assertIsItem: function(/* item */ item){
// summary:
// This function tests whether the item passed in is indeed an item in the store.
// item:
// The item to test for being contained by the store.
if(!this.isItem(item)){
throw new Error("dojox.data.OpenSearchStore: a function was passed an item argument that was not an item");
}
},
_assertIsAttribute: function(/* attribute-name-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(typeof attribute !== "string"){
throw new Error("dojox.data.OpenSearchStore: a function was passed an attribute argument that was not an attribute name string");
}
},
getFeatures: function(){
// summary:
// See dojo.data.api.Read.getFeatures()
return {
'dojo.data.api.Read': true
};
},
getValue: function(item, attribute, defaultValue){
// summary:
// See dojo.data.api.Read.getValue()
var values = this.getValues(item, attribute);
if(values){
return values[0];
}
return defaultValue;
},
getAttributes: function(item){
// summary:
// See dojo.data.api.Read.getAttributes()
return ["content"];
},
hasAttribute: function(item, attribute){
// summary:
// See dojo.data.api.Read.hasAttributes()
if(this.getValue(item,attribute)){
return true;
}
return false;
},
isItemLoaded: function(item){
// summary:
// See dojo.data.api.Read.isItemLoaded()
return this.isItem(item);
},
loadItem: function(keywordArgs){
// summary:
// See dojo.data.api.Read.loadItem()
},
getLabel: function(item){
// summary:
// See dojo.data.api.Read.getLabel()
return undefined;
},
getLabelAttributes: function(item){
// summary:
// See dojo.data.api.Read.getLabelAttributes()
return null;
},
containsValue: function(item, attribute, value){
// summary:
// See dojo.data.api.Read.containsValue()
var values = this.getValues(item,attribute);
for(var i = 0; i < values.length; i++){
if(values[i] === value){
return true;
}
}
return false;
},
getValues: function(item, attribute){
// summary:
// See dojo.data.api.Read.getValue()
this._assertIsItem(item);
this._assertIsAttribute(attribute);
var value = this.processItem(item, attribute);
if(value){
return [value];
}
return undefined;
},
isItem: function(item){
// summary:
// See dojo.data.api.Read.isItem()
if(item && item[this._storeRef] === this){
return true;
}
return false;
},
close: function(request){
// summary:
// See dojo.data.api.Read.close()
},
process: function(data){
// This should return an array of items. This would be the function to override if the
// developer wanted to customize the processing/parsing of the entire batch of search
// results.
return this["_processOSD"+this.contentType](data);
},
processItem: function(item, attribute){
// This returns the text that represents the item. If a developer wanted to customize
// how an individual item is rendered/parsed, they'd override this function.
return this["_processItem"+this.contentType](item.node, attribute);