Fix importing RIS/refer
This commit is contained in:
parent
f37a225a30
commit
0ea89d9755
|
@ -124,48 +124,12 @@ var Zotero_Browser = new function() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function scrapeThisPage(translator) {
|
function scrapeThisPage(translator) {
|
||||||
if (Zotero.locked) {
|
// Perform translation
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
|
||||||
var desc = Zotero.localeJoin([
|
if(tab.page.translators && tab.page.translators.length) {
|
||||||
Zotero.getString('general.operationInProgress'),
|
tab.page.translate.setTranslator(translator || tab.page.translators[0]);
|
||||||
Zotero.getString('general.operationInProgress.waitUntilFinishedAndTryAgain')
|
Zotero_Browser.performTranslation(tab.page.translate);
|
||||||
]);
|
|
||||||
Zotero_Browser.progress.addDescription(desc);
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
Zotero_Browser.progress.startCloseTimer(8000);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Zotero.stateCheck()) {
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
|
||||||
var desc = Zotero.getString("ingester.scrapeErrorDescription.previousError")
|
|
||||||
+ ' ' + Zotero.getString("general.restartFirefoxAndTryAgain", Zotero.appName);
|
|
||||||
Zotero_Browser.progress.addDescription(desc);
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
Zotero_Browser.progress.startCloseTimer(8000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get libraryID and collectionID
|
|
||||||
var libraryID = null, collectionID = null;
|
|
||||||
if(ZoteroPane && !Zotero.isConnector) {
|
|
||||||
try {
|
|
||||||
if (!ZoteroPane.collectionsView.editable) {
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
|
||||||
var desc = Zotero.getString('save.error.cannotMakeChangesToCollection');
|
|
||||||
Zotero_Browser.progress.addDescription(desc);
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
Zotero_Browser.progress.startCloseTimer(8000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
libraryID = ZoteroPane.getSelectedLibraryID();
|
|
||||||
collectionID = ZoteroPane.getSelectedCollection(true);
|
|
||||||
} catch(e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// translate into specified library and collection
|
|
||||||
_getTabObject(Zotero_Browser.tabbrowser.selectedBrowser).translate(libraryID, collectionID, translator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -494,6 +458,134 @@ var Zotero_Browser = new function() {
|
||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates using the specified translation instance. setTranslator() must already
|
||||||
|
* have been called
|
||||||
|
* @param {Zotero.Translate} translate
|
||||||
|
*/
|
||||||
|
this.performTranslation = function(translate, libraryID, collection) {
|
||||||
|
if (Zotero.locked) {
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
||||||
|
var desc = Zotero.localeJoin([
|
||||||
|
Zotero.getString('general.operationInProgress'),
|
||||||
|
Zotero.getString('general.operationInProgress.waitUntilFinishedAndTryAgain')
|
||||||
|
]);
|
||||||
|
Zotero_Browser.progress.addDescription(desc);
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
Zotero_Browser.progress.startCloseTimer(8000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Zotero.stateCheck()) {
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
||||||
|
var desc = Zotero.getString("ingester.scrapeErrorDescription.previousError")
|
||||||
|
+ ' ' + Zotero.getString("general.restartFirefoxAndTryAgain", Zotero.appName);
|
||||||
|
Zotero_Browser.progress.addDescription(desc);
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
Zotero_Browser.progress.startCloseTimer(8000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
Zotero_Browser.isScraping = true;
|
||||||
|
|
||||||
|
// Get libraryID and collectionID
|
||||||
|
if(libraryID === undefined && ZoteroPane && !Zotero.isConnector) {
|
||||||
|
try {
|
||||||
|
if (!ZoteroPane.collectionsView.editable) {
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
||||||
|
var desc = Zotero.getString('save.error.cannotMakeChangesToCollection');
|
||||||
|
Zotero_Browser.progress.addDescription(desc);
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
Zotero_Browser.progress.startCloseTimer(8000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
libraryID = ZoteroPane.getSelectedLibraryID();
|
||||||
|
collection = ZoteroPane.getSelectedCollection(true);
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Zotero.isConnector) {
|
||||||
|
Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) {
|
||||||
|
if(status !== 200) {
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping"));
|
||||||
|
} else {
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
||||||
|
"chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png",
|
||||||
|
response.name+"\u2026");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var name;
|
||||||
|
if(collection) {
|
||||||
|
name = collection.name;
|
||||||
|
} else if(libraryID) {
|
||||||
|
name = Zotero.Libraries.getName(libraryID);
|
||||||
|
} else {
|
||||||
|
name = Zotero.getString("pane.collections.library");
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
||||||
|
"chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png",
|
||||||
|
name+"\u2026");
|
||||||
|
}
|
||||||
|
|
||||||
|
translate.clearHandlers("done");
|
||||||
|
translate.clearHandlers("itemDone");
|
||||||
|
|
||||||
|
translate.setHandler("done", function(obj, returnValue) {
|
||||||
|
if(!returnValue) {
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
||||||
|
// Include link to Known Translator Issues page
|
||||||
|
var url = "http://www.zotero.org/documentation/known_translator_issues";
|
||||||
|
var linkText = '<a href="' + url + '" tooltiptext="' + url + '">'
|
||||||
|
+ Zotero.getString('ingester.scrapeErrorDescription.linkText') + '</a>';
|
||||||
|
Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText));
|
||||||
|
Zotero_Browser.progress.startCloseTimer(8000);
|
||||||
|
} else {
|
||||||
|
Zotero_Browser.progress.startCloseTimer();
|
||||||
|
}
|
||||||
|
Zotero_Browser.isScraping = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
var attachmentsMap = new WeakMap();
|
||||||
|
|
||||||
|
translate.setHandler("itemDone", function(obj, dbItem, item) {
|
||||||
|
Zotero_Browser.progress.show();
|
||||||
|
var itemProgress = new Zotero_Browser.progress.ItemProgress(Zotero.ItemTypes.getImageSrc(item.itemType),
|
||||||
|
item.title);
|
||||||
|
itemProgress.setProgress(100);
|
||||||
|
for(var i=0; i<item.attachments.length; i++) {
|
||||||
|
var attachment = item.attachments[i];
|
||||||
|
attachmentsMap.set(attachment,
|
||||||
|
new Zotero_Browser.progress.ItemProgress(
|
||||||
|
Zotero.Utilities.determineAttachmentIcon(attachment),
|
||||||
|
attachment.title, itemProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
// add item to collection, if one was specified
|
||||||
|
if(collection) {
|
||||||
|
collection.addItem(dbItem.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
translate.setHandler("attachmentProgress", function(obj, attachment, progress, error) {
|
||||||
|
var itemProgress = attachmentsMap.get(attachment);
|
||||||
|
if(progress === false) {
|
||||||
|
itemProgress.setError();
|
||||||
|
} else {
|
||||||
|
itemProgress.setProgress(progress);
|
||||||
|
if(progress === 100) {
|
||||||
|
itemProgress.setIcon(Zotero.Utilities.determineAttachmentIcon(attachment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
translate.translate(libraryID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -660,110 +752,6 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* translate a page
|
|
||||||
*
|
|
||||||
* @param {Integer} libraryID
|
|
||||||
* @param {Integer} collectionID
|
|
||||||
*/
|
|
||||||
Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, translator) {
|
|
||||||
if(this.page.translators && this.page.translators.length) {
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
Zotero_Browser.isScraping = true;
|
|
||||||
|
|
||||||
if(collectionID) {
|
|
||||||
var collection = Zotero.Collections.get(collectionID);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var collection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Zotero.isConnector) {
|
|
||||||
Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) {
|
|
||||||
if(status !== 200) {
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping"));
|
|
||||||
} else {
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
|
||||||
"chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png",
|
|
||||||
response.name+"\u2026");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var name;
|
|
||||||
if(collection) {
|
|
||||||
name = collection.name;
|
|
||||||
} else if(libraryID) {
|
|
||||||
name = Zotero.Libraries.getName(libraryID);
|
|
||||||
} else {
|
|
||||||
name = Zotero.getString("pane.collections.library");
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
|
||||||
"chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png",
|
|
||||||
name+"\u2026");
|
|
||||||
}
|
|
||||||
|
|
||||||
var me = this;
|
|
||||||
|
|
||||||
// use first translator available
|
|
||||||
this.page.translate.setTranslator(translator ? translator : this.page.translators[0]);
|
|
||||||
|
|
||||||
this.page.translate.clearHandlers("done");
|
|
||||||
this.page.translate.clearHandlers("itemDone");
|
|
||||||
|
|
||||||
this.page.translate.setHandler("done", function(obj, returnValue) {
|
|
||||||
if(!returnValue) {
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
|
||||||
// Include link to Known Translator Issues page
|
|
||||||
var url = "http://www.zotero.org/documentation/known_translator_issues";
|
|
||||||
var linkText = '<a href="' + url + '" tooltiptext="' + url + '">'
|
|
||||||
+ Zotero.getString('ingester.scrapeErrorDescription.linkText') + '</a>';
|
|
||||||
Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText));
|
|
||||||
Zotero_Browser.progress.startCloseTimer(8000);
|
|
||||||
} else {
|
|
||||||
Zotero_Browser.progress.startCloseTimer();
|
|
||||||
}
|
|
||||||
Zotero_Browser.isScraping = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
var attachmentsMap = new WeakMap();
|
|
||||||
|
|
||||||
this.page.translate.setHandler("itemDone", function(obj, dbItem, item) {
|
|
||||||
Zotero_Browser.progress.show();
|
|
||||||
var itemProgress = new Zotero_Browser.progress.ItemProgress(Zotero.ItemTypes.getImageSrc(item.itemType),
|
|
||||||
item.title);
|
|
||||||
itemProgress.setProgress(100);
|
|
||||||
for(var i=0; i<item.attachments.length; i++) {
|
|
||||||
var attachment = item.attachments[i];
|
|
||||||
attachmentsMap.set(attachment,
|
|
||||||
new Zotero_Browser.progress.ItemProgress(
|
|
||||||
Zotero.Utilities.determineAttachmentIcon(attachment),
|
|
||||||
attachment.title, itemProgress));
|
|
||||||
}
|
|
||||||
|
|
||||||
// add item to collection, if one was specified
|
|
||||||
if(collection) {
|
|
||||||
collection.addItem(dbItem.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.page.translate.setHandler("attachmentProgress", function(obj, attachment, progress, error) {
|
|
||||||
var itemProgress = attachmentsMap.get(attachment);
|
|
||||||
if(progress === false) {
|
|
||||||
itemProgress.setError();
|
|
||||||
} else {
|
|
||||||
itemProgress.setProgress(progress);
|
|
||||||
if(progress === 100) {
|
|
||||||
itemProgress.setIcon(Zotero.Utilities.determineAttachmentIcon(attachment));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.page.translate.translate(libraryID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns the URL of the image representing the translator to be called on the
|
* returns the URL of the image representing the translator to be called on the
|
||||||
* current page, or false if the page cannot be scraped
|
* current page, or false if the page cannot be scraped
|
||||||
|
|
|
@ -135,47 +135,21 @@ Zotero.MIMETypeHandler = new function () {
|
||||||
var frontWindow = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
|
var frontWindow = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
|
||||||
getService(Components.interfaces.nsIWindowWatcher).activeWindow;
|
getService(Components.interfaces.nsIWindowWatcher).activeWindow;
|
||||||
|
|
||||||
if (Zotero.locked) {
|
|
||||||
frontWindow.Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
|
||||||
var desc = Zotero.localeJoin([
|
|
||||||
Zotero.getString('general.operationInProgress'), Zotero.getString('general.operationInProgress.waitUntilFinishedAndTryAgain')
|
|
||||||
]);
|
|
||||||
frontWindow.Zotero_Browser.progress.addDescription(desc);
|
|
||||||
frontWindow.Zotero_Browser.progress.show();
|
|
||||||
frontWindow.Zotero_Browser.progress.startCloseTimer(8000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attempt to import through Zotero.Translate
|
// attempt to import through Zotero.Translate
|
||||||
var translation = new Zotero.Translate("import");
|
var translation = new Zotero.Translate("import");
|
||||||
translation.setLocation(uri);
|
translation.setLocation(uri);
|
||||||
translation.setString(string);
|
translation.setString(string);
|
||||||
|
|
||||||
frontWindow.Zotero_Browser.progress.show();
|
|
||||||
var libraryID = null;
|
|
||||||
var collection = null;
|
|
||||||
try {
|
|
||||||
libraryID = frontWindow.ZoteroPane.getSelectedLibraryID();
|
|
||||||
collection = frontWindow.ZoteroPane.getSelectedCollection();
|
|
||||||
} catch(e) {}
|
|
||||||
translation.setHandler("itemDone", function(obj, dbItem, item) {
|
|
||||||
frontWindow.Zotero_Browser.itemDone(obj, dbItem, item, collection);
|
|
||||||
});
|
|
||||||
translation.setHandler("done", function(obj, item) {
|
|
||||||
frontWindow.Zotero_Browser.finishScraping(obj, item, collection);
|
|
||||||
});
|
|
||||||
|
|
||||||
// attempt to retrieve translators
|
// attempt to retrieve translators
|
||||||
var translators = translation.getTranslators();
|
var translators = translation.getTranslators();
|
||||||
if(!translators.length) {
|
if(!translators.length) {
|
||||||
// we lied. we can't really translate this file.
|
// we lied. we can't really translate this file.
|
||||||
frontWindow.Zotero_Browser.progress.close();
|
|
||||||
throw "No translator found for handled RIS, Refer or ISI file"
|
throw "No translator found for handled RIS, Refer or ISI file"
|
||||||
}
|
}
|
||||||
|
|
||||||
// translate using first available
|
// translate using first available
|
||||||
translation.setTranslator(translators[0]);
|
translation.setTranslator(translators[0]);
|
||||||
translation.translate(libraryID);
|
frontWindow.Zotero_Browser.performTranslation(translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user