Bug #253807 --> Port from the aviary 1.0 branch.

I18N improvements for character set handling in RSS.
This commit is contained in:
scott%scott-macgregor.org 2004-12-21 23:28:40 +00:00
Родитель fbf4456891
Коммит fcdb09e58b
3 изменённых файлов: 37 добавлений и 41 удалений

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

@ -1,4 +1,3 @@
// -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
var rdfcontainer =
Components
.classes["@mozilla.org/rdf/container-utils;1"]
@ -173,7 +172,7 @@ Feed.prototype.quickMode getter = function() {
quickMode = quickMode.QueryInterface(Components.interfaces.nsIRDFLiteral);
quickMode = quickMode.Value;
quickMode = eval(quickMode);
}
}
return quickMode;
}
@ -290,17 +289,13 @@ Feed.prototype.parseAsRSS2 = function() {
|| itemNode.getElementsByTagName("date")[0])
|| item.date;
var content = getNodeValue(itemNode.getElementsByTagNameNS(RSS_CONTENT_NS, "encoded")[0]);
if (content)
item.content = content;
var content = getNodeValue(itemNode.getElementsByTagNameNS(RSS_CONTENT_NS, "encoded")[0]);
if (content)
item.content = converter.ConvertFromUnicode(content);
this.itemsToStore[i] = item;
}
this.storeNextItem();
}
@ -372,8 +367,9 @@ Feed.prototype.parseAsRSS1 = function() {
this.itemsToStore[index++] = item;
}
this.storeNextItem();
if (index) // at least one item to store?
this.storeNextItem();
}
Feed.prototype.parseAsAtom = function() {
@ -551,40 +547,40 @@ Feed.prototype.storeNextItem = function()
this.storeItemsTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
this.storeItemsTimer.initWithCallback(this, 50, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
else
else
this.cleanupParsingState(item.feed);
}
Feed.prototype.cleanupParsingState = function(feed) {
// now that we are done parsing the feed, remove the feed from our feed cache
// now that we are done parsing the feed, remove the feed from our feed cache
gFzFeedCache[feed.url] = "";
feed.removeInvalidItems();
// let's be sure to flush any feed item changes back to disk
// let's be sure to flush any feed item changes back to disk
var ds = getItemsDS(feed.server);
ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); // flush any changes
ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); // flush any changes
if (feed.downloadCallback)
feed.downloadCallback.downloaded(feed, kNewsBlogSuccess);
feed.request = null; // force the xml http request to go away. This helps reduce some
// nasty assertions on shut down of all things.
// nasty assertions on shut down of all things.
this.itemsToStore = "";
this.itemsToStoreIndex = 0;
this.storeItemsTimer = null;
}
this.itemsToStore = "";
this.itemsToStoreIndex = 0;
this.storeItemsTimer = null;
}
Feed.prototype.notify = function(aTimer) {
this.storeNextItem();
}
Feed.prototype.QueryInterface = function(aIID) {
if (aIID.equals(Components.interfaces.nsITimerCallback) || aIID.equals(Components.interfaces.nsISupports))
return this;
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
return null;
}
Feed.prototype.QueryInterface = function(aIID) {
if (aIID.equals(Components.interfaces.nsITimerCallback) || aIID.equals(Components.interfaces.nsISupports))
return this;
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
return null;
}

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

@ -246,7 +246,7 @@ FeedItem.prototype.markValid = function() {
FeedItem.prototype.markStored = function() {
var ds = getItemsDS(this.feed.server);
var resource = rdf.GetResource(this.url || ("urn:" + this.id));
if (!ds.HasAssertion(resource, FZ_FEED, rdf.GetResource(this.feed.url), true))
ds.Assert(resource, FZ_FEED, rdf.GetResource(this.feed.url), true);
@ -257,7 +257,7 @@ FeedItem.prototype.markStored = function() {
}
else
ds.Assert(resource, FZ_STORED, RDF_LITERAL_TRUE, true);
}
}
FeedItem.prototype.download = function() {
this.request = new XMLHttpRequest();
@ -302,13 +302,8 @@ FeedItem.unicodeConverter =
Components
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
FeedItem.unicodeConverter.charset = "UTF-8";
FeedItem.prototype.toUtf8 = function(str) {
return FeedItem.unicodeConverter.ConvertFromUnicode(str);
}
function mimeEncodeSubject(aSubject, charset)
FeedItem.prototype.mimeEncodeSubject = function(aSubject, charset)
{
// get the mime header encoder service
var mimeEncoder = Components
@ -320,7 +315,7 @@ function mimeEncodeSubject(aSubject, charset)
var newSubject;
try {
newSubject = mimeEncoder.encodeMimePartIIStr(aSubject, false, charset, 9, 72);
newSubject = mimeEncoder.encodeMimePartIIStr(FeedItem.unicodeConverter.ConvertFromUnicode(aSubject), false, charset, 9, 72);
}
catch (ex) {
newSubject = aSubject;
@ -333,6 +328,7 @@ FeedItem.prototype.writeToFolder = function() {
debug(this.identity + " writing to message folder" + this.feed.name + "\n");
var server = this.feed.server;
FeedItem.unicodeConverter.charset = this.characterSet;
// XXX Should we really be modifying the original data here instead of making
// a copy of it? Currently we never use the item object again after writing it
@ -356,7 +352,7 @@ FeedItem.prototype.writeToFolder = function() {
// Compress white space in the subject to make it look better.
title = title.replace(/[\t\r\n]+/g, " ");
this.title = mimeEncodeSubject(title, this.characterSet);
this.title = this.mimeEncodeSubject(title, this.characterSet);
// If the date looks like it's in W3C-DTF format, convert it into
// an IETF standard date. Otherwise assume it's in IETF format.
@ -395,7 +391,9 @@ FeedItem.prototype.writeToFolder = function() {
// Get the folder and database storing the feed's messages and headers.
var folder = this.feed.folder ? this.feed.folder : server.rootMsgFolder.getChildNamed(this.feed.name);
folder = folder.QueryInterface(Components.interfaces.nsIMsgLocalMailFolder);
folder.addMessage(source);
// source is a unicode string, we want to save a char * string in the original charset. So convert back
folder.addMessage(FeedItem.unicodeConverter.ConvertFromUnicode(source));
this.markStored();
}

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

@ -413,9 +413,6 @@ nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow)
NS_IMETHODIMP nsMessenger::SetDisplayCharset(const char * aCharset)
{
if (mCurrentDisplayCharset.Equals(aCharset))
return NS_OK;
// libmime always converts to UTF-8 (both HTML and XML)
if (mDocShell)
{
@ -425,7 +422,10 @@ NS_IMETHODIMP nsMessenger::SetDisplayCharset(const char * aCharset)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
muDV->SetForceCharacterSet(nsDependentCString(aCharset));
{
muDV->SetHintCharacterSet(nsDependentCString(aCharset));
muDV->SetHintCharacterSetSource(9);
}
mCurrentDisplayCharset = aCharset;
}
@ -1511,6 +1511,8 @@ NS_IMETHODIMP nsMessenger::SetDocumentCharset(const char *characterSet)
// redisplay to use characterSet
if (!mLastDisplayURI.IsEmpty())
{
SetDisplayCharset("UTF-8");
nsCOMPtr <nsIMsgMessageService> messageService;
nsresult rv = GetMessageServiceFromURI(mLastDisplayURI.get(), getter_AddRefs(messageService));