commit 7b062f3b15a5c21b8172a0547f01e0bd6e7cfee7
parent 6086f4571df8bf640c827326845706be75d8dbfe
Author: Simon Kornblith <simon@simonster.com>
Date: Thu, 3 Jun 2010 02:56:29 +0000
- update to citeproc-js 1.0.20
From Frank's announcement:
This release adds some further fine-tuning to disambiguation, and now
retains all names added by disambiguate-add-names when a year-suffix
is added to a cite. Also fixes a bug affecting cites containing lone
institutional authors.
- hopefully fix issues with loading locales from the XPI
Diffstat:
4 files changed, 42 insertions(+), 57 deletions(-)
diff --git a/updateCSL.xsl b/chrome/content/zotero/updateCSL.xsl
diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js
@@ -199,26 +199,12 @@ Zotero.Cite.System.retrieveItem = function(item){
return cslItem;
};
-Zotero.Cite.System.retrieveLocale = function(lang){
- var localesDir = Zotero.getInstallDirectory();
- [localesDir.append(dir) for each(dir in ["chrome", "content", "zotero", "locale", "csl"])];
-
- var base = "locales-"+lang;
-
- var localesFile = localesDir.clone();
- localesFile.append(base+".xml");
- if(!localesFile.exists()) {
- var contents = localesDir.directoryEntries;
- while(contents.hasMoreElements()) {
- var file = contents.getNext().QueryInterface(Components.interfaces.nsIFile);
- if(file.leafName.substr(0, base.length) == base && file.leafName.substr(-4) == ".xml") {
- localesFile = file;
- break;
- }
- }
- }
-
- return Zotero.File.getContents(localesFile);
+Zotero.Cite.System.retrieveLocale = function(lang) {
+ var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
+ xhr.open("GET", "chrome://zotero/content/locale/csl/locales-"+lang+".xml", false);
+ xhr.overrideMimeType("application/octet-stream");
+ xhr.send();
+ return xhr.responseText;
};
Zotero.Cite.System.getAbbreviations = function() {
@@ -292,8 +278,16 @@ Zotero.Cite.getMonthStrings = function(form, locale) {
if(!Zotero.CiteProc.CSL.locale[cslLocale.best]) {
let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.best));
if(!localexml) {
- Zotero.log("No locale "+cslLocale.best+"; using en-US", "warning");
- return Zotero.Cite.getMonthStrings(form, "en-US");
+ if(localexml == "en-US") {
+ throw "No locales.xml file could be found for the preferred locale or for en-US. "+
+ "Please ensure that the locales directory exists and is properly populated";
+ } else {
+ let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.bare));
+ if(!localexml) {
+ Zotero.log("No locale "+cslLocale.best+"; using en-US", "warning");
+ return Zotero.Cite.getMonthStrings(form, "en-US");
+ }
+ }
}
Zotero.CiteProc.CSL.localeSet.call(Zotero.CiteProc.CSL, sys, localexml, cslLocale.best, cslLocale.best);
}
diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js
@@ -1432,7 +1432,7 @@ CSL.dateParser = function (txt) {
};
CSL.Engine = function (sys, style, lang, xmlmode) {
var attrs, langspec, localexml, locale;
- this.processor_version = "1.0.19";
+ this.processor_version = "1.0.20";
this.csl_version = "1.0";
this.sys = sys;
this.sys.xml = new CSL.System.Xml.Parsing();
@@ -3642,7 +3642,7 @@ CSL.Node.names = {
} else {
frontnames = [];
}
- if (tnamesets.length > 0 && tnamesets.slice(-1)[0].species === "org" && !(state.opt.xclass === "in-text" && state.tmp.area.slice(0, 8) === "citation")) {
+ if (tnamesets.length > 0 && tnamesets.slice(-1)[0].species === "org") {
tnamesets[0].organization_first = true;
tnamesets.slice(-1)[0].organization_last = true;
if (frontnames.length) {
@@ -7541,7 +7541,7 @@ CSL.Registry.NameReg = function (state) {
};
var debug = false;
CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candidate_list) {
- var ambigs, reg_token, keypos, id_vals, a, base, token, pos, len, tokens, str, maxvals, minval, testpartner, otherstr, base_return, ret, id, key, givensbase, remainder, last_remainder;
+ var ambigs, reg_token, keypos, id_vals, a, base, token, pos, len, tokens, str, maxvals, minval, testpartner, otherstr, base_return, ret, id, key, origbase, remainder, last_remainder;
if (!candidate_list) {
ambigs = this.ambigcites[akey].slice();
this.ambigcites[akey] = [];
@@ -7574,10 +7574,7 @@ CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candida
maxvals = CSL.getMaxVals.call(state);
minval = CSL.getMinVal.call(state);
base = CSL.getAmbigConfig.call(state);
- givensbase = [];
- for (pos = 0, len = base.givens.length; pos < len; pos += 1) {
- givensbase.push(base.givens[pos].slice());
- }
+ origbase = CSL.cloneAmbigConfig(base);
remainder = tokens.length;
last_remainder = this.checkerator.seen.length;
while (CSL.runCheckerator.call(this.checkerator)) {
@@ -7614,9 +7611,9 @@ CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candida
if (CSL.evaluateCheckeratorClashes.call(this.checkerator)) {
remainder = tokens.length - this.checkerator.seen.length;
if (remainder === 1 && last_remainder === 0) {
- base_return = CSL.decrementCheckeratorGivenNames.call(this, state, base, givensbase, token.id);
+ base_return = CSL.decrementCheckeratorGivenNames.call(this, state, base, origbase, token.id);
} else {
- base_return = CSL.decrementCheckeratorNames.call(this, state, base, givensbase);
+ base_return = CSL.decrementCheckeratorNames.call(this, state, base, origbase, token.id);
}
last_remainder = remainder;
this.registerAmbigToken(akey, token.id, base_return);
@@ -7624,11 +7621,8 @@ CSL.Registry.prototype.disambiguateCites = function (state, akey, modes, candida
continue;
}
if (CSL.maxCheckeratorAmbigLevel.call(this.checkerator)) {
- if (!state.citation.opt["disambiguate-add-year-suffix"]) {
- this.checkerator.mode1_counts = false;
- this.checkerator.maxed_out_bases[token.id] = CSL.cloneAmbigConfig(base);
- } else {
- }
+ this.checkerator.mode1_counts = false;
+ this.checkerator.maxed_out_bases[token.id] = CSL.cloneAmbigConfig(base);
this.checkerator.seen.push(token.id);
base = false;
continue;
@@ -7823,36 +7817,39 @@ CSL.incrementCheckeratorAmbigLevel = function () {
}
}
};
-CSL.decrementCheckeratorGivenNames = function (state, base, givensbase, id) {
+CSL.decrementCheckeratorGivenNames = function (state, base, origbase, id) {
var base_return, ids, pos, len;
ids = this.checkerator.ids;
this.checkerator.ids = ids.slice(0,ids.indexOf(id)).concat(ids.slice(ids.indexOf(id) + 1));
base_return = CSL.cloneAmbigConfig(base);
for (pos = 0, len = base_return.givens.length; pos < len; pos += 1) {
- base_return.givens[pos] = givensbase.slice();
+ base_return.givens[pos] = origbase.givens[pos].slice();
}
return base_return;
};
-CSL.decrementCheckeratorNames = function (state, base, givensbase) {
- var base_return, do_me, i, j, pos, len, ppos, llen;
+CSL.decrementCheckeratorNames = function (state, base, origbase, id) {
+ var base_return, do_me, i, j, pos, len, ppos, llen, ids;
base_return = CSL.cloneAmbigConfig(base);
do_me = false;
len = base_return.givens.length - 1;
for (pos = len; pos > -1; pos += -1) {
llen = base_return.givens[pos].length - 1;
for (ppos = llen; ppos > -1; ppos += -1) {
- if (base_return.givens[pos][ppos] > givensbase[pos][ppos]) {
- do_me = true;
+ if (base_return.givens[pos][ppos] > origbase.givens[pos][ppos]) {
+ do_me = true;
}
}
}
if (do_me) {
+ ids = this.checkerator.ids;
len = base_return.givens.length - 1;
for (pos = len; pos > -1; pos += -1) {
llen = base_return.givens[pos].length - 1;
for (ppos = llen; ppos > -1; ppos += -1) {
- if (base_return.givens[pos][ppos] > givensbase[pos][ppos]) {
- i = -1;
+ if (base_return.givens[pos][ppos] > origbase.givens[pos][ppos]) {
+ if (ids.indexOf(id) > -1) {
+ this.checkerator.ids = ids.slice(0,ids.indexOf(id)).concat(ids.slice(ids.indexOf(id) + 1));
+ }
break;
}
if (ppos < base_return.names[pos]) {
@@ -7896,4 +7893,4 @@ CSL.getModes = function () {
CSL.Registry.CitationReg = function (state) {
this.citationById = {};
this.citationByIndex = [];
-};
+};
+\ No newline at end of file
diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js
@@ -394,18 +394,11 @@ function() {
if(this._version == "0.8") {
// get XSLT file
- let updateXSLTFile = Zotero.getInstallDirectory();
- updateXSLTFile.append("updateCSL.xsl");
-
- // read XSLT file as DOM XML
- let xmlFiles = [];
- let fis = Components.classes["@mozilla.org/network/file-input-stream;1"].
- createInstance(Components.interfaces.nsIFileInputStream);
- fis.init(updateXSLTFile, 0x01, 0664, 0);
- let updateXSLT = Components.classes["@mozilla.org/xmlextras/domparser;1"]
- .createInstance(Components.interfaces.nsIDOMParser)
- .parseFromStream(fis, "UTF-8", updateXSLTFile.fileSize, "text/xml");
- fis.close();
+ let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
+ xhr.open("GET", "chrome://zotero/content/updateCSL.xsl", false);
+ xhr.overrideMimeType("text/xml");
+ xhr.send();
+ let updateXSLT = xhr.responseXML;
// load XSLT file into XSLTProcessor
let xsltProcessor = Components.classes["@mozilla.org/document-transformer;1?type=xslt"]