Allow use of relative paths for file import in non-RDF translators

This commit is contained in:
Simon Kornblith 2012-04-02 17:57:13 -04:00
parent 89d3f09682
commit c9354535da
2 changed files with 27 additions and 4 deletions

View file

@ -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 = [];
}

View file

@ -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;