closes #216, support for non-ascii characters in word integration
This commit is contained in:
parent
697fcedc58
commit
858c0145e6
5 changed files with 73 additions and 23 deletions
BIN
Zotero.dot
BIN
Zotero.dot
Binary file not shown.
BIN
Zotero.dot.dmg
BIN
Zotero.dot.dmg
Binary file not shown.
|
@ -94,6 +94,8 @@ CSL = function(csl) {
|
|||
CSL.prototype.preprocessItems = function(items) {
|
||||
Scholar.debug("CSL: preprocessing items");
|
||||
|
||||
this._ignore = null;
|
||||
|
||||
// get data necessary to generate citations before sorting
|
||||
for(var i in items) {
|
||||
var item = items[i];
|
||||
|
@ -563,13 +565,6 @@ CSL.prototype._parseFields = function(ref, position, type, bibCitElement, inheri
|
|||
if(bibCitElement && inheritFormat) {
|
||||
itemDesc = this._merge(bibCitElement.inheritFormat, itemDesc);
|
||||
}
|
||||
|
||||
// create serialized representation
|
||||
itemDesc._serialized = this._serializeElement(itemDesc.name, itemDesc);
|
||||
// add to serialization for type
|
||||
if(bibCitElement) {
|
||||
bibCitElement._serializations[position][type][itemDesc._serialized] = itemDesc;
|
||||
}
|
||||
}
|
||||
|
||||
// parse group children
|
||||
|
@ -586,6 +581,15 @@ CSL.prototype._parseFields = function(ref, position, type, bibCitElement, inheri
|
|||
this._parseFieldAttrChildren(element, itemDesc);
|
||||
}
|
||||
|
||||
if(type != undefined) {
|
||||
// create serialized representation
|
||||
itemDesc._serialized = this._serializeElement(itemDesc.name, itemDesc);
|
||||
// add to serialization for type
|
||||
if(bibCitElement) {
|
||||
bibCitElement._serializations[position][type][itemDesc._serialized] = itemDesc;
|
||||
}
|
||||
}
|
||||
|
||||
typeDesc.push(itemDesc);
|
||||
}
|
||||
}
|
||||
|
@ -809,7 +813,6 @@ CSL.prototype._getFieldDefaults = function(elementName) {
|
|||
* gets a term, in singular or plural form
|
||||
*/
|
||||
CSL.prototype._getTerm = function(term, plural, form) {
|
||||
Scholar.debug("CSL: looking up term "+term);
|
||||
if(!form) {
|
||||
form = "long";
|
||||
}
|
||||
|
@ -1039,7 +1042,7 @@ CSL.prototype._serializeElement = function(name, element) {
|
|||
string += " relation:"+element.relation;
|
||||
}
|
||||
if(element.role) {
|
||||
string += " role"+element.role;
|
||||
string += " role:"+element.role;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
@ -1214,6 +1217,8 @@ CSL.prototype._getCitation = function(item, position, format, bibCitElement) {
|
|||
}
|
||||
Scholar.debug("CSL: using CSL type "+typeName);
|
||||
|
||||
// remove previous ignore entries from list
|
||||
this._ignore = new Array();
|
||||
var string = "";
|
||||
for(var j in type) {
|
||||
var value = this._getFieldValue(type[j].name, type[j], item, format,
|
||||
|
@ -1230,7 +1235,8 @@ CSL.prototype._getCitation = function(item, position, format, bibCitElement) {
|
|||
CSL.prototype._getFieldValue = function(name, element, item, format, bibCitElement, position, typeName) {
|
||||
var data = "";
|
||||
|
||||
if(element._serialized && item._csl.ignore[element._serialized]) {
|
||||
var itemID = item.getID();
|
||||
if(element._serialized && this._ignore && this._ignore[itemID] && this._ignore[itemID][element._serialized]) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -1403,13 +1409,17 @@ CSL.prototype._getFieldValue = function(name, element, item, format, bibCitEleme
|
|||
// clear substitute element off of the element we're substituting
|
||||
substituteElement.substitute = undefined;
|
||||
|
||||
// ignore elements with the same serialization
|
||||
item._csl.ignore[serialization] = true;
|
||||
|
||||
// get field value
|
||||
data = this._getFieldValue(substituteElement.name,
|
||||
substituteElement, item, format,
|
||||
bibCitElement);
|
||||
bibCitElement, position, typeName);
|
||||
|
||||
// ignore elements with the same serialization
|
||||
if(this._ignore) { // array might not exist if doing disambiguation
|
||||
if(!this._ignore[itemID]) this._ignore[itemID] = new Array();
|
||||
this._ignore[itemID][substituteElement._serialized] = true;
|
||||
}
|
||||
|
||||
// return field value, if there is one; otherwise, keep processing
|
||||
// the data
|
||||
if(data) {
|
||||
|
|
|
@ -50,7 +50,7 @@ Scholar.Integration = new function() {
|
|||
/*
|
||||
* handles a SOAP envelope
|
||||
*/
|
||||
function handleEnvelope(envelope) {
|
||||
function handleEnvelope(envelope, encoding) {
|
||||
Scholar.debug("Integration: SOAP Request\n"+envelope);
|
||||
envelope = envelope.replace(_XMLRe, "");
|
||||
|
||||
|
@ -115,11 +115,11 @@ Scholar.Integration = new function() {
|
|||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>;
|
||||
|
||||
var response = responseEnvelope.toXMLString();
|
||||
var response = '<?xml version="1.0" encoding="'+encoding+'"?>\n'+responseEnvelope.toXMLString();
|
||||
Scholar.debug("Integration: SOAP Response\n"+response);
|
||||
|
||||
// return OK
|
||||
return _generateResponse("200 OK", 'text/xml; charset="utf-8"',
|
||||
return _generateResponse("200 OK", 'text/xml; charset="'+encoding+'"',
|
||||
response);
|
||||
} else {
|
||||
Scholar.debug("Integration: SOAP method not supported");
|
||||
|
@ -275,20 +275,54 @@ Scholar.Integration.DataListener.prototype._bodyData = function() {
|
|||
this.body = this.body.substr(0, this.bodyLength);
|
||||
}
|
||||
|
||||
var output = Scholar.Integration.handleEnvelope(this.body);
|
||||
this._requestFinished(output);
|
||||
// UTF-8 crashes AppleScript
|
||||
var encoding = (this.header.indexOf("\nUser-Agent: Mac OS X") !== -1 ? "macintosh" : "UTF-8");
|
||||
var output = Scholar.Integration.handleEnvelope(this.body, encoding);
|
||||
this._requestFinished(output, encoding);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* returns HTTP data from a request
|
||||
*/
|
||||
Scholar.Integration.DataListener.prototype._requestFinished = function(response) {
|
||||
Scholar.Integration.DataListener.prototype._requestFinished = function(response, encoding) {
|
||||
// close input stream
|
||||
this.iStream.close();
|
||||
|
||||
// write response
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
// close output stream
|
||||
this.oStream.close();
|
||||
|
@ -458,8 +492,10 @@ Scholar.Integration.SOAP = new function() {
|
|||
} else {
|
||||
// session ID exists
|
||||
var sessionID = vars[0];
|
||||
Scholar.debug(vars.toSource());
|
||||
var session = _sessions[sessionID];
|
||||
if(!session) {
|
||||
return "ERROR:sessionExpired";
|
||||
}
|
||||
var originalStyle = session.styleID;
|
||||
io.style = originalStyle;
|
||||
}
|
||||
|
|
|
@ -745,6 +745,10 @@ Scholar.Translate.prototype._canTranslate = function(translator, ignoreExtension
|
|||
|
||||
return canTranslate;
|
||||
}
|
||||
|
||||
/*
|
||||
* parses translator detect code
|
||||
*/
|
||||
Scholar.Translate.prototype._parseDetectCode = function(translator) {
|
||||
this._configOptions = new Array();
|
||||
this._displayOptions = new Array();
|
||||
|
|
Loading…
Reference in a new issue