Bug 341842 microsummary service should be stricter about parsing generators, r=myk

This commit is contained in:
jminta%gmail.com 2007-01-14 05:38:16 +00:00
parent be6b9d6928
commit 9e6a88e239

View File

@ -1207,10 +1207,8 @@ MicrosummaryGenerator.prototype = {
// in the microsummaries namespace, regardless of whether or not
// it's the root element. Should it matter?
var generatorNode = xmlDocument.getElementsByTagNameNS(MICSUM_NS, "generator")[0];
// XXX We should throw instead of returning if the file doesn't contain
// a generator.
if (!generatorNode)
return;
throw Components.results.NS_ERROR_FAILURE;
this.name = generatorNode.getAttribute("name");
@ -1223,11 +1221,21 @@ MicrosummaryGenerator.prototype = {
this.localURI; // locally created generator without sourceURI
}
function getFirstChildByTagName(aTagName, aParentNode) {
var nodeList = aParentNode.getElementsByTagNameNS(MICSUM_NS, aTagName);
for (var i = 0; i < nodeList.length; i++) {
// Make sure that the node is a direct descendent of the generator node
if (nodeList[i].parentNode == aParentNode)
return nodeList[i];
}
return null;
}
// Slurp the include/exclude rules that determine the pages to which
// this generator applies. Order is important, so we add the rules
// in the order in which they appear in the XML.
this._rules = [];
var pages = generatorNode.getElementsByTagNameNS(MICSUM_NS, "pages")[0];
var pages = getFirstChildByTagName("pages", generatorNode);
if (pages) {
// XXX Make sure the pages tag exists.
for ( var i = 0; i < pages.childNodes.length ; i++ ) {
@ -1243,7 +1251,7 @@ MicrosummaryGenerator.prototype = {
// allow the generators to set individual update values (even varying
// depending on certain XPath expressions)
var update = generatorNode.getElementsByTagNameNS(MICSUM_NS, "update")[0] || null;
var update = getFirstChildByTagName("update", generatorNode);
if (update) {
function _parseInterval(string) {
// convert from minute fractions to milliseconds
@ -1273,12 +1281,12 @@ MicrosummaryGenerator.prototype = {
}
}
var templateNode = generatorNode.getElementsByTagNameNS(MICSUM_NS, "template")[0];
var templateNode = getFirstChildByTagName("template", generatorNode);
if (templateNode) {
this.template = templateNode.getElementsByTagNameNS(XSLT_NS, "transform")[0]
|| templateNode.getElementsByTagNameNS(XSLT_NS, "stylesheet")[0];
this.template = getFirstChildByTagName("transform", templateNode) ||
getFirstChildByTagName("stylesheet", templateNode);
}
// XXX Make sure the template is a valid XSL transform sheet.
// XXX Make sure the template is a valid XSL transform sheet.
this.loaded = true;
},