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

This commit is contained in:
jminta%gmail.com 2006-07-31 23:20:14 +00:00
Родитель 65c64d57ac
Коммит a8d5d22a90
1 изменённых файлов: 17 добавлений и 9 удалений

Просмотреть файл

@ -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(tagName, parentNode, namespace) {
var nodeList = parentNode.getElementsByTagNameNS(namespace, tagName);
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 == parentNode)
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, MICSUM_NS);
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, MICSUM_NS);
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, MICSUM_NS);
if (templateNode) {
this.template = templateNode.getElementsByTagNameNS(XSLT_NS, "transform")[0]
|| templateNode.getElementsByTagNameNS(XSLT_NS, "stylesheet")[0];
this.template = getFirstChildByTagName("transform", templateNode, XSLT_NS) ||
getFirstChildByTagName("stylesheet", templateNode, XSLT_NS);
}
// 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;
},