2021-05-03 22:29:18 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2021-05-07 16:45:01 +00:00
|
|
|
/* eslint-disable quote-props */
|
|
|
|
|
2021-05-03 22:29:18 +00:00
|
|
|
function LOG(str) {
|
2021-05-07 13:07:40 +00:00
|
|
|
dump("*** " + str + "\n");
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
const FP_CONTRACTID = "@mozilla.org/feed-processor;1";
|
|
|
|
const FP_CLASSID = Components.ID("{26acb1f0-28fc-43bc-867a-a46aabc85dd4}");
|
|
|
|
const FP_CLASSNAME = "Feed Processor";
|
|
|
|
const FR_CONTRACTID = "@mozilla.org/feed-result;1";
|
|
|
|
const FR_CLASSID = Components.ID("{072a5c3d-30c6-4f07-b87f-9f63d51403f2}");
|
|
|
|
const FR_CLASSNAME = "Feed Result";
|
|
|
|
const FEED_CONTRACTID = "@mozilla.org/feed;1";
|
|
|
|
const FEED_CLASSID = Components.ID("{5d0cfa97-69dd-4e5e-ac84-f253162e8f9a}");
|
|
|
|
const FEED_CLASSNAME = "Feed";
|
|
|
|
const ENTRY_CONTRACTID = "@mozilla.org/feed-entry;1";
|
|
|
|
const ENTRY_CLASSID = Components.ID("{8e4444ff-8e99-4bdd-aa7f-fb3c1c77319f}");
|
|
|
|
const ENTRY_CLASSNAME = "Feed Entry";
|
|
|
|
const TEXTCONSTRUCT_CONTRACTID = "@mozilla.org/feed-textconstruct;1";
|
2021-05-08 16:15:38 +00:00
|
|
|
const TEXTCONSTRUCT_CLASSID
|
|
|
|
= Components.ID("{b992ddcd-3899-4320-9909-924b3e72c922}");
|
2021-05-03 22:29:18 +00:00
|
|
|
const TEXTCONSTRUCT_CLASSNAME = "Feed Text Construct";
|
|
|
|
const GENERATOR_CONTRACTID = "@mozilla.org/feed-generator;1";
|
2021-05-08 16:15:38 +00:00
|
|
|
const GENERATOR_CLASSID
|
|
|
|
= Components.ID("{414af362-9ad8-4296-898e-62247f25a20e}");
|
2021-05-03 22:29:18 +00:00
|
|
|
const GENERATOR_CLASSNAME = "Feed Generator";
|
|
|
|
const PERSON_CONTRACTID = "@mozilla.org/feed-person;1";
|
|
|
|
const PERSON_CLASSID = Components.ID("{95c963b7-20b2-11db-92f6-001422106990}");
|
|
|
|
const PERSON_CLASSNAME = "Feed Person";
|
|
|
|
|
|
|
|
const IO_CONTRACTID = "@mozilla.org/network/io-service;1";
|
|
|
|
const BAG_CONTRACTID = "@mozilla.org/hash-property-bag;1";
|
|
|
|
const ARRAY_CONTRACTID = "@mozilla.org/array;1";
|
|
|
|
const SAX_CONTRACTID = "@mozilla.org/saxparser/xmlreader;1";
|
|
|
|
const PARSERUTILS_CONTRACTID = "@mozilla.org/parserutils;1";
|
|
|
|
|
|
|
|
const gMimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
|
|
|
|
|
|
|
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) {
|
2021-05-07 13:07:40 +00:00
|
|
|
base = base || null;
|
|
|
|
try {
|
|
|
|
return Services.io.newURI(link, null, base);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isArray(a) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return isObject(a) && a.constructor == Array;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isObject(a) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return (a && typeof a == "object") || isFunction(a);
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isFunction(a) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return typeof a == "function";
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isIID(a, iid) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var rv = false;
|
|
|
|
try {
|
|
|
|
a.QueryInterface(iid);
|
|
|
|
rv = true;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
return rv;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isIArray(a) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return isIID(a, Ci.nsIArray);
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isIFeedContainer(a) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return isIID(a, Ci.nsIFeedContainer);
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stripTags(someHTML) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return someHTML.replace(/<[^>]+>/g, "");
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches through an array of links and returns a JS array
|
|
|
|
* of matching property bags.
|
|
|
|
*/
|
|
|
|
const IANA_URI = "http://www.iana.org/assignments/relation/";
|
|
|
|
function findAtomLinks(rel, links) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var rvLinks = [];
|
|
|
|
for (var i = 0; i < links.length; ++i) {
|
|
|
|
var linkElement = links.queryElementAt(i, Ci.nsIPropertyBag2);
|
|
|
|
// atom:link MUST have @href
|
|
|
|
if (bagHasKey(linkElement, "href")) {
|
|
|
|
var relAttribute = null;
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(linkElement, "rel")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
relAttribute = linkElement.getPropertyAsAString("rel");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
if ((!relAttribute && rel == "alternate") || relAttribute == rel) {
|
|
|
|
rvLinks.push(linkElement);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// catch relations specified by IANA URI
|
|
|
|
if (relAttribute == IANA_URI + rel) {
|
|
|
|
rvLinks.push(linkElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rvLinks;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function xmlEscape(s) {
|
2021-05-07 13:07:40 +00:00
|
|
|
s = s.replace(/&/g, "&");
|
|
|
|
s = s.replace(/>/g, ">");
|
|
|
|
s = s.replace(/</g, "<");
|
|
|
|
s = s.replace(/"/g, """);
|
|
|
|
s = s.replace(/'/g, "'");
|
|
|
|
return s;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function arrayContains(array, element) {
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var i = 0; i < array.length; ++i) {
|
|
|
|
if (array[i] == element) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX add hasKey to nsIPropertyBag
|
|
|
|
function bagHasKey(bag, key) {
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
|
|
|
bag.getProperty(key);
|
|
|
|
return true;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function makePropGetter(key) {
|
2021-05-08 16:15:38 +00:00
|
|
|
return function (bag) {
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
|
|
|
return bag.getProperty(key);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
|
|
// namespace map
|
|
|
|
var gNamespaces = {
|
2021-05-07 13:07:40 +00:00
|
|
|
"http://webns.net/mvcb/": "admin",
|
|
|
|
"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://purl.org/dc/terms/": "dcterms",
|
|
|
|
"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",
|
|
|
|
"http://search.yahoo.com/mrss/": "media",
|
|
|
|
"http://search.yahoo.com/mrss": "media",
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// We allow a very small set of namespaces in XHTML content,
|
|
|
|
// for attributes only
|
|
|
|
var gAllowedXHTMLNamespaces = {
|
2021-05-07 13:07:40 +00:00
|
|
|
"http://www.w3.org/XML/1998/namespace": "xml",
|
|
|
|
// if someone ns qualifies XHTML, we have to prefix it to avoid an
|
|
|
|
// attribute collision.
|
|
|
|
"http://www.w3.org/1999/xhtml": "xhtml",
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function FeedResult() {}
|
|
|
|
FeedResult.prototype = {
|
2021-05-07 13:07:40 +00:00
|
|
|
bozo: false,
|
|
|
|
doc: null,
|
|
|
|
version: null,
|
|
|
|
headers: null,
|
|
|
|
uri: null,
|
|
|
|
stylesheet: null,
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
registerExtensionPrefix: function (ns, prefix) {
|
2021-05-07 13:07:40 +00:00
|
|
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: FR_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIFeedResult]),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function Feed() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.subtitle = null;
|
|
|
|
this.title = null;
|
|
|
|
this.items = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
|
|
|
this.link = null;
|
|
|
|
this.id = null;
|
|
|
|
this.generator = null;
|
|
|
|
this.authors = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
|
|
|
this.contributors = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
|
|
|
this.baseURI = null;
|
|
|
|
this.enclosureCount = 0;
|
|
|
|
this.type = Ci.nsIFeed.TYPE_FEED;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Feed.prototype = {
|
2021-05-07 13:07:40 +00:00
|
|
|
searchLists: {
|
|
|
|
title: ["title", "rss1:title", "atom03:title", "atom:title"],
|
2021-05-07 16:45:01 +00:00
|
|
|
subtitle: [
|
|
|
|
"description",
|
|
|
|
"dc:description",
|
|
|
|
"rss1:description",
|
|
|
|
"atom03:tagline",
|
|
|
|
"atom:subtitle",
|
|
|
|
],
|
2021-05-07 13:07:40 +00:00
|
|
|
items: ["items", "atom03_entries", "entries"],
|
|
|
|
id: ["atom:id", "rdf:about"],
|
|
|
|
generator: ["generator"],
|
|
|
|
authors: ["authors"],
|
|
|
|
contributors: ["contributors"],
|
2021-05-08 16:15:38 +00:00
|
|
|
link: [["link", strToURI], ["rss1:link", strToURI]],
|
2021-05-07 13:07:40 +00:00
|
|
|
categories: ["categories", "dc:subject"],
|
|
|
|
rights: ["atom03:rights", "atom:rights"],
|
|
|
|
cloud: ["cloud"],
|
|
|
|
image: ["image", "rss1:image", "atom:logo"],
|
|
|
|
textInput: ["textInput", "rss1:textinput"],
|
|
|
|
skipDays: ["skipDays"],
|
|
|
|
skipHours: ["skipHours"],
|
2021-05-07 16:45:01 +00:00
|
|
|
updated: [
|
|
|
|
"pubDate",
|
|
|
|
"lastBuildDate",
|
|
|
|
"atom03:modified",
|
|
|
|
"dc:date",
|
|
|
|
"dcterms:modified",
|
|
|
|
"atom:updated",
|
|
|
|
],
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
normalize: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
fieldsToObj(this, this.searchLists);
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this.skipDays) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.skipDays = this.skipDays.getProperty("days");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
if (this.skipHours) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.skipHours = this.skipHours.getProperty("hours");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this.updated) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.updated = dateParse(this.updated);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Assign Atom link if needed
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "links")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._atomLinksToURI();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this._calcEnclosureCountAndFeedType();
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Resolve relative image links
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this.image && bagHasKey(this.image, "url")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._resolveImageLink();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
this._resetBagMembersToRawText([this.searchLists.subtitle, this.searchLists.title]);
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_calcEnclosureCountAndFeedType: function () {
|
2021-05-08 16:24:04 +00:00
|
|
|
var entriesWithEnclosures = 0;
|
|
|
|
var audioCount = 0;
|
|
|
|
var imageCount = 0;
|
|
|
|
var videoCount = 0;
|
|
|
|
var otherCount = 0;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var i = 0; i < this.items.length; ++i) {
|
|
|
|
var entry = this.items.queryElementAt(i, Ci.nsIFeedEntry);
|
|
|
|
entry.QueryInterface(Ci.nsIFeedContainer);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
if (entry.enclosures && entry.enclosures.length > 0) {
|
2021-05-08 16:24:04 +00:00
|
|
|
++entriesWithEnclosures;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var e = 0; e < entry.enclosures.length; ++e) {
|
|
|
|
var enc = entry.enclosures.queryElementAt(e, Ci.nsIWritablePropertyBag2);
|
|
|
|
if (enc.hasKey("type")) {
|
|
|
|
var enctype = enc.get("type");
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
if (/^audio/.test(enctype)) {
|
2021-05-08 16:24:04 +00:00
|
|
|
++audioCount;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (/^image/.test(enctype)) {
|
2021-05-08 16:24:04 +00:00
|
|
|
++imageCount;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (/^video/.test(enctype)) {
|
2021-05-08 16:24:04 +00:00
|
|
|
++videoCount;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-08 16:24:04 +00:00
|
|
|
++otherCount;
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-08 16:24:04 +00:00
|
|
|
++otherCount;
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
var feedtype = Ci.nsIFeed.TYPE_FEED;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// For a feed to be marked as TYPE_VIDEO, TYPE_AUDIO and TYPE_IMAGE,
|
|
|
|
// we enforce two things:
|
|
|
|
//
|
|
|
|
// 1. all entries must have at least one enclosure
|
|
|
|
// 2. all enclosures must be video for TYPE_VIDEO, audio for TYPE_AUDIO or image
|
|
|
|
// for TYPE_IMAGE
|
|
|
|
//
|
|
|
|
// Otherwise it's a TYPE_FEED.
|
2021-05-08 16:24:04 +00:00
|
|
|
if (entriesWithEnclosures == this.items.length && otherCount == 0) {
|
|
|
|
if (audioCount > 0 && !videoCount && !imageCount) {
|
2021-05-07 13:07:40 +00:00
|
|
|
feedtype = Ci.nsIFeed.TYPE_AUDIO;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-08 16:24:04 +00:00
|
|
|
else if (imageCount > 0 && !audioCount && !videoCount) {
|
2021-05-07 13:07:40 +00:00
|
|
|
feedtype = Ci.nsIFeed.TYPE_IMAGE;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-08 16:24:04 +00:00
|
|
|
else if (videoCount > 0 && !audioCount && !imageCount) {
|
2021-05-07 13:07:40 +00:00
|
|
|
feedtype = Ci.nsIFeed.TYPE_VIDEO;
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this.type = feedtype;
|
2021-05-08 16:24:04 +00:00
|
|
|
this.enclosureCount = otherCount + videoCount + audioCount + imageCount;
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_atomLinksToURI: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
var links = this.fields.getPropertyAsInterface("links", Ci.nsIArray);
|
|
|
|
var alternates = findAtomLinks("alternate", links);
|
|
|
|
if (alternates.length > 0) {
|
|
|
|
var href = alternates[0].getPropertyAsAString("href");
|
|
|
|
var base;
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(alternates[0], "xml:base")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
base = alternates[0].getPropertyAsAString("xml:base");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
this.link = this._resolveURI(href, base);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_resolveImageLink: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
var base;
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.image, "xml:base")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
base = this.image.getPropertyAsAString("xml:base");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
var url = this._resolveURI(this.image.getPropertyAsAString("url"), base);
|
2021-05-08 16:15:38 +00:00
|
|
|
if (url) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.image.setPropertyAsAString("url", url.spec);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_resolveURI: function (linkSpec, baseSpec) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var uri = null;
|
|
|
|
try {
|
|
|
|
var base = baseSpec ? strToURI(baseSpec, this.baseURI) : this.baseURI;
|
|
|
|
uri = strToURI(linkSpec, base);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
LOG(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// reset the bag to raw contents, not text constructs
|
2021-05-08 16:15:38 +00:00
|
|
|
_resetBagMembersToRawText: function (fieldLists) {
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var i = 0; i < fieldLists.length; i++) {
|
|
|
|
for (var j = 0; j < fieldLists[i].length; j++) {
|
|
|
|
if (bagHasKey(this.fields, fieldLists[i][j])) {
|
|
|
|
var textConstruct = this.fields.getProperty(fieldLists[i][j]);
|
2021-05-08 16:15:38 +00:00
|
|
|
this.fields.setPropertyAsAString(fieldLists[i][j], textConstruct.text);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: FEED_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIFeed, Ci.nsIFeedContainer]),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function Entry() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.summary = null;
|
|
|
|
this.content = null;
|
|
|
|
this.title = null;
|
2021-05-08 16:15:38 +00:00
|
|
|
this.fields = Cc["@mozilla.org/hash-property-bag;1"].createInstance(Ci.nsIWritablePropertyBag2);
|
2021-05-07 13:07:40 +00:00
|
|
|
this.link = null;
|
|
|
|
this.id = null;
|
|
|
|
this.baseURI = null;
|
|
|
|
this.updated = null;
|
|
|
|
this.published = null;
|
|
|
|
this.authors = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
|
|
|
this.contributors = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Entry.prototype = {
|
2021-05-07 13:07:40 +00:00
|
|
|
fields: null,
|
|
|
|
enclosures: null,
|
|
|
|
mediaContent: null,
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
searchLists: {
|
|
|
|
title: ["title", "rss1:title", "atom03:title", "atom:title"],
|
|
|
|
link: [["link", strToURI], ["rss1:link", strToURI]],
|
2021-05-07 16:45:01 +00:00
|
|
|
id: [
|
|
|
|
["guid", makePropGetter("guid")],
|
|
|
|
"rdf:about",
|
|
|
|
"atom03:id",
|
|
|
|
"atom:id",
|
|
|
|
],
|
2021-05-07 13:07:40 +00:00
|
|
|
authors: ["authors"],
|
|
|
|
contributors: ["contributors"],
|
2021-05-07 16:45:01 +00:00
|
|
|
summary: [
|
|
|
|
"description",
|
|
|
|
"rss1:description",
|
|
|
|
"dc:description",
|
|
|
|
"atom03:summary",
|
|
|
|
"atom:summary",
|
|
|
|
],
|
2021-05-07 13:07:40 +00:00
|
|
|
content: ["content:encoded", "atom03:content", "atom:content"],
|
|
|
|
rights: ["atom03:rights", "atom:rights"],
|
|
|
|
published: ["pubDate", "atom03:issued", "dcterms:issued", "atom:published"],
|
2021-05-07 16:45:01 +00:00
|
|
|
updated: [
|
|
|
|
"pubDate",
|
|
|
|
"atom03:modified",
|
|
|
|
"dc:date",
|
|
|
|
"dcterms:modified",
|
|
|
|
"atom:updated",
|
|
|
|
],
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
normalize: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
fieldsToObj(this, this.searchLists);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Assign Atom link if needed
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "links")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._atomLinksToURI();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Populate enclosures array
|
|
|
|
this._populateEnclosures();
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// The link might be a guid w/ permalink=true
|
|
|
|
if (!this.link && bagHasKey(this.fields, "guid")) {
|
|
|
|
var guid = this.fields.getProperty("guid");
|
|
|
|
var isPermaLink = true;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(guid, "isPermaLink")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
isPermaLink = guid.getProperty("isPermaLink").toLowerCase() != "false";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
if (guid && isPermaLink) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.link = strToURI(guid.getProperty("guid"));
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this.updated) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.updated = dateParse(this.updated);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
if (this.published) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.published = dateParse(this.published);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
this._resetBagMembersToRawText([
|
|
|
|
this.searchLists.content,
|
|
|
|
this.searchLists.summary,
|
|
|
|
this.searchLists.title,
|
|
|
|
]);
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_populateEnclosures: function () {
|
|
|
|
if (bagHasKey(this.fields, "links")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._atomLinksToEnclosures();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Add RSS2 enclosure to enclosures
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "enclosure")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._enclosureToEnclosures();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Add media:content to enclosures
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "mediacontent")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._mediaToEnclosures("mediacontent");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Add media:thumbnail to enclosures
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "mediathumbnail")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._mediaToEnclosures("mediathumbnail");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Add media:content in media:group to enclosures
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(this.fields, "mediagroup")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._mediaToEnclosures("mediagroup", "mediacontent");
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
__enclosureMap: null,
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
_addToEnclosures: function (newEnc) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// items we add to the enclosures array get displayed in the FeedWriter and
|
|
|
|
// they must have non-empty urls.
|
2021-05-08 16:24:04 +00:00
|
|
|
if (!bagHasKey(newEnc, "url") || newEnc.getPropertyAsAString("url") == "") {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
if (this.__enclosureMap === null) {
|
|
|
|
this.__enclosureMap = {};
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
var previousEnc = this.__enclosureMap[newEnc.getPropertyAsAString("url")];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
if (previousEnc != undefined) {
|
|
|
|
previousEnc.QueryInterface(Ci.nsIWritablePropertyBag2);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
if (!bagHasKey(previousEnc, "type") && bagHasKey(newEnc, "type")) {
|
|
|
|
previousEnc.setPropertyAsAString("type", newEnc.getPropertyAsAString("type"));
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
2021-05-08 16:24:04 +00:00
|
|
|
let handlerInfoWrapper = gMimeService.getFromTypeAndExtension(newEnc.getPropertyAsAString("type"), null);
|
2021-05-07 13:07:40 +00:00
|
|
|
if (handlerInfoWrapper && handlerInfoWrapper.description) {
|
2021-05-08 16:24:04 +00:00
|
|
|
previousEnc.setPropertyAsAString("typeDesc", handlerInfoWrapper.description);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (ext) {}
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
if (!bagHasKey(previousEnc, "length") && bagHasKey(newEnc, "length")) {
|
|
|
|
previousEnc.setPropertyAsAString("length", newEnc.getPropertyAsAString("length"));
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
if (this.enclosures === null) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.enclosures = Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray);
|
|
|
|
this.enclosures.QueryInterface(Ci.nsIMutableArray);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
this.enclosures.appendElement(newEnc);
|
|
|
|
this.__enclosureMap[newEnc.getPropertyAsAString("url")] = newEnc;
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_atomLinksToEnclosures: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
var links = this.fields.getPropertyAsInterface("links", Ci.nsIArray);
|
2021-05-08 16:24:04 +00:00
|
|
|
var encLinks = findAtomLinks("enclosure", links);
|
|
|
|
if (encLinks.length == 0) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:24:04 +00:00
|
|
|
for (var i = 0; i < encLinks.length; ++i) {
|
|
|
|
var link = encLinks[i];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// an enclosure must have an href
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!(link.getProperty("href"))) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
var enc = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// copy Atom bits over to equivalent enclosure bits
|
|
|
|
enc.setPropertyAsAString("url", link.getPropertyAsAString("href"));
|
2021-05-08 16:15:38 +00:00
|
|
|
if (bagHasKey(link, "type")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
enc.setPropertyAsAString("type", link.getPropertyAsAString("type"));
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
if (bagHasKey(link, "length")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
enc.setPropertyAsAString("length", link.getPropertyAsAString("length"));
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this._addToEnclosures(enc);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_enclosureToEnclosures: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
var enc = this.fields.getPropertyAsInterface("enclosure", Ci.nsIPropertyBag2);
|
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!(enc.getProperty("url"))) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
|
|
|
|
this._addToEnclosures(enc);
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_mediaToEnclosures: function (mediaType, contentType) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var content;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If a contentType is specified, the mediaType is a simple propertybag,
|
|
|
|
// and the contentType is an array inside it.
|
|
|
|
if (contentType) {
|
|
|
|
var group = this.fields.getPropertyAsInterface(mediaType, Ci.nsIPropertyBag2);
|
|
|
|
content = group.getPropertyAsInterface(contentType, Ci.nsIArray);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
content = this.fields.getPropertyAsInterface(mediaType, Ci.nsIArray);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var i = 0; i < content.length; ++i) {
|
|
|
|
var contentElement = content.queryElementAt(i, Ci.nsIWritablePropertyBag2);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// media:content don't require url, but if it's not there, we should
|
|
|
|
// skip it.
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!bagHasKey(contentElement, "url")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
continue;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
var enc = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// copy media:content bits over to equivalent enclosure bits
|
|
|
|
enc.setPropertyAsAString("url", contentElement.getPropertyAsAString("url"));
|
|
|
|
if (bagHasKey(contentElement, "type")) {
|
|
|
|
enc.setPropertyAsAString("type", contentElement.getPropertyAsAString("type"));
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (mediaType == "mediathumbnail") {
|
2021-05-07 13:07:40 +00:00
|
|
|
// thumbnails won't have a type, but default to image types
|
|
|
|
enc.setPropertyAsAString("type", "image/*");
|
|
|
|
enc.setPropertyAsBool("thumbnail", true);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
if (bagHasKey(contentElement, "fileSize")) {
|
|
|
|
enc.setPropertyAsAString("length", contentElement.getPropertyAsAString("fileSize"));
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this._addToEnclosures(enc);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: ENTRY_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI(
|
|
|
|
[Ci.nsIFeedEntry, Ci.nsIFeedContainer]
|
|
|
|
),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Entry.prototype._atomLinksToURI = Feed.prototype._atomLinksToURI;
|
|
|
|
Entry.prototype._resolveURI = Feed.prototype._resolveURI;
|
2021-05-08 16:15:38 +00:00
|
|
|
Entry.prototype._resetBagMembersToRawText = Feed.prototype._resetBagMembersToRawText;
|
2021-05-03 22:29:18 +00:00
|
|
|
|
|
|
|
// TextConstruct represents and element that could contain (X)HTML
|
|
|
|
function TextConstruct() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.lang = null;
|
|
|
|
this.base = null;
|
|
|
|
this.type = "text";
|
|
|
|
this.text = null;
|
|
|
|
this.parserUtils = Cc[PARSERUTILS_CONTRACTID].getService(Ci.nsIParserUtils);
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextConstruct.prototype = {
|
2021-05-08 16:15:38 +00:00
|
|
|
plainText: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
if (this.type != "text") {
|
|
|
|
return this.parserUtils.convertToPlainText(stripTags(this.text),
|
2021-05-08 16:15:38 +00:00
|
|
|
Ci.nsIDocumentEncoder.OutputSelectionOnly
|
|
|
|
| Ci.nsIDocumentEncoder.OutputAbsoluteLinks,
|
2021-05-07 13:07:40 +00:00
|
|
|
0);
|
|
|
|
}
|
|
|
|
return this.text;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
createDocumentFragment: function (element) {
|
2021-05-07 13:07:40 +00:00
|
|
|
if (this.type == "text") {
|
|
|
|
var doc = element.ownerDocument;
|
|
|
|
var docFragment = doc.createDocumentFragment();
|
|
|
|
var node = doc.createTextNode(this.text);
|
|
|
|
docFragment.appendChild(node);
|
|
|
|
return docFragment;
|
|
|
|
}
|
|
|
|
var isXML;
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this.type == "xhtml") {
|
2021-05-07 13:07:40 +00:00
|
|
|
isXML = true;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (this.type == "html") {
|
2021-05-07 13:07:40 +00:00
|
|
|
isXML = false;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
return null;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
let flags = Ci.nsIParserUtils.SanitizerDropForms;
|
|
|
|
return this.parserUtils.parseFragment(this.text, flags, isXML,
|
2021-05-08 16:15:38 +00:00
|
|
|
this.base, element);
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: TEXTCONSTRUCT_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIFeedTextConstruct]),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Generator represents the software that produced the feed
|
|
|
|
function Generator() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.lang = null;
|
|
|
|
this.agent = null;
|
|
|
|
this.version = null;
|
|
|
|
this.uri = null;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// nsIFeedElementBase
|
|
|
|
this._attributes = null;
|
|
|
|
this.baseURI = null;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Generator.prototype = {
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
get attributes() {
|
|
|
|
return this._attributes;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
set attributes(value) {
|
|
|
|
this._attributes = value;
|
|
|
|
this.version = this._attributes.getValueFromName("", "version");
|
2021-05-07 16:45:01 +00:00
|
|
|
var uriAttribute = this._attributes.getValueFromName("", "uri")
|
|
|
|
|| this._attributes.getValueFromName("", "url");
|
2021-05-07 13:07:40 +00:00
|
|
|
this.uri = strToURI(uriAttribute, this.baseURI);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// RSS1
|
|
|
|
uriAttribute = this._attributes.getValueFromName(RDF_NS, "resource");
|
|
|
|
if (uriAttribute) {
|
|
|
|
this.agent = uriAttribute;
|
|
|
|
this.uri = strToURI(uriAttribute, this.baseURI);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: GENERATOR_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI(
|
|
|
|
[Ci.nsIFeedGenerator, Ci.nsIFeedElementBase]
|
|
|
|
),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function Person() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.name = null;
|
|
|
|
this.uri = null;
|
|
|
|
this.email = null;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// nsIFeedElementBase
|
|
|
|
this.attributes = null;
|
|
|
|
this.baseURI = null;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Person.prototype = {
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: PERSON_CLASSID,
|
|
|
|
QueryInterface: ChromeUtils.generateQI(
|
|
|
|
[Ci.nsIFeedPerson, Ci.nsIFeedElementBase]
|
|
|
|
),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map a list of fields into properties on a container.
|
|
|
|
*
|
|
|
|
* @param container An nsIFeedContainer
|
|
|
|
* @param fields A list of fields to search for. List members can
|
|
|
|
* be a list, in which case the second member is
|
|
|
|
* transformation function (like parseInt).
|
|
|
|
*/
|
|
|
|
function fieldsToObj(container, fields) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var props, prop, field, searchList;
|
|
|
|
for (var key in fields) {
|
|
|
|
searchList = fields[key];
|
|
|
|
for (var i = 0; i < searchList.length; ++i) {
|
|
|
|
props = searchList[i];
|
|
|
|
prop = null;
|
|
|
|
field = isArray(props) ? props[0] : props;
|
|
|
|
try {
|
|
|
|
prop = container.fields.getProperty(field);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
if (prop) {
|
|
|
|
prop = isArray(props) ? props[1](prop) : prop;
|
|
|
|
container[key] = prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lower cases an element's localName property
|
|
|
|
* @param element A DOM element.
|
|
|
|
*
|
|
|
|
* @returns The lower case localName property of the specified element
|
|
|
|
*/
|
|
|
|
function LC(element) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return element.localName.toLowerCase();
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO move these post-processor functions
|
|
|
|
// create a generator element
|
|
|
|
function atomGenerator(s, generator) {
|
2021-05-07 13:07:40 +00:00
|
|
|
generator.QueryInterface(Ci.nsIFeedGenerator);
|
|
|
|
generator.agent = s.trim();
|
|
|
|
return generator;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// post-process atom:logo to create an RSS2-like structure
|
|
|
|
function atomLogo(s, logo) {
|
2021-05-07 13:07:40 +00:00
|
|
|
logo.setPropertyAsAString("url", s.trim());
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// post-process an RSS category, map it to the Atom fields.
|
|
|
|
function rssCatTerm(s, cat) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// add slash handling?
|
|
|
|
cat.setPropertyAsAString("term", s.trim());
|
|
|
|
return cat;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// post-process a GUID
|
|
|
|
function rssGuid(s, guid) {
|
2021-05-07 13:07:40 +00:00
|
|
|
guid.setPropertyAsAString("guid", s.trim());
|
|
|
|
return guid;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// post-process an RSS author element
|
|
|
|
//
|
|
|
|
// It can contain a field like this:
|
|
|
|
//
|
|
|
|
// <author>lawyer@boyer.net (Lawyer Boyer)</author>
|
|
|
|
//
|
|
|
|
// or, delightfully, a field like this:
|
|
|
|
//
|
|
|
|
// <dc:creator>Simon St.Laurent (mailto:simonstl@simonstl.com)</dc:creator>
|
|
|
|
//
|
|
|
|
// We want to split this up and assign it to corresponding Atom
|
|
|
|
// fields.
|
|
|
|
//
|
|
|
|
function rssAuthor(s, author) {
|
2021-05-07 13:07:40 +00:00
|
|
|
author.QueryInterface(Ci.nsIFeedPerson);
|
|
|
|
// check for RSS2 string format
|
|
|
|
var chars = s.trim();
|
|
|
|
var matches = chars.match(/(.*)\((.*)\)/);
|
2021-05-08 16:15:38 +00:00
|
|
|
var emailCheck
|
2021-05-08 16:24:04 +00:00
|
|
|
= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
2021-05-07 13:07:40 +00:00
|
|
|
if (matches) {
|
|
|
|
var match1 = matches[1].trim();
|
|
|
|
var match2 = matches[2].trim();
|
2021-05-08 16:15:38 +00:00
|
|
|
if (match2.indexOf("mailto:") == 0) {
|
2021-05-07 13:07:40 +00:00
|
|
|
match2 = match2.substring(7);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
if (emailCheck.test(match1)) {
|
|
|
|
author.email = match1;
|
|
|
|
author.name = match2;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (emailCheck.test(match2)) {
|
2021-05-07 13:07:40 +00:00
|
|
|
author.email = match2;
|
|
|
|
author.name = match1;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
// put it back together
|
|
|
|
author.name = match1 + " (" + match2 + ")";
|
|
|
|
}
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
author.name = chars;
|
2021-05-08 16:15:38 +00:00
|
|
|
if (chars.indexOf("@")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
author.email = chars;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
return author;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// skipHours and skipDays map to arrays, so we need to change the
|
|
|
|
// string to an nsISupports in order to stick it in there.
|
|
|
|
//
|
|
|
|
function rssArrayElement(s) {
|
2021-05-08 16:15:38 +00:00
|
|
|
var str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
2021-05-07 13:07:40 +00:00
|
|
|
str.data = s;
|
|
|
|
str.QueryInterface(Ci.nsISupportsString);
|
|
|
|
return str;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries parsing a string through the JavaScript Date object.
|
|
|
|
* @param aDateString
|
|
|
|
* A string that is supposedly an RFC822 or RFC3339 date.
|
|
|
|
* @return A Date.toUTCString, or null if the string can't be parsed.
|
|
|
|
*/
|
|
|
|
function dateParse(aDateString) {
|
2021-05-07 13:07:40 +00:00
|
|
|
let dateString = aDateString.trim();
|
|
|
|
// Without bug 682781 fixed, JS won't parse an RFC822 date with a Z for the
|
|
|
|
// timezone, so convert to -00:00 which works for any date format.
|
|
|
|
dateString = dateString.replace(/z$/i, "-00:00");
|
|
|
|
let date = new Date(dateString);
|
|
|
|
if (!isNaN(date)) {
|
|
|
|
return date.toUTCString();
|
|
|
|
}
|
|
|
|
return null;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
|
|
|
|
// The XHTMLHandler handles inline XHTML found in things like atom:summary
|
|
|
|
function XHTMLHandler(processor, isAtom) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf = "";
|
|
|
|
this._processor = processor;
|
|
|
|
this._depth = 0;
|
|
|
|
this._isAtom = isAtom;
|
|
|
|
// a stack of lists tracking in-scope namespaces
|
|
|
|
this._inScopeNS = [];
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The fidelity can be improved here, to allow handling of stuff like
|
|
|
|
// SVG and MathML. XXX
|
|
|
|
XHTMLHandler.prototype = {
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
// look back up at the declared namespaces
|
|
|
|
// we always use the same prefixes for our safe stuff
|
|
|
|
_isInScope: function (ns) {
|
2021-05-07 13:07:40 +00:00
|
|
|
for (var i in this._inScopeNS) {
|
|
|
|
for (var uri in this._inScopeNS[i]) {
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._inScopeNS[i][uri] == ns) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return true;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
startDocument: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
endDocument: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
startElement: function (namespace, localName, qName, attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
++this._depth;
|
|
|
|
this._inScopeNS.push([]);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// RFC4287 requires XHTML to be wrapped in a div that is *not* part of
|
|
|
|
// the content. This prevents people from screwing up namespaces, but
|
|
|
|
// we need to skip it here.
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._isAtom && this._depth == 1 && localName == "div") {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If it's an XHTML element, record it. Otherwise, it's ignored.
|
|
|
|
if (namespace == XHTML_NS) {
|
|
|
|
this._buf += "<" + localName;
|
|
|
|
var uri;
|
|
|
|
for (var i = 0; i < attributes.length; ++i) {
|
|
|
|
uri = attributes.getURI(i);
|
|
|
|
// XHTML attributes aren't in a namespace
|
|
|
|
if (uri == "") {
|
2021-05-08 16:15:38 +00:00
|
|
|
this._buf += (" " + attributes.getLocalName(i) + "='"
|
|
|
|
+ xmlEscape(attributes.getValue(i)) + "'");
|
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
// write a small set of allowed attribute namespaces
|
|
|
|
var prefix = gAllowedXHTMLNamespaces[uri];
|
2021-05-08 16:24:04 +00:00
|
|
|
if (prefix) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// The attribute value we'll attempt to write
|
|
|
|
var attributeValue = xmlEscape(attributes.getValue(i));
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// it's an allowed attribute NS.
|
|
|
|
// write the attribute
|
2021-05-08 16:15:38 +00:00
|
|
|
this._buf += (" " + prefix + ":"
|
|
|
|
+ attributes.getLocalName(i)
|
|
|
|
+ "='" + attributeValue + "'");
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// write an xmlns declaration if necessary
|
|
|
|
if (prefix != "xml" && !this._isInScope(uri)) {
|
|
|
|
this._inScopeNS[this._inScopeNS.length - 1].push(uri);
|
|
|
|
this._buf += " xmlns:" + prefix + "='" + uri + "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._buf += ">";
|
|
|
|
}
|
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
endElement: function (uri, localName, qName) {
|
2021-05-07 13:07:40 +00:00
|
|
|
--this._depth;
|
|
|
|
this._inScopeNS.pop();
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// We need to skip outer divs in Atom. See comment in startElement.
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._isAtom && this._depth == 0 && localName == "div") {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// When we peek too far, go back to the main processor
|
|
|
|
if (this._depth < 0) {
|
2021-05-08 16:15:38 +00:00
|
|
|
this._processor.returnFromXHTMLHandler(this._buf.trim(), uri, localName, qName);
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If it's an XHTML element, record it. Otherwise, it's ignored.
|
|
|
|
if (uri == XHTML_NS) {
|
|
|
|
this._buf += "</" + localName + ">";
|
|
|
|
}
|
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
characters: function (data) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf += xmlEscape(data);
|
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
processingInstruction: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ExtensionHandler deals with elements we haven't explicitly
|
|
|
|
* added to our transition table in the FeedProcessor.
|
|
|
|
*/
|
|
|
|
function ExtensionHandler(processor) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf = "";
|
|
|
|
this._depth = 0;
|
|
|
|
this._hasChildElements = false;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// The FeedProcessor
|
|
|
|
this._processor = processor;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Fields of the outermost extension element.
|
|
|
|
this._localName = null;
|
|
|
|
this._uri = null;
|
|
|
|
this._qName = null;
|
|
|
|
this._attrs = null;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionHandler.prototype = {
|
2021-05-08 16:15:38 +00:00
|
|
|
startDocument: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
endDocument: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
startElement: function (uri, localName, qName, attrs) {
|
2021-05-07 13:07:40 +00:00
|
|
|
++this._depth;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
if (this._depth == 1) {
|
|
|
|
this._uri = uri;
|
|
|
|
this._localName = localName;
|
|
|
|
this._qName = qName;
|
|
|
|
this._attrs = attrs;
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// if we descend into another element, we won't send text
|
|
|
|
this._hasChildElements = (this._depth > 1);
|
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
endElement: function (uri, localName, qName) {
|
2021-05-07 13:07:40 +00:00
|
|
|
--this._depth;
|
|
|
|
if (this._depth == 0) {
|
|
|
|
var text = this._hasChildElements ? null : this._buf.trim();
|
2021-05-08 16:15:38 +00:00
|
|
|
this._processor.returnFromExtHandler(this._uri, this._localName, text, this._attrs);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
characters: function (data) {
|
|
|
|
if (!this._hasChildElements) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf += data;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-08 16:15:38 +00:00
|
|
|
processingInstruction: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ElementInfo is a simple container object that describes
|
|
|
|
* some characteristics of a feed element. For example, it
|
|
|
|
* says whether an element can be expected to appear more
|
|
|
|
* than once inside a given entry or feed.
|
|
|
|
*/
|
|
|
|
function ElementInfo(fieldName, containerClass, closeFunc, isArray) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.fieldName = fieldName;
|
|
|
|
this.containerClass = containerClass;
|
|
|
|
this.closeFunc = closeFunc;
|
|
|
|
this.isArray = isArray;
|
|
|
|
this.isWrapper = false;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FeedElementInfo represents a feed element, usually the root.
|
|
|
|
*/
|
|
|
|
function FeedElementInfo(fieldName, feedVersion) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.isWrapper = false;
|
|
|
|
this.fieldName = fieldName;
|
|
|
|
this.feedVersion = feedVersion;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some feed formats include vestigial wrapper elements that we don't
|
|
|
|
* want to include in our object model, but we do need to keep track
|
|
|
|
* of during parsing.
|
|
|
|
*/
|
|
|
|
function WrapperElementInfo(fieldName) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.isWrapper = true;
|
|
|
|
this.fieldName = fieldName;
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** *** The Processor *****/
|
|
|
|
function FeedProcessor() {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._reader = Cc[SAX_CONTRACTID].createInstance(Ci.nsISAXXMLReader);
|
2021-05-08 16:15:38 +00:00
|
|
|
this._buf = "";
|
2021-05-07 13:07:40 +00:00
|
|
|
this._feed = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
|
|
|
|
this._handlerStack = [];
|
|
|
|
this._xmlBaseStack = []; // sparse array keyed to nesting depth
|
|
|
|
this._depth = 0;
|
|
|
|
this._state = "START";
|
|
|
|
this._result = null;
|
|
|
|
this._extensionHandler = null;
|
|
|
|
this._xhtmlHandler = null;
|
|
|
|
this._haveSentResult = false;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// The nsIFeedResultListener waiting for the parse results
|
|
|
|
this.listener = null;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// These elements can contain (X)HTML or plain text.
|
|
|
|
// We keep a table here that contains their default treatment
|
2021-05-07 16:45:01 +00:00
|
|
|
this._textConstructs = {
|
|
|
|
"atom:title": "text",
|
|
|
|
"atom:summary": "text",
|
|
|
|
"atom:rights": "text",
|
|
|
|
"atom:content": "text",
|
|
|
|
"atom:subtitle": "text",
|
|
|
|
"description": "html",
|
|
|
|
"rss1:description": "html",
|
|
|
|
"dc:description": "html",
|
|
|
|
"content:encoded": "html",
|
|
|
|
"title": "text",
|
|
|
|
"rss1:title": "text",
|
|
|
|
"atom03:title": "text",
|
|
|
|
"atom03:tagline": "text",
|
|
|
|
"atom03:summary": "text",
|
|
|
|
"atom03:content": "text"
|
|
|
|
};
|
2021-05-07 13:07:40 +00:00
|
|
|
this._stack = [];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this._trans = {
|
|
|
|
"START": {
|
|
|
|
// If we hit a root RSS element, treat as RSS2.
|
|
|
|
"rss": new FeedElementInfo("RSS2", "rss2"),
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If we hit an RDF element, if could be RSS1, but we can't
|
|
|
|
// verify that until we hit a rss1:channel element.
|
|
|
|
"rdf:RDF": new WrapperElementInfo("RDF"),
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If we hit a Atom 1.0 element, treat as Atom 1.0.
|
|
|
|
"atom:feed": new FeedElementInfo("Atom", "atom"),
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Treat as Atom 0.3
|
|
|
|
"atom03:feed": new FeedElementInfo("Atom03", "atom03"),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
/** ******* RSS2 **********/
|
|
|
|
"IN_RSS2": {
|
|
|
|
"channel": new WrapperElementInfo("channel"),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_CHANNEL": {
|
|
|
|
"item": new ElementInfo("items", Cc[ENTRY_CONTRACTID], null, true),
|
2021-05-07 16:45:01 +00:00
|
|
|
"managingEditor": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:creator": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"category": new ElementInfo("categories", null, rssCatTerm, true),
|
|
|
|
"cloud": new ElementInfo("cloud", null, null, false),
|
|
|
|
"image": new ElementInfo("image", null, null, false),
|
|
|
|
"textInput": new ElementInfo("textInput", null, null, false),
|
|
|
|
"skipDays": new ElementInfo("skipDays", null, null, false),
|
|
|
|
"skipHours": new ElementInfo("skipHours", null, null, false),
|
2021-05-07 16:45:01 +00:00
|
|
|
"generator": new ElementInfo("generator", Cc[GENERATOR_CONTRACTID], atomGenerator, false),
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_ITEMS": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:creator": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"category": new ElementInfo("categories", null, rssCatTerm, true),
|
|
|
|
"enclosure": new ElementInfo("enclosure", null, null, false),
|
|
|
|
"media:content": new ElementInfo("mediacontent", null, null, true),
|
|
|
|
"media:group": new ElementInfo("mediagroup", null, null, false),
|
|
|
|
"media:thumbnail": new ElementInfo("mediathumbnail", null, null, true),
|
|
|
|
"guid": new ElementInfo("guid", null, rssGuid, false),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_SKIPDAYS": {
|
|
|
|
"day": new ElementInfo("days", null, rssArrayElement, true),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_SKIPHOURS": {
|
|
|
|
"hour": new ElementInfo("hours", null, rssArrayElement, true),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_MEDIAGROUP": {
|
|
|
|
"media:content": new ElementInfo("mediacontent", null, null, true),
|
|
|
|
"media:thumbnail": new ElementInfo("mediathumbnail", null, null, true),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
/** ******* RSS1 **********/
|
|
|
|
"IN_RDF": {
|
|
|
|
// If we hit a rss1:channel, we can verify that we have RSS1
|
|
|
|
"rss1:channel": new FeedElementInfo("rdf_channel", "rss1"),
|
|
|
|
"rss1:image": new ElementInfo("image", null, null, false),
|
|
|
|
"rss1:textinput": new ElementInfo("textInput", null, null, false),
|
|
|
|
"rss1:item": new ElementInfo("items", Cc[ENTRY_CONTRACTID], null, true),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_RDF_CHANNEL": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"admin:generatorAgent": new ElementInfo("generator", Cc[GENERATOR_CONTRACTID], null, false),
|
|
|
|
"dc:creator": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
|
|
|
"dc:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], rssAuthor, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
/** ******* ATOM 1.0 **********/
|
|
|
|
"IN_ATOM": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], null, true),
|
|
|
|
"atom:generator": new ElementInfo("generator", Cc[GENERATOR_CONTRACTID], atomGenerator, false),
|
|
|
|
"atom:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"atom:link": new ElementInfo("links", null, null, true),
|
|
|
|
"atom:logo": new ElementInfo("atom:logo", null, atomLogo, false),
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom:entry": new ElementInfo("entries", Cc[ENTRY_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_ENTRIES": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], null, true),
|
|
|
|
"atom:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"atom:link": new ElementInfo("links", null, null, true),
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
/** ******* ATOM 0.3 **********/
|
|
|
|
"IN_ATOM03": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom03:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], null, true),
|
|
|
|
"atom03:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"atom03:link": new ElementInfo("links", null, null, true),
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom03:entry": new ElementInfo("atom03_entries", Cc[ENTRY_CONTRACTID], null, true),
|
|
|
|
"atom03:generator": new ElementInfo("generator", Cc[GENERATOR_CONTRACTID], atomGenerator, false),
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
"IN_ATOM03_ENTRIES": {
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom03:author": new ElementInfo("authors", Cc[PERSON_CONTRACTID], null, true),
|
|
|
|
"atom03:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
"atom03:link": new ElementInfo("links", null, null, true),
|
2021-05-07 16:45:01 +00:00
|
|
|
"atom03:entry": new ElementInfo("atom03_entries", Cc[ENTRY_CONTRACTID], null, true),
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
|
|
|
};
|
2021-05-03 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See startElement for a long description of how feeds are processed.
|
|
|
|
FeedProcessor.prototype = {
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Set ourselves as the SAX handler, and set the base URI
|
2021-05-08 16:15:38 +00:00
|
|
|
_init: function (uri) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._reader.contentHandler = this;
|
|
|
|
this._reader.errorHandler = this;
|
|
|
|
this._result = Cc[FR_CONTRACTID].createInstance(Ci.nsIFeedResult);
|
|
|
|
if (uri) {
|
|
|
|
this._result.uri = uri;
|
|
|
|
this._reader.baseURI = uri;
|
|
|
|
this._xmlBaseStack[0] = uri;
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// This function is called once we figure out what type of feed
|
|
|
|
// we're dealing with. Some feed types require digging a bit further
|
|
|
|
// than the root.
|
2021-05-08 16:15:38 +00:00
|
|
|
_docVerified: function (version) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result.doc = Cc[FEED_CONTRACTID].createInstance(Ci.nsIFeed);
|
2021-05-08 16:15:38 +00:00
|
|
|
this._result.doc.baseURI
|
|
|
|
= this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result.doc.fields = this._feed;
|
|
|
|
this._result.version = version;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// When we're done with the feed, let the listener know what
|
|
|
|
// happened.
|
2021-05-08 16:15:38 +00:00
|
|
|
_sendResult: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._haveSentResult = true;
|
|
|
|
try {
|
|
|
|
// Can be null when a non-feed is fed to us
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._result.doc) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result.doc.normalize();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
LOG("FIXME: " + e);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
2021-05-08 16:24:04 +00:00
|
|
|
if (this.listener !== null) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this.listener.handleResult(this._result);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result = null;
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Parsing functions
|
2021-05-08 16:15:38 +00:00
|
|
|
parseAsync: function (requestObserver, uri) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._init(uri);
|
|
|
|
this._reader.parseAsync(requestObserver);
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// nsIStreamListener
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// The XMLReader will throw sensible exceptions if these get called
|
|
|
|
// out of order.
|
2021-05-08 16:15:38 +00:00
|
|
|
onStartRequest: function (request, context) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// this will throw if the request is not a channel, but so will nsParser.
|
|
|
|
var channel = request.QueryInterface(Ci.nsIChannel);
|
|
|
|
channel.contentType = "application/vnd.mozilla.maybe.feed";
|
|
|
|
this._reader.onStartRequest(request, context);
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
onStopRequest: function (request, context, statusCode) {
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
|
|
|
this._reader.onStopRequest(request, context, statusCode);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
finally {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._reader = null;
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
onDataAvailable: function (request, context, inputStream, offset, count) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._reader.onDataAvailable(request, context, inputStream, offset, count);
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// nsISAXErrorHandler
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// We only care about fatal errors. When this happens, we may have
|
|
|
|
// parsed through the feed metadata and some number of entries. The
|
|
|
|
// listener can still show some of that data if it wants, and we'll
|
|
|
|
// set the bozo bit to indicate we were unable to parse all the way
|
|
|
|
// through.
|
2021-05-08 16:15:38 +00:00
|
|
|
fatalError: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result.bozo = true;
|
|
|
|
// XXX need to QI to FeedProgressListener
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!this._haveSentResult) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._sendResult();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// nsISAXContentHandler
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
startDocument: function () {
|
2021-05-07 13:07:40 +00:00
|
|
|
// LOG("----------");
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
endDocument: function () {
|
|
|
|
if (!this._haveSentResult) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._sendResult();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// The transitions defined above identify elements that contain more
|
|
|
|
// than just text. For example RSS items contain many fields, and so
|
|
|
|
// do Atom authors. The only commonly used elements that contain
|
|
|
|
// mixed content are Atom Text Constructs of type="xhtml", which we
|
|
|
|
// delegate to another handler for cleaning. That leaves a couple
|
|
|
|
// different types of elements to deal with: those that should occur
|
|
|
|
// only once, such as title elements, and those that can occur
|
|
|
|
// multiple times, such as the RSS category element and the Atom
|
|
|
|
// link element. Most of the RSS1/DC elements can occur multiple
|
|
|
|
// times in theory, but in practice, the only ones that do have
|
|
|
|
// analogues in Atom.
|
|
|
|
//
|
|
|
|
// Some elements are also groups of attributes or sub-elements,
|
|
|
|
// while others are simple text fields. For the most part, we don't
|
|
|
|
// have to pay explicit attention to the simple text elements,
|
|
|
|
// unless we want to post-process the resulting string to transform
|
|
|
|
// it into some richer object like a Date or URI.
|
|
|
|
//
|
|
|
|
// Elements that have more sophisticated content models still end up
|
|
|
|
// being dictionaries, whether they are based on attributes like RSS
|
|
|
|
// cloud, sub-elements like Atom author, or even items and
|
|
|
|
// entries. These elements are treated as "containers". It's
|
|
|
|
// theoretically possible for a container to have an attribute with
|
|
|
|
// the same universal name as a sub-element, but none of the feed
|
|
|
|
// formats allow this by default, and I don't of any extension that
|
|
|
|
// works this way.
|
|
|
|
//
|
2021-05-08 16:15:38 +00:00
|
|
|
startElement: function (uri, localName, qName, attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf = "";
|
|
|
|
++this._depth;
|
|
|
|
var elementInfo;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// LOG("<" + localName + ">");
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Check for xml:base
|
|
|
|
var base = attributes.getValueFromName(XMLNS, "base");
|
|
|
|
if (base) {
|
2021-05-08 16:15:38 +00:00
|
|
|
this._xmlBaseStack[this._depth]
|
|
|
|
= strToURI(base, this._xmlBaseStack[this._xmlBaseStack.length - 1]);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// To identify the element we're dealing with, we look up the
|
|
|
|
// namespace URI in our gNamespaces dictionary, which will give us
|
|
|
|
// a "canonical" prefix for a namespace URI. For example, this
|
|
|
|
// 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.
|
2021-05-08 16:15:38 +00:00
|
|
|
var key = this._prefixForNS(uri) + localName;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Check to see if we need to hand this off to our XHTML handler.
|
|
|
|
// The elements we're dealing with will look like this:
|
|
|
|
//
|
|
|
|
// <title type="xhtml">
|
|
|
|
// <div xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
// A title with <b>bold</b> and <i>italics</i>.
|
|
|
|
// </div>
|
|
|
|
// </title>
|
|
|
|
//
|
|
|
|
// When it returns in returnFromXHTMLHandler, the handler should
|
|
|
|
// give us back a string like this:
|
|
|
|
//
|
|
|
|
// "A title with <b>bold</b> and <i>italics</i>."
|
|
|
|
//
|
|
|
|
// The Atom spec explicitly says the div is not part of the content,
|
|
|
|
// and explicitly allows whitespace collapsing.
|
|
|
|
//
|
2021-05-08 16:15:38 +00:00
|
|
|
if ((this._result.version == "atom" || this._result.version == "atom03")
|
2021-05-08 16:24:04 +00:00
|
|
|
&& this._textConstructs[key]) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var type = attributes.getValueFromName("", "type");
|
2021-05-08 16:24:04 +00:00
|
|
|
if (type !== null && type.includes("xhtml")) {
|
2021-05-08 16:15:38 +00:00
|
|
|
this._xhtmlHandler
|
|
|
|
= new XHTMLHandler(this, (this._result.version == "atom"));
|
2021-05-07 13:07:40 +00:00
|
|
|
this._reader.contentHandler = this._xhtmlHandler;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Check our current state, and see if that state has a defined
|
|
|
|
// transition. For example, this._trans["atom:entry"]["atom:author"]
|
|
|
|
// will have one, and it tells us to add an item to our authors array.
|
|
|
|
if (this._trans[this._state] && this._trans[this._state][key]) {
|
|
|
|
elementInfo = this._trans[this._state][key];
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
// If we don't have a transition, hand off to extension handler
|
|
|
|
this._extensionHandler = new ExtensionHandler(this);
|
|
|
|
this._reader.contentHandler = this._extensionHandler;
|
|
|
|
this._extensionHandler.startElement(uri, localName, qName, attributes);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// This distinguishes wrappers like 'channel' from elements
|
|
|
|
// we'd actually like to do something with (which will test true).
|
|
|
|
this._handlerStack[this._depth] = elementInfo;
|
|
|
|
if (elementInfo.isWrapper) {
|
|
|
|
this._state = "IN_" + elementInfo.fieldName.toUpperCase();
|
|
|
|
this._stack.push([this._feed, this._state]);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (elementInfo.feedVersion) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._state = "IN_" + elementInfo.fieldName.toUpperCase();
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Check for the older RSS2 variants
|
2021-05-08 16:15:38 +00:00
|
|
|
if (elementInfo.feedVersion == "rss2") {
|
2021-05-07 13:07:40 +00:00
|
|
|
elementInfo.feedVersion = this._findRSSVersion(attributes);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (uri == RSS090NS) {
|
2021-05-07 13:07:40 +00:00
|
|
|
elementInfo.feedVersion = "rss090";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
this._docVerified(elementInfo.feedVersion);
|
|
|
|
this._stack.push([this._feed, this._state]);
|
|
|
|
this._mapAttributes(this._feed, attributes);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._state = this._processComplexElement(elementInfo, attributes);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// In the endElement handler, we decrement the stack and look
|
|
|
|
// for cleanup/transition functions to execute. The second part
|
|
|
|
// of the state transition works as above in startElement, but
|
|
|
|
// the state we're looking for is prefixed with an underscore
|
|
|
|
// to distinguish endElement events from startElement events.
|
2021-05-08 16:15:38 +00:00
|
|
|
endElement: function (uri, localName, qName) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var elementInfo = this._handlerStack[this._depth];
|
|
|
|
// LOG("</" + localName + ">");
|
2021-05-08 16:15:38 +00:00
|
|
|
if (elementInfo && !elementInfo.isWrapper) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._closeComplexElement(elementInfo);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// cut down xml:base context
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._xmlBaseStack.length == this._depth + 1) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._xmlBaseStack = this._xmlBaseStack.slice(0, this._depth);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// our new state is whatever is at the top of the stack now
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._stack.length > 0) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._state = this._stack[this._stack.length - 1][1];
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
this._handlerStack = this._handlerStack.slice(0, this._depth);
|
|
|
|
--this._depth;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Buffer up character data. The buffer is cleared with every
|
|
|
|
// opening element.
|
2021-05-08 16:15:38 +00:00
|
|
|
characters: function (data) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._buf += data;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
processingInstruction: function (target, data) {
|
2021-05-07 13:07:40 +00:00
|
|
|
if (target == "xml-stylesheet") {
|
2021-05-08 16:24:04 +00:00
|
|
|
var hrefAttribute = data.match(/href=["'](.*?)["']/);
|
2021-05-08 16:15:38 +00:00
|
|
|
if (hrefAttribute && hrefAttribute.length == 2) {
|
2021-05-07 13:07:40 +00:00
|
|
|
this._result.stylesheet = strToURI(hrefAttribute[1], this._result.uri);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// end of nsISAXContentHandler
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Handle our more complicated elements--those that contain
|
|
|
|
// attributes and child elements.
|
2021-05-08 16:15:38 +00:00
|
|
|
_processComplexElement: function (elementInfo, attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var obj;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If the container is an entry/item, it'll need to have its
|
|
|
|
// more esoteric properties put in the 'fields' property bag.
|
|
|
|
if (elementInfo.containerClass == Cc[ENTRY_CONTRACTID]) {
|
|
|
|
obj = elementInfo.containerClass.createInstance(Ci.nsIFeedEntry);
|
|
|
|
obj.baseURI = this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
|
|
|
this._mapAttributes(obj.fields, attributes);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (elementInfo.containerClass) {
|
2021-05-07 13:07:40 +00:00
|
|
|
obj = elementInfo.containerClass.createInstance(Ci.nsIFeedElementBase);
|
|
|
|
obj.baseURI = this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
|
|
|
obj.attributes = attributes; // just set the SAX attributes
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
obj = Cc[BAG_CONTRACTID].createInstance(Ci.nsIWritablePropertyBag2);
|
|
|
|
this._mapAttributes(obj, attributes);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// We should have a container/propertyBag that's had its
|
|
|
|
// attributes processed. Now we need to attach it to its
|
|
|
|
// container.
|
|
|
|
var newProp;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// First we'll see what's on top of the stack.
|
|
|
|
var container = this._stack[this._stack.length - 1][0];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Check to see if it has the property
|
|
|
|
var prop;
|
|
|
|
try {
|
|
|
|
prop = container.getProperty(elementInfo.fieldName);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
if (elementInfo.isArray) {
|
|
|
|
if (!prop) {
|
2021-05-08 16:15:38 +00:00
|
|
|
container.setPropertyAsInterface(
|
|
|
|
elementInfo.fieldName,
|
|
|
|
Cc[ARRAY_CONTRACTID].createInstance(Ci.nsIMutableArray),
|
|
|
|
);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
newProp = container.getProperty(elementInfo.fieldName);
|
|
|
|
// XXX This QI should not be necessary, but XPConnect seems to fly
|
|
|
|
// off the handle in the browser, and loses track of the interface
|
|
|
|
// on large files. Bug 335638.
|
|
|
|
newProp.QueryInterface(Ci.nsIMutableArray);
|
|
|
|
newProp.appendElement(obj);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If new object is an nsIFeedContainer, we want to deal with
|
|
|
|
// its member nsIPropertyBag instead.
|
2021-05-08 16:15:38 +00:00
|
|
|
if (isIFeedContainer(obj)) {
|
2021-05-07 13:07:40 +00:00
|
|
|
newProp = obj.fields;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
// If it doesn't, set it.
|
|
|
|
if (!prop) {
|
|
|
|
container.setPropertyAsInterface(elementInfo.fieldName, obj);
|
|
|
|
}
|
|
|
|
newProp = container.getProperty(elementInfo.fieldName);
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// make our new state name, and push the property onto the stack
|
|
|
|
var newState = "IN_" + elementInfo.fieldName.toUpperCase();
|
|
|
|
this._stack.push([newProp, newState, obj]);
|
|
|
|
return newState;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Sometimes we need reconcile the element content with the object
|
|
|
|
// model for a given feed. We use helper functions to do the
|
|
|
|
// munging, but we need to identify array types here, so the munging
|
|
|
|
// happens only to the last element of an array.
|
2021-05-08 16:15:38 +00:00
|
|
|
_closeComplexElement: function (elementInfo) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var stateTuple = this._stack.pop();
|
|
|
|
var container = stateTuple[0];
|
|
|
|
var containerParent = stateTuple[2];
|
|
|
|
var element = null;
|
|
|
|
var isArray = isIArray(container);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If it's an array and we have to post-process,
|
|
|
|
// grab the last element
|
2021-05-08 16:15:38 +00:00
|
|
|
if (isArray) {
|
2021-05-07 13:07:40 +00:00
|
|
|
element = container.queryElementAt(container.length - 1, Ci.nsISupports);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
element = container;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Run the post-processing function if there is one.
|
2021-05-08 16:15:38 +00:00
|
|
|
if (elementInfo.closeFunc) {
|
2021-05-07 13:07:40 +00:00
|
|
|
element = elementInfo.closeFunc(this._buf, element);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If an nsIFeedContainer was on top of the stack,
|
|
|
|
// we need to normalize it
|
2021-05-08 16:15:38 +00:00
|
|
|
if (elementInfo.containerClass == Cc[ENTRY_CONTRACTID]) {
|
2021-05-07 13:07:40 +00:00
|
|
|
containerParent.normalize();
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If it's an array, re-set the last element
|
2021-05-08 16:15:38 +00:00
|
|
|
if (isArray) {
|
2021-05-07 13:07:40 +00:00
|
|
|
container.replaceElementAt(element, container.length - 1);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_prefixForNS: function (uri) {
|
|
|
|
if (!uri) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return "";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
var prefix = gNamespaces[uri];
|
2021-05-08 16:15:38 +00:00
|
|
|
if (prefix) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return prefix + ":";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
if (uri.toLowerCase().indexOf("http://backend.userland.com") == 0) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return "";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
return null;
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-08 16:15:38 +00:00
|
|
|
_mapAttributes: function (bag, attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// 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) {
|
|
|
|
var key = this._prefixForNS(attributes.getURI(i)) + attributes.getLocalName(i);
|
|
|
|
var val = attributes.getValue(i);
|
|
|
|
bag.setPropertyAsAString(key, val);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Only for RSS2esque formats
|
2021-05-08 16:15:38 +00:00
|
|
|
_findRSSVersion: function (attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
var versionAttr = attributes.getValueFromName("", "version").trim();
|
2021-05-08 16:15:38 +00:00
|
|
|
var versions = {
|
|
|
|
"0.91": "rss091",
|
|
|
|
"0.92": "rss092",
|
|
|
|
"0.93": "rss093",
|
|
|
|
"0.94": "rss094"
|
|
|
|
};
|
|
|
|
if (versions[versionAttr]) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return versions[versionAttr];
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
if (versionAttr.substr(0, 2) != "2.") {
|
2021-05-07 13:07:40 +00:00
|
|
|
return "rssUnknown";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
return "rss2";
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// unknown element values are returned here. See startElement above
|
|
|
|
// for how this works.
|
2021-05-08 16:15:38 +00:00
|
|
|
returnFromExtHandler: function (uri, localName, chars, attributes) {
|
2021-05-07 13:07:40 +00:00
|
|
|
--this._depth;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// take control of the SAX events
|
|
|
|
this._reader.contentHandler = this;
|
2021-05-08 16:24:04 +00:00
|
|
|
if (localName === null && chars === null) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// we don't take random elements inside rdf:RDF
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._state == "IN_RDF") {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Grab the top of the stack
|
|
|
|
var top = this._stack[this._stack.length - 1];
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!top) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
var container = top[0];
|
|
|
|
// Grab the last element if it's an array
|
|
|
|
if (isIArray(container)) {
|
|
|
|
var contract = this._handlerStack[this._depth].containerClass;
|
|
|
|
// check if it's something specific, but not an entry
|
|
|
|
if (contract && contract != Cc[ENTRY_CONTRACTID]) {
|
|
|
|
var el = container.queryElementAt(container.length - 1,
|
2021-05-08 16:15:38 +00:00
|
|
|
Ci.nsIFeedElementBase);
|
2021-05-07 13:07:40 +00:00
|
|
|
// XXX there must be a way to flatten these interfaces
|
2021-05-08 16:15:38 +00:00
|
|
|
if (contract == Cc[PERSON_CONTRACTID]) {
|
2021-05-07 13:07:40 +00:00
|
|
|
el.QueryInterface(Ci.nsIFeedPerson);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
return; // don't know about this interface
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
let propName = localName;
|
|
|
|
var prefix = gNamespaces[uri];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// synonyms
|
2021-05-08 16:15:38 +00:00
|
|
|
if (
|
|
|
|
(uri == ""
|
|
|
|
|| prefix
|
|
|
|
&& ((prefix.indexOf("atom") > -1)
|
|
|
|
|| (prefix.indexOf("rss") > -1)))
|
|
|
|
&& (propName == "url" || propName == "href")
|
|
|
|
) {
|
2021-05-07 13:07:40 +00:00
|
|
|
propName = "uri";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
try {
|
|
|
|
if (el[propName] !== "undefined") {
|
|
|
|
var propValue = chars;
|
|
|
|
// convert URI-bearing values to an nsIURI
|
|
|
|
if (propName == "uri") {
|
|
|
|
var base = this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
|
|
|
propValue = strToURI(chars, base);
|
|
|
|
}
|
|
|
|
el[propName] = propValue;
|
|
|
|
}
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// ignore XPConnect errors
|
|
|
|
}
|
|
|
|
// the rest of the function deals with entry- and feed-level stuff
|
|
|
|
return;
|
|
|
|
}
|
2021-05-08 16:15:38 +00:00
|
|
|
container = container.queryElementAt(container.length - 1, Ci.nsIWritablePropertyBag2);
|
2021-05-07 13:07:40 +00:00
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Make the buffer our new property
|
|
|
|
var propName = this._prefixForNS(uri) + localName;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// But, it could be something containing HTML. If so,
|
|
|
|
// we need to know about that.
|
2021-05-08 16:24:04 +00:00
|
|
|
if (this._textConstructs[propName]
|
2021-05-08 16:15:38 +00:00
|
|
|
&& this._handlerStack[this._depth].containerClass !== null) {
|
|
|
|
var newProp = Cc[TEXTCONSTRUCT_CONTRACTID].createInstance(Ci.nsIFeedTextConstruct);
|
2021-05-07 13:07:40 +00:00
|
|
|
newProp.text = chars;
|
|
|
|
// Look up the default type in our table
|
|
|
|
var type = this._textConstructs[propName];
|
|
|
|
var typeAttribute = attributes.getValueFromName("", "type");
|
2021-05-08 16:24:04 +00:00
|
|
|
if (this._result.version == "atom" && typeAttribute !== null) {
|
2021-05-07 13:07:40 +00:00
|
|
|
type = typeAttribute;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-08 16:24:04 +00:00
|
|
|
else if (this._result.version == "atom03" && typeAttribute !== null) {
|
2021-05-07 13:07:40 +00:00
|
|
|
if (typeAttribute.toLowerCase().includes("xhtml")) {
|
|
|
|
type = "xhtml";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (typeAttribute.toLowerCase().includes("html")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
type = "html";
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else if (typeAttribute.toLowerCase().includes("text")) {
|
2021-05-07 13:07:40 +00:00
|
|
|
type = "text";
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// If it's rss feed-level description, it's not supposed to have html
|
2021-05-08 16:15:38 +00:00
|
|
|
if (this._result.version.includes("rss")
|
|
|
|
&& this._handlerStack[this._depth].containerClass != ENTRY_CONTRACTID) {
|
2021-05-07 13:07:40 +00:00
|
|
|
type = "text";
|
|
|
|
}
|
|
|
|
newProp.type = type;
|
|
|
|
newProp.base = this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
|
|
|
container.setPropertyAsInterface(propName, newProp);
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-07 13:07:40 +00:00
|
|
|
container.setPropertyAsAString(propName, chars);
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Sometimes, we'll hand off SAX handling duties to an XHTMLHandler
|
|
|
|
// (see above) that will scrape out non-XHTML stuff, normalize
|
|
|
|
// namespaces, and remove the wrapper div from Atom 1.0. When the
|
|
|
|
// XHTMLHandler is done, it'll callback here.
|
2021-05-08 16:15:38 +00:00
|
|
|
returnFromXHTMLHandler: function (chars, uri, localName, qName) {
|
2021-05-07 13:07:40 +00:00
|
|
|
// retake control of the SAX content events
|
|
|
|
this._reader.contentHandler = this;
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Grab the top of the stack
|
|
|
|
var top = this._stack[this._stack.length - 1];
|
2021-05-08 16:15:38 +00:00
|
|
|
if (!top) {
|
2021-05-07 13:07:40 +00:00
|
|
|
return;
|
2021-05-08 16:15:38 +00:00
|
|
|
}
|
2021-05-07 13:07:40 +00:00
|
|
|
var container = top[0];
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// Assign the property
|
2021-05-08 16:15:38 +00:00
|
|
|
var newProp = newProp = Cc[TEXTCONSTRUCT_CONTRACTID].createInstance(Ci.nsIFeedTextConstruct);
|
2021-05-07 13:07:40 +00:00
|
|
|
newProp.text = chars;
|
|
|
|
newProp.type = "xhtml";
|
|
|
|
newProp.base = this._xmlBaseStack[this._xmlBaseStack.length - 1];
|
2021-05-08 16:15:38 +00:00
|
|
|
container.setPropertyAsInterface(this._prefixForNS(uri) + localName, newProp);
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XHTML will cause us to peek too far. The XHTML handler will
|
|
|
|
// send us an end element to call. RFC4287-valid feeds allow a
|
|
|
|
// more graceful way to handle this. Unfortunately, we can't count
|
|
|
|
// on compliance at this point.
|
|
|
|
this.endElement(uri, localName, qName);
|
|
|
|
},
|
2021-05-07 16:45:01 +00:00
|
|
|
|
2021-05-07 13:07:40 +00:00
|
|
|
// XPCOM stuff
|
|
|
|
classID: FP_CLASSID,
|
2021-05-07 16:45:01 +00:00
|
|
|
QueryInterface: ChromeUtils.generateQI([
|
|
|
|
Ci.nsIFeedProcessor,
|
|
|
|
Ci.nsISAXContentHandler,
|
|
|
|
Ci.nsISAXErrorHandler,
|
|
|
|
Ci.nsIStreamListener,
|
|
|
|
Ci.nsIRequestObserver,
|
|
|
|
]),
|
2021-05-03 22:29:18 +00:00
|
|
|
};
|
|
|
|
|
2021-05-07 16:45:01 +00:00
|
|
|
var components = [
|
|
|
|
FeedProcessor,
|
|
|
|
FeedResult,
|
|
|
|
Feed,
|
|
|
|
Entry,
|
|
|
|
TextConstruct,
|
|
|
|
Generator,
|
|
|
|
Person,
|
|
|
|
];
|
2021-05-03 22:29:18 +00:00
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|