- fixes a bug in capitalizeTitle

- better feedback for search translator errors
This commit is contained in:
Simon Kornblith 2006-09-09 22:45:03 +00:00
parent 14c5c40a50
commit d5bc6cbe4b
3 changed files with 30 additions and 24 deletions

View File

@ -876,6 +876,8 @@ Scholar.Translate.prototype._translationComplete = function(returnValue, error)
if(this.type == "search" && !this._itemsFound && this.translator.length > 1) { if(this.type == "search" && !this._itemsFound && this.translator.length > 1) {
// if we're performing a search and didn't get any results, go on // if we're performing a search and didn't get any results, go on
// to the next translator // to the next translator
Scholar.debug("could not find a result using "+this.translator[0].label+": \n"
+this._generateErrorString(error));
this.translator.shift(); this.translator.shift();
this.translate(); this.translate();
} else { } else {
@ -897,6 +899,24 @@ Scholar.Translate.prototype._translationComplete = function(returnValue, error)
this._runHandler("done", returnValue); this._runHandler("done", returnValue);
if(!returnValue) { if(!returnValue) {
var errorString = this._generateErrorString(error);
Scholar.debug("translation using "+this.translator[0].label+" failed: \n"+errorString);
if(this.type == "web") {
// report translation error for websites
this._reportTranslationFailure(errorString);
}
} else {
Scholar.debug("translation successful");
}
}
}
}
/*
* generates a useful error string, for submitting and debugging purposes
*/
Scholar.Translate.prototype._generateErrorString = function(error) {
var errorString = ""; var errorString = "";
if(typeof(error) == "string") { if(typeof(error) == "string") {
errorString = "\nthrown exception => "+error; errorString = "\nthrown exception => "+error;
@ -911,20 +931,7 @@ Scholar.Translate.prototype._translationComplete = function(returnValue, error)
errorString += "\nurl => "+this.path errorString += "\nurl => "+this.path
+ "\nextensions.zotero.cacheTranslatorData => "+Scholar.Prefs.get("cacheTranslatorData") + "\nextensions.zotero.cacheTranslatorData => "+Scholar.Prefs.get("cacheTranslatorData")
+ "\nextensions.zotero.downloadAssociatedFiles => "+Scholar.Prefs.get("downloadAssociatedFiles"); + "\nextensions.zotero.downloadAssociatedFiles => "+Scholar.Prefs.get("downloadAssociatedFiles");
return errorString.substr(1);
errorString = errorString.substr(1);
Scholar.debug("translation using "+this.translator[0].label+" failed: \n"+errorString);
if(this.type == "web") {
// report translation error for websites
this._reportTranslationFailure(errorString);
}
} else {
Scholar.debug("translation successful");
}
}
}
} }
/* /*

View File

@ -158,6 +158,7 @@ Scholar.Utilities.capitalizeSkipWords = ["but", "or", "yet", "so", "for", "and",
"nor", "a", "an", "the", "at", "by", "from", "in", "into", "of", "on", "to", "nor", "a", "an", "the", "at", "by", "from", "in", "into", "of", "on", "to",
"with", "up", "down"]; "with", "up", "down"];
Scholar.Utilities.prototype.capitalizeTitle = function(title) { Scholar.Utilities.prototype.capitalizeTitle = function(title) {
title = this.cleanString(title);
title = title.replace(/ : /g, ": "); title = title.replace(/ : /g, ": ");
var words = title.split(" "); var words = title.split(" ");
@ -172,7 +173,7 @@ Scholar.Utilities.prototype.capitalizeTitle = function(title) {
for(var i=1; i<lastWordIndex; i++) { for(var i=1; i<lastWordIndex; i++) {
// if not a skip word // if not a skip word
if(Scholar.Utilities.capitalizeSkipWords.indexOf(words[i].toLowerCase()) == -1 || if(Scholar.Utilities.capitalizeSkipWords.indexOf(words[i].toLowerCase()) == -1 ||
words[i-1][words[i-1].length-1] == ":") { (words[i-1].length && words[i-1][words[i-1].length-1] == ":")) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1); words[i] = words[i][0].toUpperCase() + words[i].substr(1);
} else { } else {
words[i] = words[i].toLowerCase(); words[i] = words[i].toLowerCase();
@ -560,8 +561,10 @@ Scholar.Utilities.HTTP.processDocuments = function(firstDoc, urls, processor, do
} }
} else { } else {
removeListeners(); removeListeners();
if(done) {
done(); done();
} }
}
}; };
var onLoad = function() { var onLoad = function() {
Scholar.debug(hiddenBrowser.contentDocument.location.href+" has been loaded"); Scholar.debug(hiddenBrowser.contentDocument.location.href+" has been loaded");

View File

@ -4094,9 +4094,7 @@ function processOWC(doc) {
var spanTitle = spanTags[i].getAttribute("title"); var spanTitle = spanTags[i].getAttribute("title");
var item = new Scholar.Item(); var item = new Scholar.Item();
if(Scholar.Utilities.parseContextObject(spanTitle, item)) { if(Scholar.Utilities.parseContextObject(spanTitle, item)) {
if(item.title) {
item.title = Scholar.Utilities.capitalizeTitle(item.title); item.title = Scholar.Utilities.capitalizeTitle(item.title);
}
item.complete(); item.complete();
return true; return true;
} else { } else {
@ -4146,8 +4144,6 @@ function doSearch(item) {
processOWC(doc); processOWC(doc);
}, function() { // done }, function() { // done
Scholar.done(); Scholar.done();
}, function() { // error
Scholar.done(false);
}); });
} }
}, null); }, null);