diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index ae409e07b..7aa1f0ddc 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -20,8 +20,92 @@ ***** END LICENSE BLOCK ***** */ +/****Zotero_File_Exporter**** + ** + * A class to handle exporting of items, collections, or the entire library + **/ + +/** + * Constructs a new Zotero_File_Exporter with defaults + **/ +var Zotero_File_Exporter = function() { + this.name = Zotero.getString("fileInterface.exportedItems"); + this.collection = false; + this.items = false; +} + +/** + * Performs the actual export operation + **/ +Zotero_File_Exporter.prototype.save = function() { + var translation = new Zotero.Translate("export"); + var translators = translation.getTranslators(); + + // present options dialog + var io = {translators:translators} + window.openDialog("chrome://zotero/content/exportOptions.xul", + "_blank", "chrome,modal,centerscreen", io); + if(!io.selectedTranslator) { + return false; + } + + const nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(nsIFilePicker); + + fp.init(window, Zotero.getString("fileInterface.export"), nsIFilePicker.modeSave); + + // set file name and extension + if(io.selectedTranslator.displayOptions.exportFileData) { + // if the result will be a folder, don't append any extension or use + // filters + fp.defaultString = this.name; + } else { + // if the result will be a file, append an extension and use filters + fp.defaultString = this.name+"."+io.selectedTranslator.target; + fp.appendFilter(io.selectedTranslator.label, "*."+io.selectedTranslator.target); + } + + var rv = fp.show(); + if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { + if(this.collection) { + translation.setCollection(this.collection); + } else if(this.items) { + translation.setItems(this.items); + } + + translation.setLocation(fp.file); + translation.setTranslator(io.selectedTranslator); + translation.setHandler("done", this._exportDone); + Zotero.UnresponsiveScriptIndicator.disable(); + Zotero_File_Interface.Progress.show( + Zotero.getString("fileInterface.itemsExported"), + function() { + translation.translate(); + }); + } + return false; +} + +/* + * Closes the items exported indicator + */ +Zotero_File_Exporter.prototype._exportDone = function(obj, worked) { + Zotero_File_Interface.Progress.close(); + Zotero.UnresponsiveScriptIndicator.enable(); + + if(!worked) { + window.alert(Zotero.getString("fileInterface.exportError")); + } +} + +/****Zotero_File_Interface**** + ** + * A singleton to interface with ZoteroPane to provide export/bibliography + * capabilities + **/ var Zotero_File_Interface = new function() { - var _unresponsiveScriptPreference, _importCollection, _notifyItem, _notifyCollection; + var _importCollection, _unlock; this.exportFile = exportFile; this.exportCollection = exportCollection; @@ -33,65 +117,36 @@ var Zotero_File_Interface = new function() { /* * Creates Zotero.Translate instance and shows file picker for file export */ - function exportFile(name, items) { - var translation = new Zotero.Translate("export"); - var translators = translation.getTranslators(); - - // present options dialog - var io = {translators:translators} - window.openDialog("chrome://zotero/content/exportOptions.xul", - "_blank", "chrome,modal,centerscreen", io); - if(!io.selectedTranslator) { - return false; - } - - const nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(nsIFilePicker); - - fp.init(window, Zotero.getString("fileInterface.export"), nsIFilePicker.modeSave); - - // set file name and extension - name = (name ? name : Zotero.getString("pane.collections.library")); - if(io.selectedTranslator.displayOptions.exportFileData) { - // if the result will be a folder, don't append any extension or use - // filters - fp.defaultString = name; - } else { - // if the result will be a file, append an extension and use filters - fp.defaultString = name+"."+io.selectedTranslator.target; - fp.appendFilter(io.selectedTranslator.label, "*."+io.selectedTranslator.target); - } - - var rv = fp.show(); - if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { - if(items) { - translation.setItems(items); - } - translation.setLocation(fp.file); - translation.setTranslator(io.selectedTranslator); - translation.setHandler("done", _exportDone); - _disableUnresponsive(); - Zotero_File_Interface.Progress.show( - Zotero.getString("fileInterface.itemsExported"), - function() { - translation.translate(); - }); - } - return false; + function exportFile() { + var exporter = new Zotero_File_Exporter(); + exporter.name = Zotero.getString("pane.collections.library"); + exporter.save(); } /* * exports a collection or saved search */ function exportCollection() { - var nameAndItems = _getSortedSelectedCollection(); - if(nameAndItems) { - exportFile(nameAndItems[0], nameAndItems[1]); - return; + var exporter = new Zotero_File_Exporter(); + + var collection = ZoteroPane.getSelectedCollection(); + if(collection) { + exporter.name = collection.getName(); + exporter.collection = collection; + } else { + // find sorted items + exporter.items = ZoteroPane.getSortedItems(); + if(!exporter.items) throw ("No items to save"); + + // find name + var searchRef = ZoteroPane.getSelectedSavedSearch(); + if(searchRef) { + var search = new Zotero.Search(); + search.load(searchRef['id']); + exporter.name = search.getName(); + } } - - throw ("No collection or saved search currently selected"); + exporter.save(); } @@ -99,49 +154,12 @@ var Zotero_File_Interface = new function() { * exports items */ function exportItems() { - var items = ZoteroPane.getSelectedItems(); - if(!items || !items.length) throw("no items currently selected"); + var exporter = new Zotero_File_Exporter(); - exportFile(Zotero.getString("fileInterface.exportedItems"), items); - } - - /* - * gets selected collection or saved search sorted - */ - function _getSortedSelectedCollection() { - var name = false; - var items = false; + exporter.items = ZoteroPane.getSelectedItems(); + if(!exporter.items || !exporter.items.length) throw("no items currently selected"); - var collection = ZoteroPane.getSelectedCollection(); - if (collection) { - name = collection.getName(); - items = Zotero.getItems(collection.getID()); - } else { - var searchRef = ZoteroPane.getSelectedSavedSearch(); - if (searchRef) { - var search = new Zotero.Search(); - search.load(searchRef['id']); - name = search.getName(); - items = Zotero.Items.get(search.search()); - } - } - - if(items) { - return [name, items]; - } - return false; - } - - /* - * closes items exported indicator - */ - function _exportDone(obj, worked) { - Zotero_File_Interface.Progress.close(); - _restoreUnresponsive(); - - if(!worked) { - window.alert(Zotero.getString("fileInterface.exportError")); - } + exporter.save(); } /* @@ -175,15 +193,15 @@ var Zotero_File_Interface = new function() { translation.setTranslator(translators[0]); translation.setHandler("collectionDone", _importCollectionDone); translation.setHandler("done", _importDone); - _disableUnresponsive(); - - // disable notifier - Zotero.Notifier.disable(); + Zotero.UnresponsiveScriptIndicator.disable(); // show progress indicator Zotero_File_Interface.Progress.show( Zotero.getString("fileInterface.itemsImported"), function() { + // disable notifier + _unlock = Zotero.Notifier.begin(true); + // translate translation.translate(); }); } else { @@ -198,10 +216,7 @@ var Zotero_File_Interface = new function() { * collections */ function _importCollectionDone(obj, collection) { - Zotero.Notifier.enable(); - Zotero.Notifier.trigger("add", "collection", collection.getID()); collection.changeParent(_importCollection.getID()); - Zotero.Notifier.disable(); } /* @@ -213,51 +228,43 @@ var Zotero_File_Interface = new function() { _importCollection.addItem(itemID); } - // run notify - Zotero.Notifier.enable(); - if(obj.newItems.length) { - Zotero.Notifier.trigger("add", "item", obj.newItems); - Zotero.Notifier.trigger("modify", "collection", _importCollection.getID()); - } + // notify + Zotero.Notifier.commit(_unlock); Zotero_File_Interface.Progress.close(); - _restoreUnresponsive(); + Zotero.UnresponsiveScriptIndicator.enable(); if(!worked) { window.alert(Zotero.getString("fileInterface.importError")); } } - /* - * disables the "unresponsive script" warning; necessary for import and - * export, which can take quite a while to execute - */ - function _disableUnresponsive() { - var prefService = Components.classes["@mozilla.org/preferences-service;1"]. - getService(Components.interfaces.nsIPrefBranch); - _unresponsiveScriptPreference = prefService.getIntPref("dom.max_chrome_script_run_time"); - prefService.setIntPref("dom.max_chrome_script_run_time", 0); - } - - /* - * restores the "unresponsive script" warning - */ - function _restoreUnresponsive() { - var prefService = Components.classes["@mozilla.org/preferences-service;1"]. - getService(Components.interfaces.nsIPrefBranch); - prefService.setIntPref("dom.max_chrome_script_run_time", _unresponsiveScriptPreference); - } - /* * Creates a bibliography from a collection or saved search */ function bibliographyFromCollection() { - var nameAndItems = _getSortedSelectedCollection(); - if(nameAndItems) { - _doBibliographyOptions(nameAndItems[0], nameAndItems[1]); - return; + // find sorted items + var items = Zotero.Items.get(ZoteroPane.getSortedItems()); + if(!items) return; + + // find name + var name = false; + + var collection = ZoteroPane.getSelectedCollection(); + if(collection) { + name = collection.getName(); + } else { + var searchRef = ZoteroPane.getSelectedSavedSearch(); + if(searchRef) { + var search = new Zotero.Search(); + search.load(searchRef['id']); + name = search.getName(); + } } + _doBibliographyOptions(name, items); + return; + throw ("No collection or saved search currently selected"); } diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 52bf62a23..9764d8caf 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -949,8 +949,8 @@ Zotero.CSL.prototype._compareItem = function(a, b, opt) { this._getFieldValue(sortElement.name, sortElement, b, formattedStringB, this._bib); - var aValue = formattedStringA.get(); - var bValue = formattedStringB.get(); + var aValue = formattedStringA.get().toLowerCase(); + var bValue = formattedStringB.get().toLowerCase(); if(bValue > aValue) { return -1; diff --git a/chrome/content/zotero/xpcom/ingester.js b/chrome/content/zotero/xpcom/ingester.js index c1cc175aa..c9103fe75 100644 --- a/chrome/content/zotero/xpcom/ingester.js +++ b/chrome/content/zotero/xpcom/ingester.js @@ -567,6 +567,8 @@ Zotero.OpenURL = new function() { item.tags.push(value); } else if(key == "rft.type") { if(Zotero.ItemTypes.getID(value)) item.itemType = value; + } else if(key == "rft.source") { + item.publicationTitle = value; } } } diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index b86e0db63..ac9c6bf78 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -233,12 +233,19 @@ Zotero.Translate.prototype.setSearch = function(search) { } /* - * sets the item to be used for export + * sets the items to be used for export */ Zotero.Translate.prototype.setItems = function(items) { this.items = items; } +/* + * sets the collection to be used for export (overrides setItems) + */ +Zotero.Translate.prototype.setCollection = function(collection) { + this.collection = collection; +} + /* * sets the location to operate upon (file should be an nsILocalFile object or * web address) @@ -357,12 +364,6 @@ Zotero.Translate.prototype.setTranslator = function(translator) { * returns: a numerically indexed array of ids, as extracted from the passed * string * - * itemCount - * valid: export - * called: when the export - * passed: the number of items to be processed - * returns: N/A - * * itemDone * valid: import, web, search * called: when an item has been processed; may be called asynchronously @@ -932,17 +933,6 @@ Zotero.Translate.prototype._translationComplete = function(returnValue, error) { // close open streams this._closeStreams(); - if(Zotero.Notifier.isEnabled()) { - // notify itemTreeView about updates - if(this.newItems.length) { - Zotero.Notifier.trigger("add", "item", this.newItems); - } - // notify collectionTreeView about updates - if(this.newCollections && this.newCollections.length) { - Zotero.Notifier.trigger("add", "collection", this.newCollections); - } - } - if(!returnValue) { var errorString = this._generateErrorString(error); this._debug("Translation using "+this.translator[0].label+" failed: \n"+errorString); @@ -1012,9 +1002,11 @@ Zotero.Translate.prototype._closeStreams = function() { } try { - var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]. - getService(Components.interfaces.nsIRDFService); - rdfService.UnregisterDataSource(this._rdf.dataSource); + if(this._rdf.dataSource) { + var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]. + getService(Components.interfaces.nsIRDFService); + rdfService.UnregisterDataSource(this._rdf.dataSource); + } } catch(e) {} delete this._rdf.dataSource; @@ -1094,265 +1086,243 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) { return; } - if(!attachedTo) { - var notifierStatus = Zotero.Notifier.isEnabled(); - if(notifierStatus) { - Zotero.Notifier.disable(); - } - } + // Get typeID, defaulting to "webpage" + var type = (item.itemType ? item.itemType : "webpage"); - try { // make sure notifier gets turned back on when done - // Get typeID, defaulting to "webpage" - var type = (item.itemType ? item.itemType : "webpage"); + if(type == "note") { // handle notes differently + var myID = Zotero.Notes.add(item.note); + // re-retrieve the item + var newItem = Zotero.Items.get(myID); + } else { + if(!item.title && this.type == "web") { + throw("item has no title"); + } - if(type == "note") { // handle notes differently - var myID = Zotero.Notes.add(item.note); - // re-retrieve the item - var newItem = Zotero.Items.get(myID); - } else { - if(!item.title && this.type == "web") { - throw("item has no title"); + // if item was accessed through a proxy, ensure that the proxy + // address remains in the accessed version + if(this.locationIsProxied && item.url) { + item.url = Zotero.Ingester.ProxyMonitor.properToProxy(item.url); + } + + // create new item + if(type == "attachment") { + if(this.type != "import") { + Zotero.debug("discarding standalone attachment"); + return; } - // if item was accessed through a proxy, ensure that the proxy - // address remains in the accessed version - if(this.locationIsProxied && item.url) { - item.url = Zotero.Ingester.ProxyMonitor.properToProxy(item.url); - } + Zotero.debug("adding attachment"); - // create new item - if(type == "attachment") { - if(this.type != "import") { - Zotero.debug("discarding standalone attachment"); - return; - } - - Zotero.debug("adding attachment"); - - if(!item.path) { - // create from URL - if(item.url) { - var myID = Zotero.Attachments.linkFromURL(item.url, attachedTo, - (item.mimeType ? item.mimeType : undefined), - (item.title ? item.title : undefined)); - Zotero.debug("created attachment; id is "+myID); - if(!myID) { - // if we didn't get an ID, don't continue adding - // notes, because we can't without knowing the ID - return; - } - var newItem = Zotero.Items.get(myID); - } else { - Zotero.debug("not adding attachment: no path or url specified"); + if(!item.path) { + // create from URL + if(item.url) { + var myID = Zotero.Attachments.linkFromURL(item.url, attachedTo, + (item.mimeType ? item.mimeType : undefined), + (item.title ? item.title : undefined)); + Zotero.debug("created attachment; id is "+myID); + if(!myID) { + // if we didn't get an ID, don't continue adding + // notes, because we can't without knowing the ID return; } + var newItem = Zotero.Items.get(myID); } else { - // generate nsIFile - var IOService = Components.classes["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService); - var uri = IOService.newURI(item.path, "", null); - var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; - - if(item.url) { - // import from nsIFile - var myID = Zotero.Attachments.importSnapshotFromFile(file, - item.url, item.title, item.mimeType, - (item.charset ? item.charset : null), attachedTo); - var newItem = Zotero.Items.get(myID); + Zotero.debug("not adding attachment: no path or url specified"); + return; + } + } else { + // generate nsIFile + var IOService = Components.classes["@mozilla.org/network/io-service;1"]. + getService(Components.interfaces.nsIIOService); + var uri = IOService.newURI(item.path, "", null); + var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; + + if(item.url) { + // import from nsIFile + var myID = Zotero.Attachments.importSnapshotFromFile(file, + item.url, item.title, item.mimeType, + (item.charset ? item.charset : null), attachedTo); + var newItem = Zotero.Items.get(myID); + } else { + // import from nsIFile + var myID = Zotero.Attachments.importFromFile(file, attachedTo); + // get attachment item + var newItem = Zotero.Items.get(myID); + } + } + + var typeID = Zotero.ItemTypes.getID("attachment"); + + // add note if necessary + if(item.note) { + newItem.updateNote(item.note); + } + } else { + var typeID = Zotero.ItemTypes.getID(type); + var newItem = Zotero.Items.getNewItemByType(typeID); + } + + // makes looping through easier + item.itemType = item.complete = undefined; + + // automatically set access date if URL is set + if(item.url && !item.accessDate && this.type == "web") { + item.accessDate = "CURRENT_TIMESTAMP"; + } + + var fieldID, data; + for(var field in item) { + // loop through item fields + data = item[field]; + + if(data) { // if field has content + if(field == "creators") { // creators are a special case + for(var j in data) { + var creatorType = 1; + // try to assign correct creator type + if(data[j].creatorType) { + try { + var creatorType = Zotero.CreatorTypes.getID(data[j].creatorType); + } catch(e) { + Zotero.debug("invalid creator type "+data[j].creatorType+" for creator index "+j); + } + } + + newItem.setCreator(j, data[j].firstName, data[j].lastName, creatorType); + } + } else if(field == "title") { // skip checks for title + newItem.setField(field, data); + } else if(field == "seeAlso") { + newItem.translateSeeAlso = data; + } else if(field != "note" && field != "notes" && field != "itemID" && + field != "attachments" && field != "tags" && + (fieldID = Zotero.ItemFields.getID(field))) { + // if field is in db + if(Zotero.ItemFields.isValidForType(fieldID, typeID)) { + // if field is valid for this type + // add field + newItem.setField(field, data); } else { - // import from nsIFile - var myID = Zotero.Attachments.importFromFile(file, attachedTo); - // get attachment item - var newItem = Zotero.Items.get(myID); - } - } - - var typeID = Zotero.ItemTypes.getID("attachment"); - - // add note if necessary - if(item.note) { - newItem.updateNote(item.note); - } - } else { - var typeID = Zotero.ItemTypes.getID(type); - var newItem = Zotero.Items.getNewItemByType(typeID); - } - - // makes looping through easier - item.itemType = item.complete = undefined; - - // automatically set access date if URL is set - if(item.url && !item.accessDate && this.type == "web") { - item.accessDate = "CURRENT_TIMESTAMP"; - } - - var fieldID, field; - for(var i in item) { - // loop through item fields - data = item[i]; - - if(data) { // if field has content - if(i == "creators") { // creators are a special case - for(var j in data) { - var creatorType = 1; - // try to assign correct creator type - if(data[j].creatorType) { - try { - var creatorType = Zotero.CreatorTypes.getID(data[j].creatorType); - } catch(e) { - Zotero.debug("invalid creator type "+data[j].creatorType+" for creator index "+j); - } - } - - newItem.setCreator(j, data[j].firstName, data[j].lastName, creatorType); - } - } else if(i == "title") { // skip checks for title - newItem.setField(i, data); - } else if(i == "seeAlso") { - newItem.translateSeeAlso = data; - } else if(i != "note" && i != "notes" && i != "itemID" && - i != "attachments" && i != "tags" && - (fieldID = Zotero.ItemFields.getID(i))) { - // if field is in db - if(Zotero.ItemFields.isValidForType(fieldID, typeID)) { - // if field is valid for this type - // add field - newItem.setField(i, data); - } else { - Zotero.debug("discarded field "+i+" for item: field not valid for type "+type); - } + Zotero.debug("discarded field "+field+" for item: field not valid for type "+type); } } } - - // save item - if(myID) { - newItem.save(); - } else { - var myID = newItem.save(); - if(myID == true || !myID) { - myID = newItem.getID(); - } + } + + // save item + if(myID) { + newItem.save(); + } else { + var myID = newItem.save(); + if(myID == true || !myID) { + myID = newItem.getID(); } - - // handle notes - if(item.notes) { - for each(var note in item.notes) { - var noteID = Zotero.Notes.add(note.note, myID); - - // handle see also - var myNote = Zotero.Items.get(noteID); - this._itemTagsAndSeeAlso(note, myNote); - } + } + + // handle notes + if(item.notes) { + for each(var note in item.notes) { + var noteID = Zotero.Notes.add(note.note, myID); + + // handle see also + var myNote = Zotero.Items.get(noteID); + this._itemTagsAndSeeAlso(note, myNote); } - - // handle abstract - if(item.abstractNote) { - Zotero.Notes.add(item.abstractNote, myID, true); - } - - // handle attachments - if(item.attachments && Zotero.Prefs.get("automaticSnapshots")) { - Zotero.debug("HANDLING ATTACHMENTS"); - for each(var attachment in item.attachments) { - if(this.type == "web") { - if(!attachment.url && !attachment.document) { - Zotero.debug("not adding attachment: no URL specified"); - } else { - if(attachment.document - || (attachment.mimeType && attachment.mimeType == "text/html") - || Zotero.Prefs.get("downloadAssociatedFiles")) { - if(attachment.document) { - Zotero.Attachments.importFromDocument(attachment.document, myID, attachment.title); - } else { - Zotero.debug("GOT ATTACHMENT"); - Zotero.debug(attachment); - - var mimeType = null; - var title = null; - - if(attachment.mimeType) { - // first, try to extract mime type from mimeType attribute - mimeType = attachment.mimeType; - } else if(attachment.document && attachment.document.contentType) { - // if that fails, use document if possible - mimeType = attachment.document.contentType - } - - // same procedure for title as mime type - if(attachment.title) { - title = attachment.title; - } else if(attachment.document && attachment.document.title) { - title = attachment.document.title; - } - - if(this.locationIsProxied) { - attachment.url = Zotero.Ingester.ProxyMonitor.properToProxy(attachment.url); - } - - Zotero.Attachments.importFromURL(attachment.url, myID, title); - } - } - // links no longer exist, so just don't save them - /*if(attachment.document) { - attachmentID = Zotero.Attachments.linkFromURL(attachment.document.location.href, myID, - (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), - (attachment.title ? attachment.title : attachment.document.title)); + } + + // handle abstract + if(item.abstractNote) { + Zotero.Notes.add(item.abstractNote, myID, true); + } + + // handle attachments + if(item.attachments && Zotero.Prefs.get("automaticSnapshots")) { + Zotero.debug("HANDLING ATTACHMENTS"); + for each(var attachment in item.attachments) { + if(this.type == "web") { + if(!attachment.url && !attachment.document) { + Zotero.debug("not adding attachment: no URL specified"); + } else { + if(attachment.document + || (attachment.mimeType && attachment.mimeType == "text/html") + || Zotero.Prefs.get("downloadAssociatedFiles")) { + if(attachment.document) { + Zotero.Attachments.importFromDocument(attachment.document, myID, attachment.title); } else { - if(!attachment.mimeType || attachment.title) { - Zotero.debug("notice: either mimeType or title is missing; attaching file will be slower"); + Zotero.debug("GOT ATTACHMENT"); + Zotero.debug(attachment); + + var mimeType = null; + var title = null; + + if(attachment.mimeType) { + // first, try to extract mime type from mimeType attribute + mimeType = attachment.mimeType; + } else if(attachment.document && attachment.document.contentType) { + // if that fails, use document if possible + mimeType = attachment.document.contentType } - attachmentID = Zotero.Attachments.linkFromURL(attachment.url, myID, - (attachment.mimeType ? attachment.mimeType : undefined), - (attachment.title ? attachment.title : undefined)); - }*/ + // same procedure for title as mime type + if(attachment.title) { + title = attachment.title; + } else if(attachment.document && attachment.document.title) { + title = attachment.document.title; + } + + if(this.locationIsProxied) { + attachment.url = Zotero.Ingester.ProxyMonitor.properToProxy(attachment.url); + } + + Zotero.Attachments.importFromURL(attachment.url, myID, title); + } } - } else if(this.type == "import") { - // create new attachments attached here - this._itemDone(attachment, myID); + // links no longer exist, so just don't save them + /*if(attachment.document) { + attachmentID = Zotero.Attachments.linkFromURL(attachment.document.location.href, myID, + (attachment.mimeType ? attachment.mimeType : attachment.document.contentType), + (attachment.title ? attachment.title : attachment.document.title)); + } else { + if(!attachment.mimeType || attachment.title) { + Zotero.debug("notice: either mimeType or title is missing; attaching file will be slower"); + } + + attachmentID = Zotero.Attachments.linkFromURL(attachment.url, myID, + (attachment.mimeType ? attachment.mimeType : undefined), + (attachment.title ? attachment.title : undefined)); + }*/ } + } else if(this.type == "import") { + // create new attachments attached here + this._itemDone(attachment, myID); } } } - - if(item.itemID) { - this._IDMap[item.itemID] = myID; - } - if(!attachedTo) { - this.newItems.push(myID); - } - - // handle see also - if(item.seeAlso) { - for each(var seeAlso in item.seeAlso) { - if(this._IDMap[seeAlso]) { - newItem.addSeeAlso(this._IDMap[seeAlso]); - } - } - } - - if(item.tags) { - for each(var tag in item.tags) { - newItem.addTag(tag); - } - } - - delete item; - } catch(e) { - if(notifierStatus) { - Zotero.Notifier.enable(); - } - throw(e); } - // only re-enable if notifier was enabled at the beginning of scraping - if(!attachedTo) { - if(notifierStatus) { - Zotero.Notifier.enable(); - } - this._runHandler("itemDone", newItem); + if(item.itemID) { + this._IDMap[item.itemID] = myID; } + if(!attachedTo) { + this.newItems.push(myID); + } + + // handle see also + if(item.seeAlso) { + for each(var seeAlso in item.seeAlso) { + if(this._IDMap[seeAlso]) { + newItem.addSeeAlso(this._IDMap[seeAlso]); + } + } + } + + if(item.tags) { + for each(var tag in item.tags) { + newItem.addTag(tag); + } + } + + delete item; } /* @@ -1708,19 +1678,32 @@ Zotero.Translate.prototype._importDefuseBOM = function() { */ Zotero.Translate.prototype._export = function() { - // get items if(this.items) { + // if just items, get them and don't worry about collection logic this._itemsLeft = this.items; + } else if(this.collection) { + Zotero.debug("using collection"); + Zotero.debug(this.collection); + + // get items in this collection + this._itemsLeft = Zotero.getItems(this.collection.getID()); + + if(this._configOptions.getCollections) { + // get child collections + this._collectionsLeft = Zotero.getCollections(this.collection.getID(), true); + // get items in child collections + for each(var collection in this._collectionsLeft) { + this._itemsLeft = this._itemsLeft.concat(Zotero.getItems(collection.getID())); + } + } } else { + // get all items this._itemsLeft = Zotero.getItems(); - } - - // run handler for items available - this._runHandler("itemCount", this._itemsLeft.length); - - // get collections, if requested - if(this._configOptions.getCollections && !this.items) { - this._collectionsLeft = Zotero.getCollections(); + + if(this._configOptions.getCollections) { + // get all collections + this._collectionsLeft = Zotero.getCollections(); + } } Zotero.debug(this._displayOptions); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index c50b4cb86..1cdb46cd6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1252,6 +1252,9 @@ Zotero.Date = new function(){ } } +/** + * Functions for creating and destroying hidden browser objects + **/ Zotero.Browser = new function() { this.createHiddenBrowser = createHiddenBrowser; this.deleteHiddenBrowser = deleteHiddenBrowser; @@ -1279,6 +1282,44 @@ Zotero.Browser = new function() { } } +/** + * Functions for disabling and enabling the unresponsive script indicator + **/ +Zotero.UnresponsiveScriptIndicator = new function() { + this.disable = disable; + this.enable = enable; + + // stores the state of the unresponsive script preference prior to disabling + var _unresponsiveScriptPreference, _isDisabled; + + /** + * disables the "unresponsive script" warning; necessary for import and + * export, which can take quite a while to execute + **/ + function disable() { + // don't do anything if already disabled + if(_isDisabled) return; + + var prefService = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + _unresponsiveScriptPreference = prefService.getIntPref("dom.max_chrome_script_run_time"); + prefService.setIntPref("dom.max_chrome_script_run_time", 0); + + _isDisabled = true; + } + + /** + * restores the "unresponsive script" warning + **/ + function enable() { + var prefService = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + prefService.setIntPref("dom.max_chrome_script_run_time", _unresponsiveScriptPreference); + + _isDisabled = false; + } +} + /* * Implements nsIWebProgressListener diff --git a/scrapers.sql b/scrapers.sql index 22998e8d3..8631f497d 100644 --- a/scrapers.sql +++ b/scrapers.sql @@ -1,4 +1,4 @@ --- 167 +-- 168 -- ***** BEGIN LICENSE BLOCK ***** -- @@ -22,7 +22,7 @@ -- Set the following timestamp to the most recent scraper update date -REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-01-24 01:35:00')); +REPLACE INTO version VALUES ('repository', STRFTIME('%s', '2007-01-26 20:43:00')); REPLACE INTO translators VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '1.0.0b3.r1', '', '2006-12-15 03:40:00', 1, 100, 4, 'Amazon.com', 'Sean Takats', '^https?://(?:www\.)?amazon', 'function detectWeb(doc, url) { @@ -4798,7 +4798,7 @@ REPLACE INTO translators VALUES ('cb48083-4d9-4ed-ac95-2e93dceea0ec', '1.0.0b3.r Zotero.wait(); }'); -REPLACE INTO translators VALUES ('f8765470-5ace-4a31-b4bd-4327b960ccd', '1.0.0b3.r1', '', '2006-12-16 01:02:00', 1, 100, 4, 'SpringerLink', 'Simon Kornblith', '^http://www\.springerlink\.com/content/', +REPLACE INTO translators VALUES ('f8765470-5ace-4a31-b4bd-4327b960ccd', '1.0.0b3.r1', '', '2007-01-26 20:43:00', 1, 100, 4, 'SpringerLink', 'Simon Kornblith', '^http://www\.springerlink\.com/content/', 'function detectWeb(doc, url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { @@ -4809,7 +4809,7 @@ REPLACE INTO translators VALUES ('f8765470-5ace-4a31-b4bd-4327b960ccd', '1.0.0b3 return "multiple"; } else if(doc.title == "SpringerLink - Book Chapter") { return "bookSection"; - } else if(doc.evaluate(''//a[@id="_ctl0_PageSidebar__ctl1_Sidebarplaceholder1__ctl1_ExportRisLink"]'', + } else if(doc.evaluate(''//a[text() = "RIS"]'', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) { return "journalArticle"; } @@ -4881,7 +4881,7 @@ REPLACE INTO translators VALUES ('f8765470-5ace-4a31-b4bd-4327b960ccd', '1.0.0b3 Zotero.wait(); }'); -REPLACE INTO translators VALUES ('6614a99-479a-4524-8e30-686e4d66663e', '1.0.0b3.r1', '', '2006-12-16 04:13:00', 1, 100, 4, 'Nature', 'Simon Kornblith', '^http://www\.nature\.com/(?:[^/]+/journal/v[^/]+/n[^/]+/(?:(?:full|abs)/.+\.html|index.html)|search/executeSearch)', +REPLACE INTO translators VALUES ('6614a99-479a-4524-8e30-686e4d66663e', '1.0.0b3.r1', '', '2007-01-26 20:43:00', 1, 100, 4, 'Nature', 'Simon Kornblith', '^http://www\.nature\.com/(?:[^/]+/journal/v[^/]+/n[^/]+/(?:(?:full|abs)/.+\.html|index.html)|search/executeSearch)', 'function detectWeb(doc, url) { var articleRe = /(https?:\/\/[^\/]+\/[^\/]+\/journal\/v[^\/]+\/n[^\/]+\/)(full|abs)(\/.+\.)html/; @@ -4911,7 +4911,7 @@ REPLACE INTO translators VALUES ('6614a99-479a-4524-8e30-686e4d66663e', '1.0.0b3 if (prefix == ''x'') return namespace; else return null; } : null; - var articleRe = /(https?:\/\/[^\/]+\/[^\/]+\/journal\/v[^\/]+\/n[^\/]+\/)(full|abs)(\/.+\.)html/; + var articleRe = /(https?:\/\/[^\/]+\/[^\/]+\/journal\/v[^\/]+\/n[^\/]+\/)(full|abs)(\/.+)\.html/; var m = articleRe.exec(url); if(!m) { @@ -4943,7 +4943,10 @@ REPLACE INTO translators VALUES ('6614a99-479a-4524-8e30-686e4d66663e', '1.0.0b3 for each(var item in urls) { var m = articleRe.exec(item); - RIS.push(m[1]+"ris"+m[3]+"ris"); + if(m[3][m[3].length-2] == "_") { + m[3] = m[3].substr(0, m[3].length-2); + } + RIS.push(m[1]+"ris"+m[3]+".ris"); regexps.push(m); } @@ -4958,7 +4961,7 @@ REPLACE INTO translators VALUES ('6614a99-479a-4524-8e30-686e4d66663e', '1.0.0b3 var m = regexps.shift(); item.attachments = [ {url:m[0], title:"Nature Snapshot", mimeType:"text/html"}, - {url:m[1]+"pdf"+m[3]+"pdf", title:"Nature Full Text PDF", mimeType:"application/pdf"} + {url:m[1]+"pdf"+m[3]+".pdf", title:"Nature Full Text PDF", mimeType:"application/pdf"} ] item.notes = new Array(); @@ -7769,7 +7772,7 @@ REPLACE INTO translators VALUES ('6e372642-ed9d-4934-b5d1-c11ac758ebb7', '1.0.0b } }'); -REPLACE INTO translators VALUES ('5e3ad958-ac79-463d-812b-a86a9235c28f', '1.0.0b3.r1', '', '2006-12-15 14:39:00', 1, 100, 1, 'RDF', 'Simon Kornblith', 'rdf', +REPLACE INTO translators VALUES ('5e3ad958-ac79-463d-812b-a86a9235c28f', '1.0.0b3.r1', '', '2007-01-26 20:43:00', 1, 100, 1, 'RDF', 'Simon Kornblith', 'rdf', 'Zotero.configure("dataMode", "rdf"); function detectImport() { @@ -8267,7 +8270,7 @@ function importItem(newItem, node, type) { for each(var relation in relations) { var type = Zotero.RDF.getTargets(relation, rdf+"type"); if(Zotero.RDF.getResourceURI(type[0]) == n.fs+"Attachment") { - var attachment = new Object(); + var attachment = new Zotero.Item(); newItem.attachments.push(attachment); importItem(attachment, relation, n.fs+"Attachment"); } @@ -8304,7 +8307,6 @@ function doImport() { // figure out if this is a part of another resource, or a linked // attachment if(Zotero.RDF.getSources(node, n.dcterms+"isPartOf") || - Zotero.RDF.getSources(node, n.dcterms+"hasPart") || Zotero.RDF.getSources(node, n.bib+"presentedAt") || Zotero.RDF.getSources(node, n.link+"link")) { continue; @@ -8318,7 +8320,7 @@ function doImport() { // skip if this is not an independent attachment, if((type == n.fs+"Attachment" || type == n.bib+"Memo") && isPart(node)) { continue; - } else if(type == n.bib+"Collection") { + } else if(type == n.bib+"Collection" || type == n.fs+"Collection") { // skip collections until all the items are done collections.push(node); continue;