Update mimeTypeHandler for asynchronous getTranslators
This commit is contained in:
parent
f58a5ed298
commit
b16bfc80e1
1 changed files with 35 additions and 36 deletions
|
@ -145,15 +145,16 @@ Zotero.MIMETypeHandler = new function () {
|
||||||
translation.setString(string);
|
translation.setString(string);
|
||||||
|
|
||||||
// attempt to retrieve translators
|
// attempt to retrieve translators
|
||||||
var translators = translation.getTranslators();
|
return translation.getTranslators().then(function(translators) {
|
||||||
if(!translators.length) {
|
if(!translators.length) {
|
||||||
// we lied. we can't really translate this file.
|
// we lied. we can't really translate this file.
|
||||||
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]);
|
||||||
frontWindow.Zotero_Browser.performTranslation(translation);
|
frontWindow.Zotero_Browser.performTranslation(translation);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,7 +269,7 @@ Zotero.MIMETypeHandler = new function () {
|
||||||
if (!this._storageStream) {
|
if (!this._storageStream) {
|
||||||
this._storageStream = Components.classes["@mozilla.org/storagestream;1"].
|
this._storageStream = Components.classes["@mozilla.org/storagestream;1"].
|
||||||
createInstance(Components.interfaces.nsIStorageStream);
|
createInstance(Components.interfaces.nsIStorageStream);
|
||||||
this._storageStream.init(4096, 4294967295, null); // PR_UINT32_MAX
|
this._storageStream.init(16384, 4294967295, null); // PR_UINT32_MAX
|
||||||
this._outputStream = this._storageStream.getOutputStream(0);
|
this._outputStream = this._storageStream.getOutputStream(0);
|
||||||
|
|
||||||
this._binaryInputStream = Components.classes["@mozilla.org/binaryinputstream;1"].
|
this._binaryInputStream = Components.classes["@mozilla.org/binaryinputstream;1"].
|
||||||
|
@ -291,38 +292,36 @@ Zotero.MIMETypeHandler = new function () {
|
||||||
const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER;
|
const replacementChar = Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER;
|
||||||
var convStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
|
var convStream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
|
||||||
.createInstance(Components.interfaces.nsIConverterInputStream);
|
.createInstance(Components.interfaces.nsIConverterInputStream);
|
||||||
convStream.init(inputStream, charset, 1024, replacementChar);
|
convStream.init(inputStream, charset, 16384, replacementChar);
|
||||||
var readString = "";
|
var readString = "";
|
||||||
var str = {};
|
var str = {};
|
||||||
while (convStream.readString(4096, str) != 0) {
|
while (convStream.readString(16384, str) != 0) {
|
||||||
readString += str.value;
|
readString += str.value;
|
||||||
}
|
}
|
||||||
convStream.close();
|
convStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
|
||||||
try {
|
var me = this;
|
||||||
_typeHandlers[this._contentType](readString, (this._request.name ? this._request.name : null),
|
Q(_typeHandlers[this._contentType](readString, (this._request.name ? this._request.name : null),
|
||||||
this._contentType, channel);
|
this._contentType, channel)).fail(function(e) {
|
||||||
} catch(e) {
|
// if there was an error, handle using nsIExternalHelperAppService
|
||||||
// if there was an error, handle using nsIExternalHelperAppService
|
var externalHelperAppService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"].
|
||||||
var externalHelperAppService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"].
|
getService(Components.interfaces.nsIExternalHelperAppService);
|
||||||
getService(Components.interfaces.nsIExternalHelperAppService);
|
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;
|
|
||||||
|
var inputStream = me._storageStream.newInputStream(0);
|
||||||
var inputStream = this._storageStream.newInputStream(0);
|
var streamListener = externalHelperAppService.doContent(me._contentType, me._request, frontWindow, null);
|
||||||
var streamListener = externalHelperAppService.doContent(this._contentType, this._request, frontWindow, null);
|
if (streamListener) {
|
||||||
if (streamListener) {
|
streamListener.onStartRequest(channel, context);
|
||||||
streamListener.onStartRequest(channel, context);
|
streamListener.onDataAvailable(me._request, context, inputStream, 0, me._storageStream.length);
|
||||||
streamListener.onDataAvailable(this._request, context, inputStream, 0, this._storageStream.length);
|
streamListener.onStopRequest(channel, context, status);
|
||||||
streamListener.onStopRequest(channel, context, status);
|
}
|
||||||
}
|
|
||||||
this._storageStream.close();
|
// then throw our error
|
||||||
|
throw e;
|
||||||
// then throw our error
|
}).fin(function() {
|
||||||
throw e;
|
me._storageStream.close();
|
||||||
}
|
}).done();
|
||||||
|
|
||||||
this._storageStream.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue