diff --git a/toolkit/components/feeds/src/FeedProcessor.js b/toolkit/components/feeds/src/FeedProcessor.js index c34057c270d..530584c142f 100644 --- a/toolkit/components/feeds/src/FeedProcessor.js +++ b/toolkit/components/feeds/src/FeedProcessor.js @@ -55,6 +55,7 @@ var gUnescapeHTML = Cc[UNESCAPE_CONTRACTID]. getService(Ci.nsIScriptableUnescapeHTML); const XMLNS = "http://www.w3.org/XML/1998/namespace"; +const RSS090NS = "http://my.netscape.com/rdf/simple/0.9/"; /***** Some general utils *****/ function strToURI(link, base) { @@ -261,12 +262,15 @@ function W3CToIETFDate(dateString) { // namespace map var gNamespaces = { + "http://backend.userland.com/rss":"", + "http://blogs.law.harvard.edu/tech/rss":"", "http://www.w3.org/2005/Atom":"atom", "http://purl.org/atom/ns#":"atom03", "http://purl.org/rss/1.0/modules/content/":"content", "http://purl.org/dc/elements/1.1/":"dc", "http://www.w3.org/1999/02/22-rdf-syntax-ns#":"rdf", "http://purl.org/rss/1.0/":"rss1", + "http://my.netscape.com/rdf/simple/0.9/":"rss1", "http://wellformedweb.org/CommentAPI/":"wfw", "http://purl.org/rss/1.0/modules/wiki/":"wiki", "http://www.w3.org/XML/1998/namespace":"xml" @@ -417,7 +421,7 @@ Entry.prototype = { id: [["guid", makePropGetter("guid")], "rdf:about", "atom03:id", "atom:id"], summary: ["description", "rss1:description", "dc:description", - "atom03:summary", "atom:summary"], + "atom03:summary", "atom:summary"], content: ["content:encoded","atom03:content","atom:content"] }, @@ -739,8 +743,7 @@ ExtensionHandler.prototype = { }, startElement: function EH_startElement(uri, localName, qName, attrs) { ++this._depth; - var prefix = gNamespaces[uri] ? gNamespaces[uri] + ":" : ""; - var key = prefix + localName; + var key = this._processor._prefixForNS(uri) + localName; if (attrs.length > 0 && !arrayContains(gKnownTextElements, key)) this._isSimple = false; if (this._depth == 1) { @@ -818,7 +821,7 @@ function FeedProcessor() { this._buf = ""; this._feed = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2); this._handlerStack = []; - this._xmlBaseStack = []; + this._xmlBaseStack = []; // sparse array keyed to nesting depth this._depth = 0; this._state = "START"; this._result = null; @@ -1085,8 +1088,7 @@ FeedProcessor.prototype = { // allows Dublin Core "creator" elements to be consistently mapped // to "dc:creator", for easy field access by consumer code. This // strategy also happens to shorten up our state table. - var prefix = gNamespaces[uri] ? gNamespaces[uri] + ":" : ""; - var key = prefix + localName; + var key = this._prefixForNS(uri) + localName; // Check to see if we need to hand this off to our XHTML handler. // The elements we're dealing with will look like this: @@ -1139,6 +1141,13 @@ FeedProcessor.prototype = { } else if (elementInfo.feedVersion) { this._state = "IN_" + elementInfo.fieldName.toUpperCase(); + + // Check for the older RSS2 variants + if (elementInfo.feedVersion == "rss2") + elementInfo.feedVersion = this._findRSSVersion(attributes); + else if (uri == RSS090NS) + elementInfo.feedVersion = "rss090"; + this._docVerified(elementInfo.feedVersion); this._stack.push([this._feed, this._state]); this._mapAttributes(this._feed, attributes); @@ -1154,7 +1163,6 @@ FeedProcessor.prototype = { // the state we're looking for is prefixed with an underscore // to distinguish endElement events from startElement events. endElement: function FP_endElement(uri, localName, qName) { - var prefix = gNamespaces[uri] ? gNamespaces[uri] + ":" : ""; var elementInfo = this._handlerStack[this._depth]; if (elementInfo && !elementInfo.isWrapper) @@ -1300,19 +1308,42 @@ FeedProcessor.prototype = { container.replaceElementAt(element, container.length - 1, false); }, + _prefixForNS: function FP_prefixForNS(uri) { + if (!uri) + return ""; + var prefix = gNamespaces[uri]; + if (prefix) + return prefix + ":"; + if (uri.toLowerCase().indexOf("http://backend.userland.com") == 0) + return ""; + else + return null; + }, _mapAttributes: function FP__mapAttributes(bag, attributes) { // Cycle through the attributes, and set our properties using the // prefix:localNames we find in our namespace dictionary. for (var i = 0; i < attributes.length; ++i) { - prefix = gNamespaces[attributes.getURI(i)] ? - gNamespaces[attributes.getURI(i)] + ":" : ""; - key = prefix + attributes.getLocalName(i); + var key = this._prefixForNS(attributes.getURI(i)) + attributes.getLocalName(i); var val = attributes.getValue(i); bag.setPropertyAsAString(key, val); } }, + // Only for RSS2esque formats + _findRSSVersion: function FP__findRSSVersion(attributes) { + var versionAttr = trimString(attributes.getValueFromName("", "version")); + var versions = { "0.91":"rss091", + "0.92":"rss092", + "0.93":"rss093", + "0.94":"rss094" } + if (versions[versionAttr]) + return versions[versionAttr]; + if (versionAttr.substr(0,2) != "2.") + return "rssUnknown"; + return "rss2"; + }, + // unknown element values are returned here. See startElement above // for how this works. returnFromExtHandler: @@ -1342,8 +1373,7 @@ FeedProcessor.prototype = { } // Make the buffer our new property - var prefix = gNamespaces[uri] ? gNamespaces[uri] + ":" : ""; - var propName = prefix + localName; + var propName = this._prefixForNS(uri) + localName; // But, it could be something containing HTML. If so, // we need to know about that. @@ -1401,12 +1431,12 @@ FeedProcessor.prototype = { var container = top[0]; // Assign the property - var prefix = gNamespaces[uri] ? gNamespaces[uri] + ":" : ""; var newProp = newProp = Cc[TEXTCONSTRUCT_CONTRACTID]. createInstance(Ci.nsIFeedTextConstruct); newProp.text = chars; newProp.type = "xhtml"; - container.setPropertyAsInterface(prefix + localName, newProp); + container.setPropertyAsInterface(this._prefixForNS(uri) + localName, + newProp); // XHTML will cause us to peek too far. The XHTML handler will // send us an end element to call. RFC4287-valid feeds allow a diff --git a/toolkit/components/feeds/test/xml/rss09x/rss090.xml b/toolkit/components/feeds/test/xml/rss09x/rss090.xml new file mode 100644 index 00000000000..783c018f4a6 --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss090.xml @@ -0,0 +1,50 @@ + + + + + + + Mozilla Dot Org + http://www.mozilla.org + the Mozilla Organization web site + + + + Mozilla + http://www.mozilla.org/images/moz.gif + http://www.mozilla.org + + + + New Status Updates + http://www.mozilla.org/status/ + + + + Bugzilla Reorganized + http://www.mozilla.org/bugs/ + + + + Mozilla Party, 2.0! + http://www.mozilla.org/party/1999/ + + + + Unix Platform Parity + http://www.mozilla.org/build/unix.html + + + + NPL 1.0M published + http://www.mozilla.org/NPL/NPL-1.0M.html + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rss091.xml b/toolkit/components/feeds/test/xml/rss09x/rss091.xml new file mode 100644 index 00000000000..6749fc49e3f --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss091.xml @@ -0,0 +1,28 @@ + + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rss091_withNS.xml b/toolkit/components/feeds/test/xml/rss09x/rss091_withNS.xml new file mode 100644 index 00000000000..9ab2c3bf712 --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss091_withNS.xml @@ -0,0 +1,28 @@ + + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rss092.xml b/toolkit/components/feeds/test/xml/rss09x/rss092.xml new file mode 100644 index 00000000000..ed68bd64f87 --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss092.xml @@ -0,0 +1,27 @@ + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rss093.xml b/toolkit/components/feeds/test/xml/rss09x/rss093.xml new file mode 100644 index 00000000000..f1bb81ddf97 --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss093.xml @@ -0,0 +1,27 @@ + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rss094.xml b/toolkit/components/feeds/test/xml/rss09x/rss094.xml new file mode 100644 index 00000000000..1c2b17a24d5 --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rss094.xml @@ -0,0 +1,27 @@ + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file diff --git a/toolkit/components/feeds/test/xml/rss09x/rssUnknown.xml b/toolkit/components/feeds/test/xml/rss09x/rssUnknown.xml new file mode 100644 index 00000000000..653b574d0ce --- /dev/null +++ b/toolkit/components/feeds/test/xml/rss09x/rssUnknown.xml @@ -0,0 +1,27 @@ + + + + + en + + News and commentary from the cross-platform scripting community. + + http://www.scripting.com/ + Scripting News + + http://www.scripting.com/ + Scripting News + http://www.scripting.com/gifs/tinyScriptingNews.gif + + + stuff + http://bar.example.com + This is an article about some stuff + + + \ No newline at end of file