From 5127801160c90436e893909a3da206dc70e2f15f Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 14 Dec 2006 20:57:50 +0000 Subject: [PATCH] - closes #434, remove SOAP dependency on Windows - fixes a bug that could result in truncation of the bibliography by two characters --- chrome/content/zotero/xpcom/cite.js | 2 +- chrome/content/zotero/xpcom/integration.js | 58 ++++++---------------- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 45ff6b88d..e55bb0fbf 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -544,7 +544,7 @@ Zotero.CSL.prototype.createBibliography = function(items, format) { output = output.substr(0, output.length-6)+"}"; } else { // 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; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 2dd4a392b..46b36a973 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -76,7 +76,7 @@ Zotero.Integration = new function() { /* * handles a SOAP envelope */ - function handleEnvelope(envelope, encoding) { + function handleEnvelope(envelope) { Zotero.debug("Integration: SOAP Request\n"+envelope); envelope = envelope.replace(_XMLRe, ""); @@ -141,11 +141,11 @@ Zotero.Integration = new function() { ; - var response = '\n'+responseEnvelope.toXMLString(); + var response = '\n'+responseEnvelope.toXMLString(); Zotero.debug("Integration: SOAP Response\n"+response); // return OK - return _generateResponse("200 OK", 'text/xml; charset="'+encoding+'"', + return _generateResponse("200 OK", 'text/xml; charset="UTF-8"', response); } else { Zotero.debug("Integration: SOAP method not supported"); @@ -163,7 +163,7 @@ Zotero.Integration = new function() { if(contentType) { response += "Content-Type: "+contentType+"\r\n"; } - response += "Content-Length: "+body.length+"\r\n\r\n"+body; + response += "\r\n"+body; } else { 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); } - // UTF-8 crashes AppleScript - var encoding = (this.header.indexOf("\nUser-Agent: Mac OS X") !== -1 ? "macintosh" : "UTF-8"); - var output = Zotero.Integration.handleEnvelope(this.body, encoding); - this._requestFinished(output, encoding); + var output = Zotero.Integration.handleEnvelope(this.body); + this._requestFinished(output); } } /* * returns HTTP data from a request */ -Zotero.Integration.DataListener.prototype._requestFinished = function(response, encoding) { +Zotero.Integration.DataListener.prototype._requestFinished = function(response) { // close input stream 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(); + // open UTF-8 converter for output stream + var intlStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"] + .createInstance(Components.interfaces.nsIConverterOutputStream); + intlStream.init(this.oStream, "UTF-8", 1024, "?".charCodeAt(0)); - // write - this.oStream.write(response, response.length); - } else if(encoding) { - // open UTF-8 converter for output stream - var intlStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"] - .createInstance(Components.interfaces.nsIConverterOutputStream); - intlStream.init(this.oStream, encoding, 1024, "?".charCodeAt(0)); - - // write response - intlStream.writeString(response); - intlStream.close(); - } else { - // write - this.oStream.write(response, response.length); - } + // write response + intlStream.writeString(response); + intlStream.close(); + // write + this.oStream.write(response, response.length); // close output stream this.oStream.close();