commit c9354535da1a4117a7413e441caf5149c644f46b
parent 89d3f096828ce8f2321ea9b1fa5ded03bcf3dd88
Author: Simon Kornblith <simon@simonster.com>
Date: Mon, 2 Apr 2012 17:57:13 -0400
Allow use of relative paths for file import in non-RDF translators
Diffstat:
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -1450,7 +1450,7 @@ Zotero.Translate.Web.prototype._getParameters = function() { return [this.docume
Zotero.Translate.Web.prototype._prepareTranslation = function() {
this._itemSaver = new Zotero.Translate.ItemSaver(this._libraryID,
Zotero.Translate.ItemSaver[(this._saveAttachments ? "ATTACHMENT_MODE_DOWNLOAD" : "ATTACHMENT_MODE_IGNORE")], 1,
- this.document, this._cookieSandbox);
+ this.document, this._cookieSandbox, this.location);
this.newItems = [];
}
@@ -1672,8 +1672,18 @@ Zotero.Translate.Import.prototype._loadTranslatorPrepareIO = function(translator
*/
Zotero.Translate.Import.prototype._prepareTranslation = function() {
this._progress = undefined;
+
+ var baseURI = null;
+ if(this.location) {
+ try {
+ baseURI = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService).newFileURI(this.location);
+ } catch(e) {}
+ }
+
this._itemSaver = new Zotero.Translate.ItemSaver(this._libraryID,
- Zotero.Translate.ItemSaver[(this._saveAttachments ? "ATTACHMENT_MODE_FILE" : "ATTACHMENT_MODE_IGNORE")]);
+ Zotero.Translate.ItemSaver[(this._saveAttachments ? "ATTACHMENT_MODE_FILE" : "ATTACHMENT_MODE_IGNORE")],
+ undefined, undefined, undefined, baseURI);
this.newItems = [];
this.newCollections = [];
}
diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js
@@ -24,7 +24,7 @@
*/
Zotero.Translate.ItemSaver = function(libraryID, attachmentMode, forceTagType, document,
- cookieSandbox) {
+ cookieSandbox, baseURI) {
// initialize constants
this.newItems = [];
this.newCollections = [];
@@ -66,7 +66,20 @@ Zotero.Translate.ItemSaver = function(libraryID, attachmentMode, forceTagType, d
// force tag types if requested
this._forceTagType = forceTagType;
+ // to set cookies on downloaded files
this._cookieSandbox = cookieSandbox;
+
+ // the URI to which other URIs are assumed to be relative
+ if(typeof baseURI === "object" && baseURI instanceof Components.interfaces.nsIURI) {
+ this._baseURI = baseURI;
+ } else {
+ // try to convert to a URI
+ this._baseURI = null;
+ try {
+ this._baseURI = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService).newURI(baseURI, null, null);
+ } catch(e) {};
+ }
};
Zotero.Translate.ItemSaver.ATTACHMENT_MODE_IGNORE = 0;
@@ -231,7 +244,7 @@ Zotero.Translate.ItemSaver.prototype = {
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
try {
- var uri = IOService.newURI(attachment.path, "", null);
+ var uri = IOService.newURI(attachment.path, "", this._baseURI);
}
catch (e) {
var msg = "Error parsing attachment path: " + attachment.path;