- closes #434, remove SOAP dependency on Windows
- fixes a bug that could result in truncation of the bibliography by two characters
This commit is contained in:
parent
e705bc21e5
commit
5127801160
|
@ -544,7 +544,7 @@ Zotero.CSL.prototype.createBibliography = function(items, format) {
|
||||||
output = output.substr(0, output.length-6)+"}";
|
output = output.substr(0, output.length-6)+"}";
|
||||||
} else {
|
} else {
|
||||||
// drop last 4 characters (last two returns)
|
// drop last 4 characters (last two returns)
|
||||||
output = output.substr(0, output.length-4);
|
output = output.substr(0, (Zotero.isMac ? output.length-2 : output.length-4));
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -76,7 +76,7 @@ Zotero.Integration = new function() {
|
||||||
/*
|
/*
|
||||||
* handles a SOAP envelope
|
* handles a SOAP envelope
|
||||||
*/
|
*/
|
||||||
function handleEnvelope(envelope, encoding) {
|
function handleEnvelope(envelope) {
|
||||||
Zotero.debug("Integration: SOAP Request\n"+envelope);
|
Zotero.debug("Integration: SOAP Request\n"+envelope);
|
||||||
envelope = envelope.replace(_XMLRe, "");
|
envelope = envelope.replace(_XMLRe, "");
|
||||||
|
|
||||||
|
@ -141,11 +141,11 @@ Zotero.Integration = new function() {
|
||||||
</SOAP-ENV:Body>
|
</SOAP-ENV:Body>
|
||||||
</SOAP-ENV:Envelope>;
|
</SOAP-ENV:Envelope>;
|
||||||
|
|
||||||
var response = '<?xml version="1.0" encoding="'+encoding+'"?>\n'+responseEnvelope.toXMLString();
|
var response = '<?xml version="1.0" encoding="UTF-8"?>\n'+responseEnvelope.toXMLString();
|
||||||
Zotero.debug("Integration: SOAP Response\n"+response);
|
Zotero.debug("Integration: SOAP Response\n"+response);
|
||||||
|
|
||||||
// return OK
|
// return OK
|
||||||
return _generateResponse("200 OK", 'text/xml; charset="'+encoding+'"',
|
return _generateResponse("200 OK", 'text/xml; charset="UTF-8"',
|
||||||
response);
|
response);
|
||||||
} else {
|
} else {
|
||||||
Zotero.debug("Integration: SOAP method not supported");
|
Zotero.debug("Integration: SOAP method not supported");
|
||||||
|
@ -163,7 +163,7 @@ Zotero.Integration = new function() {
|
||||||
if(contentType) {
|
if(contentType) {
|
||||||
response += "Content-Type: "+contentType+"\r\n";
|
response += "Content-Type: "+contentType+"\r\n";
|
||||||
}
|
}
|
||||||
response += "Content-Length: "+body.length+"\r\n\r\n"+body;
|
response += "\r\n"+body;
|
||||||
} else {
|
} else {
|
||||||
response += "Content-Length: 0\r\n\r\n"
|
response += "Content-Length: 0\r\n\r\n"
|
||||||
}
|
}
|
||||||
|
@ -301,54 +301,28 @@ Zotero.Integration.DataListener.prototype._bodyData = function() {
|
||||||
this.body = this.body.substr(0, this.bodyLength);
|
this.body = this.body.substr(0, this.bodyLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTF-8 crashes AppleScript
|
var output = Zotero.Integration.handleEnvelope(this.body);
|
||||||
var encoding = (this.header.indexOf("\nUser-Agent: Mac OS X") !== -1 ? "macintosh" : "UTF-8");
|
this._requestFinished(output);
|
||||||
var output = Zotero.Integration.handleEnvelope(this.body, encoding);
|
|
||||||
this._requestFinished(output, encoding);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns HTTP data from a request
|
* returns HTTP data from a request
|
||||||
*/
|
*/
|
||||||
Zotero.Integration.DataListener.prototype._requestFinished = function(response, encoding) {
|
Zotero.Integration.DataListener.prototype._requestFinished = function(response) {
|
||||||
// close input stream
|
// close input stream
|
||||||
this.iStream.close();
|
this.iStream.close();
|
||||||
|
|
||||||
if(encoding == "macintosh") {
|
|
||||||
// double percent signs
|
|
||||||
response = response.replace(/%/g, "%%");
|
|
||||||
// replace line endings with percent signs
|
|
||||||
response = response.replace(/\n/g, " %!");
|
|
||||||
response = response.replace(/\r/g, "");
|
|
||||||
|
|
||||||
// convert Unicode to Mac Roman
|
|
||||||
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
||||||
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
|
|
||||||
converter.charset = "macintosh";
|
|
||||||
// convert text
|
|
||||||
response = converter.ConvertFromUnicode(response);
|
|
||||||
// fix returns
|
|
||||||
response = response.replace(/ %!/g, "\n");
|
|
||||||
// fix percent signs
|
|
||||||
response = response.replace(/%%/g, "%");
|
|
||||||
response = response + converter.Finish();
|
|
||||||
|
|
||||||
// write
|
|
||||||
this.oStream.write(response, response.length);
|
|
||||||
} else if(encoding) {
|
|
||||||
// open UTF-8 converter for output stream
|
// open UTF-8 converter for output stream
|
||||||
var intlStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
var intlStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
||||||
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
||||||
intlStream.init(this.oStream, encoding, 1024, "?".charCodeAt(0));
|
intlStream.init(this.oStream, "UTF-8", 1024, "?".charCodeAt(0));
|
||||||
|
|
||||||
// write response
|
// write response
|
||||||
intlStream.writeString(response);
|
intlStream.writeString(response);
|
||||||
intlStream.close();
|
intlStream.close();
|
||||||
} else {
|
|
||||||
// write
|
// write
|
||||||
this.oStream.write(response, response.length);
|
this.oStream.write(response, response.length);
|
||||||
}
|
|
||||||
|
|
||||||
// close output stream
|
// close output stream
|
||||||
this.oStream.close();
|
this.oStream.close();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user