bug 373340. atom:logo in feed reading view. r=mano

This commit is contained in:
sayrer@gmail.com 2007-03-27 18:07:39 -07:00
parent eea3888f52
commit 9c3474cffb
2 changed files with 42 additions and 17 deletions

View File

@ -346,7 +346,7 @@ Feed.prototype = {
categories: ["categories", "dc:subject"],
rights: ["atom03:rights","atom:rights"],
cloud: ["cloud"],
image: ["image", "rss1:image"],
image: ["image", "rss1:image", "atom:logo"],
textInput: ["textInput", "rss1:textinput"],
skipDays: ["skipDays"],
skipHours: ["skipHours"],
@ -368,6 +368,10 @@ Feed.prototype = {
if (bagHasKey(this.fields, "links"))
this._atomLinksToURI();
// Resolve relative image links
if (this.image && bagHasKey(this.image, "url"))
this._resolveImageLink();
this._resetBagMembersToRawText([this.searchLists.subtitle,
this.searchLists.title]);
},
@ -376,22 +380,36 @@ Feed.prototype = {
var links = this.fields.getPropertyAsInterface("links", Ci.nsIArray);
var alternates = findAtomLinks("alternate", links);
if (alternates.length > 0) {
try {
var href = alternates[0].getPropertyAsAString("href");
var base;
if (bagHasKey(alternates[0], "xml:base"))
base = strToURI(alternates[0].getPropertyAsAString("xml:base"),
this.baseURI);
else
base = this.baseURI;
this.link = strToURI(alternates[0].getPropertyAsAString("href"), base);
}
catch(e) {
LOG(e);
}
var href = alternates[0].getPropertyAsAString("href");
var base;
if (bagHasKey(alternates[0], "xml:base"))
base = alternates[0].getPropertyAsAString("xml:base");
this.link = this._resolveURI(href, base);
}
},
_resolveImageLink: function Feed_resolveImageLink() {
var base;
if (bagHasKey(this.image, "xml:base"))
base = this.image.getPropertyAsAString("xml:base");
var url = this._resolveURI(this.image.getPropertyAsAString("url"), base);
if (url)
this.image.setPropertyAsAString("url", url.spec);
},
_resolveURI: function Feed_resolveURI(linkSpec, baseSpec) {
var uri = null;
try {
var base = baseSpec ? strToURI(baseSpec, this.baseURI) : this.baseURI;
uri = strToURI(linkSpec, base);
}
catch(e) {
LOG(e);
}
return uri;
},
// reset the bag to raw contents, not text constructs
_resetBagMembersToRawText: function Feed_resetBagMembers(fieldLists) {
for (var i=0; i<fieldLists.length; i++) {
@ -490,6 +508,7 @@ Entry.prototype = {
}
Entry.prototype._atomLinksToURI = Feed.prototype._atomLinksToURI;
Entry.prototype._resolveURI = Feed.prototype._resolveURI;
Entry.prototype._resetBagMembersToRawText =
Feed.prototype._resetBagMembersToRawText;
@ -646,7 +665,12 @@ function atomGenerator(s, generator) {
generator.QueryInterface(Ci.nsIFeedGenerator);
generator.agent = trimString(s);
return generator;
}
}
// post-process atom:logo to create an RSS2-like structure
function atomLogo(s, logo) {
logo.setPropertyAsAString("url", trimString(s));
}
// post-process an RSS category, map it to the Atom fields.
function rssCatTerm(s, cat) {
@ -1152,6 +1176,7 @@ function FeedProcessor() {
"atom:contributor": new ElementInfo("contributors", Cc[PERSON_CONTRACTID],
null, true),
"atom:link": new ElementInfo("links", null, null, true),
"atom:logo": new ElementInfo("atom:logo", null, atomLogo, false),
"atom:entry": new ElementInfo("entries", Cc[ENTRY_CONTRACTID],
null, true)
},

View File

@ -2,10 +2,10 @@
<!--
Description: atom logo works
Expect: feed.fields.getProperty('atom:logo') == 'http://example.org/logo.jpg'
Expect: feed.image.getProperty('url') == 'http://example.org/logo.jpg'
-->
<feed xmlns="http://www.w3.org/2005/Atom">
<title>test title</title>
<logo>http://example.org/logo.jpg</logo>
<logo xml:base="http://example.org/">logo.jpg</logo>
</feed>