- 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 we're performing a search and didn't get any results, go on
// to the next translator
Scholar.debug("could not find a result using "+this.translator[0].label+": \n"
+this._generateErrorString(error));
this.translator.shift();
this.translate();
} else {
@ -897,23 +899,7 @@ Scholar.Translate.prototype._translationComplete = function(returnValue, error)
this._runHandler("done", returnValue);
if(!returnValue) {
var errorString = "";
if(typeof(error) == "string") {
errorString = "\nthrown exception => "+error;
} else {
for(var i in error) {
if(typeof(error[i]) != "object") {
errorString += "\n"+i+' => '+error[i];
}
}
}
errorString += "\nurl => "+this.path
+ "\nextensions.zotero.cacheTranslatorData => "+Scholar.Prefs.get("cacheTranslatorData")
+ "\nextensions.zotero.downloadAssociatedFiles => "+Scholar.Prefs.get("downloadAssociatedFiles");
errorString = errorString.substr(1);
var errorString = this._generateErrorString(error);
Scholar.debug("translation using "+this.translator[0].label+" failed: \n"+errorString);
if(this.type == "web") {
@ -927,6 +913,27 @@ Scholar.Translate.prototype._translationComplete = function(returnValue, error)
}
}
/*
* generates a useful error string, for submitting and debugging purposes
*/
Scholar.Translate.prototype._generateErrorString = function(error) {
var errorString = "";
if(typeof(error) == "string") {
errorString = "\nthrown exception => "+error;
} else {
for(var i in error) {
if(typeof(error[i]) != "object") {
errorString += "\n"+i+' => '+error[i];
}
}
}
errorString += "\nurl => "+this.path
+ "\nextensions.zotero.cacheTranslatorData => "+Scholar.Prefs.get("cacheTranslatorData")
+ "\nextensions.zotero.downloadAssociatedFiles => "+Scholar.Prefs.get("downloadAssociatedFiles");
return errorString.substr(1);
}
/*
* runs an HTTP request to report a translation error
*/

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",
"with", "up", "down"];
Scholar.Utilities.prototype.capitalizeTitle = function(title) {
title = this.cleanString(title);
title = title.replace(/ : /g, ": ");
var words = title.split(" ");
@ -172,7 +173,7 @@ Scholar.Utilities.prototype.capitalizeTitle = function(title) {
for(var i=1; i<lastWordIndex; i++) {
// if not a skip word
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);
} else {
words[i] = words[i].toLowerCase();
@ -560,7 +561,9 @@ Scholar.Utilities.HTTP.processDocuments = function(firstDoc, urls, processor, do
}
} else {
removeListeners();
done();
if(done) {
done();
}
}
};
var onLoad = function() {

View file

@ -4094,9 +4094,7 @@ function processOWC(doc) {
var spanTitle = spanTags[i].getAttribute("title");
var item = new Scholar.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();
return true;
} else {
@ -4146,8 +4144,6 @@ function doSearch(item) {
processOWC(doc);
}, function() { // done
Scholar.done();
}, function() { // error
Scholar.done(false);
});
}
}, null);