Kill E4X in locateManager

This commit is contained in:
Simon Kornblith 2013-01-15 04:18:26 -05:00
parent 0c442dc1f6
commit 5ecfb72308

View File

@ -347,50 +347,62 @@ Zotero.LocateManager = new function() {
"http://a9.com/-/spec/opensearchdescription/1.0/" "http://a9.com/-/spec/opensearchdescription/1.0/"
]; ];
var xml = Zotero.Styles.cleanXML(xmlStr); var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
if(OPENSEARCH_NAMESPACES.indexOf(xml.namespace()) === "-1") { .createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(xmlStr, "application/xml"),
docEl = doc.documentElement,
ns = docEl.namespaceURI,
xns = {"s":doc.documentElement.namespaceURI,
"xmlns":"http://www.w3.org/2000/xmlns"};
if(OPENSEARCH_NAMESPACES.indexOf(ns) === -1) {
throw "Invalid namespace"; throw "Invalid namespace";
} }
default xml namespace = xml.namespace();
// get simple attributes // get simple attributes
this.alias = xml.ShortName.toString(); this.alias = Zotero.Utilities.xpathText(docEl, 's:ShortName', xns);
this.name = xml.LongName.toString(); this.name = Zotero.Utilities.xpathText(docEl, 's:LongName', xns);
if(!this.name) this.name = this.alias; if(!this.name) this.name = this.alias;
this.description = xml.Description.toString(); this.description = Zotero.Utilities.xpathText(docEl, 's:Description', xns);
// get the URL template // get the URL template
this._urlTemplate = undefined; this._urlTemplate = undefined;
for each(var urlTag in xml.Url.(@type.toLowerCase() == "text/html")) { var urlTags = Zotero.Utilities.xpath(docEl, 's:Url[@type="text/html"]', xns),
if(urlTag.@rel == undefined || urlTag.@rel == "results") { i = 0;
this._urlTemplate = urlTag.@template.toString(); while(urlTags[i].hasAttribute("rel") && urlTags[i].getAttribute("rel") != "results") {
break; i++;
} if(i == urlTags.length) throw "No Url tag found";
this._method = urlTag.@method.toUpperCase() === "POST" ? "POST" : "GET";
} }
// TODO: better error handling // TODO: better error handling
if(!this._urlTemplate) throw "No URL found for required content type"; var urlTag = urlTags[i];
this._urlTemplate = urlTag.getAttribute("template")
this._method = urlTag.getAttribute("method").toString().toUpperCase() === "POST" ? "POST" : "GET";
// get namespaces // get namespaces
this._urlNamespaces = {}; this._urlNamespaces = {};
for each(var ns in urlTag.inScopeNamespaces()) { var node = urlTag;
this._urlNamespaces[ns.prefix] = ns.uri; while(node && node.attributes) {
for(var i=0; i<node.attributes.length; i++) {
var attr = node.attributes[i];
if(attr.namespaceURI == "http://www.w3.org/2000/xmlns/") {
this._urlNamespaces[attr.localName] = attr.nodeValue;
}
}
node = node.parentNode;
} }
// get params // get params
this._urlParams = []; this._urlParams = [];
for each(var param in urlTag.Param) { for(var param of Zotero.Utilities.xpath(urlTag, 's:Param', xns)) {
this._urlParams[param.@name.toString()] = param.@value.toString(); this._urlParams[param.getAttribute("name")] = param.getAttribute("value");
} }
// find the icon // find the icon
this._iconSourceURI = iconURL; this._iconSourceURI = iconURL;
for each(var img in xml.Image) { for(var img of Zotero.Utilities.xpath(docEl, 's:Image', xns)) {
if((img.@width == undefined && img.@height == undefined) if((!img.hasAttribute("width") && !img.hasAttribute("height"))
|| (img.@width.toString() == "16" && img.@height.toString() == "16")) { || (img.getAttribute("width") == "16" && img.getAttribute("height") == "16")) {
this._iconSourceURI = img.toString(); this._iconSourceURI = img.textContent;
} }
} }