From 666831748eebd66f204442050e9137f26c8187e5 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 23 Oct 2006 07:34:34 +0000 Subject: [PATCH] closes #358, APA style doesn't properly handle references with editors and no authors closes #348, OpenURL should use only relevant parts of dates closes #354, Error saving History Cooperative article closes #356, Embedded Dublin Core scraper incorrectly saves web pages as item type "book" closes #355, PubMed translator problem closes #368, RIS/Endnote export hijack doesn't go into active collection fixes an issue with quotation marks in bibliographies exported as RTF fixes an issue with bibliographies and non-English locales --- chrome/content/zotero/xpcom/cite.js | 111 ++++++++++++++---------- chrome/content/zotero/xpcom/ingester.js | 28 ++++-- chrome/locale/en-US/zotero/locales.xml | 2 + scrapers.sql | 34 +++++--- 4 files changed, 112 insertions(+), 63 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 78bbe771ca..6829883243 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -183,7 +183,7 @@ Zotero.CSL.Global = new function() { // get default terms var locales = new XML(Zotero.CSL.Global.cleanXML(req.responseText)); - Zotero.CSL.Global._defaultTerms = Zotero.CSL.Global.parseLocales(locales); + Zotero.CSL.Global._defaultTerms = Zotero.CSL.Global.parseLocales(locales, true); } } @@ -205,7 +205,7 @@ Zotero.CSL.Global = new function() { /* * parses locale strings into Zotero.CSL.Global._defaultTerms */ - this.parseLocales = function(termXML) { + this.parseLocales = function(termXML, ignoreLang) { // return defaults if there are no terms if(!termXML.length()) { return (Zotero.CSL.Global._defaultTerms ? Zotero.CSL.Global._defaultTerms : {}); @@ -213,15 +213,20 @@ Zotero.CSL.Global = new function() { var xml = new Namespace("http://www.w3.org/XML/1998/namespace"); - // get proper locale - var locale = termXML.locale.(@xml::lang == Zotero.CSL.Global._xmlLang); - if(!locale.length()) { - var xmlLang = Zotero.CSL.Global._xmlLang.substr(0, 2); - locale = termXML.locale.(@xml::lang == xmlLang); - } - if(!locale.length()) { - // return defaults if there are no locales - return (Zotero.CSL.Global._defaultTerms ? Zotero.CSL.Global._defaultTerms : {}); + if(ignoreLang) { + // ignore lang if loaded from chrome + locale = termXML.locale[0]; + } else { + // get proper locale + var locale = termXML.locale.(@xml::lang == Zotero.CSL.Global._xmlLang); + if(!locale.length()) { + var xmlLang = Zotero.CSL.Global._xmlLang.substr(0, 2); + locale = termXML.locale.(@xml::lang == xmlLang); + } + if(!locale.length()) { + // return defaults if there are no locales + return (Zotero.CSL.Global._defaultTerms ? Zotero.CSL.Global._defaultTerms : {}); + } } var termArray = new Object(); @@ -1114,9 +1119,11 @@ Zotero.CSL.prototype._getFieldValue = function(name, element, item, formattedStr bibCitElement, position, locatorType, locator, typeName) { + var dataAppended = false; var itemID = item.getID(); - if(element._serialized && this._ignore && this._ignore[itemID] && this._ignore[itemID][element._serialized]) { + + if(element._serialized && this._ignore && this._ignore[element._serialized]) { return false; } @@ -1178,10 +1185,11 @@ Zotero.CSL.prototype._getFieldValue = function(name, element, item, formattedStr dataAppended = formattedString.concat(data, element); } else if(name == "access") { var data = new Zotero.CSL.FormattedString(this, formattedString.format); - var text; + var text = null; var save = false; for(var i in element.children) { + text = null; var child = element.children[i]; if(child.name == "url") { @@ -1198,8 +1206,8 @@ Zotero.CSL.prototype._getFieldValue = function(name, element, item, formattedStr text = this._getTerm(child["term-name"], false, child["form"]); } - if(string) { - data.append(string, child); + if(text) { + data.append(text, child); if(child.name != "text") { // only save if there's non-text data save = true; @@ -1342,8 +1350,7 @@ Zotero.CSL.prototype._getFieldValue = function(name, element, item, formattedStr // 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; + this._ignore[serialization] = true; } // return field value, if there is one; otherwise, keep processing @@ -1365,6 +1372,14 @@ Zotero.CSL.FormattedString = function(CSL, format, delimiter) { this.string = ""; this.closePunctuation = false; this.useBritishStyleQuotes = false; + + if(format == "RTF") { + this._openQuote = "\\uc0\\u8220 "; + this._closeQuote = "\\uc0\\u8221 "; + } else { + this._openQuote = "\u201c"; + this._closeQuote = "\u201d"; + } } Zotero.CSL.FormattedString._punctuation = ["!", ".", ",", "?"]; @@ -1377,7 +1392,6 @@ Zotero.CSL.FormattedString.prototype.concat = function(formattedString, element) return false; } - Zotero.debug("adding "+formattedString.string+" to "+this.string); if(formattedString.format != this.format) { throw "CSL: cannot concatenate formatted strings: formats do not match"; } @@ -1431,34 +1445,36 @@ Zotero.CSL.FormattedString.prototype.append = function(string, element, dontDeli string = string[0].toUpperCase()+string.substr(1).toLowerCase(); } } - - if(!dontEscape) { - if(this.format == "HTML") { - // replace HTML entities - string = string.replace(/&/g, "&"); - string = string.replace(//g, ">"); - } else if(this.format == "RTF") { - var newString = ""; - - // go through and fix up unicode entities - for(i=0; i 127) { // encode unicode - newString += "\\uc0\\u"+charCode.toString()+" "; - } else if(charCode == 92) { // double backslashes - newString += "\\\\"; - } else { - newString += string[i]; - } + } + + if(!dontEscape) { + if(this.format == "HTML") { + // replace HTML entities + string = string.replace(/&/g, "&"); + string = string.replace(//g, ">"); + } else if(this.format == "RTF") { + var newString = ""; + + // go through and fix up unicode entities + for(i=0; i 127) { // encode unicode + newString += "\\uc0\\u"+charCode.toString()+" "; + } else if(charCode == 92) { // double backslashes + newString += "\\\\"; + } else { + newString += string[i]; } - - string = newString - } else if(this.format == "Integration") { - string = string.replace(/\\/g, "\\\\"); } + + string = newString + } else if(this.format == "Integration") { + string = string.replace(/\\/g, "\\\\"); } - + } + + if(element) { if(this.format == "HTML") { var style = ""; @@ -1484,15 +1500,15 @@ Zotero.CSL.FormattedString.prototype.append = function(string, element, dontDeli string = "\\b "+string+"\\b0 "; } } - + // add quotes if necessary if(element.quotes) { - this.string += "\u201c"; + this.string += this._openQuote; if(this.useBritishStyleQuotes) { - string += "\u201d"; + string += this._closeQuote; } else { - this.closePunctuation = "\u201d"; + this.closePunctuation = this._closeQuote; } } } @@ -1512,7 +1528,6 @@ Zotero.CSL.FormattedString.prototype.append = function(string, element, dontDeli suffix = suffix.substr(1); } - Zotero.debug("appending suffix"); this.append(suffix, null, true); } diff --git a/chrome/content/zotero/xpcom/ingester.js b/chrome/content/zotero/xpcom/ingester.js index 4b733adad5..a78e35829e 100644 --- a/chrome/content/zotero/xpcom/ingester.js +++ b/chrome/content/zotero/xpcom/ingester.js @@ -326,9 +326,19 @@ Zotero.OpenURL = new function() { } if(item.date) { - co += _mapTag(item.date, "date", version); - } else { - co += _mapTag(item.year, "date", version); + var date = Zotero.Date.strToDate(item.date); + + if(date.year) { + var dateString = Zotero.Utilities.prototype.lpad(date.year, "0", 4); + if(date.month) { + dateString += "-"+Zotero.Utilities.prototype.lpad(date.month, "0", 2); + if(date.day) { + dateString += "-"+Zotero.Utilities.prototype.lpad(date.day, "0", 2); + } + } + + co += _mapTag(dateString, "date", version); + } } co += _mapTag(item.pages, "pages", version); co += _mapTag(item.ISBN, "isbn", version); @@ -643,8 +653,16 @@ Zotero.Ingester.MIMEHandler.StreamListener.prototype.onStopRequest = function(ch var translation = new Zotero.Translate("import"); translation.setLocation(this._request.name); translation.setString(this._readString); - translation.setHandler("itemDone", this._frontWindow.Zotero_Ingester_Interface._itemDone); - translation.setHandler("done", this._frontWindow.Zotero_Ingester_Interface._finishScraping); + + // use front window's save functions and folder + var frontWindow = this._frontWindow; + + var saveLocation = null; + try { + saveLocation = frontWindow.ZoteroPane.getSelectedCollection(); + } catch(e) {} + translation.setHandler("itemDone", function(obj, item) { frontWindow.Zotero_Ingester_Interface._itemDone(obj, item, saveLocation) }); + translation.setHandler("done", function(obj, item) { frontWindow.Zotero_Ingester_Interface._finishScraping(obj, item, saveLocation) }); // attempt to retrieve translators var translators = translation.getTranslators(); diff --git a/chrome/locale/en-US/zotero/locales.xml b/chrome/locale/en-US/zotero/locales.xml index 34bc93af53..f126ce9400 100644 --- a/chrome/locale/en-US/zotero/locales.xml +++ b/chrome/locale/en-US/zotero/locales.xml @@ -4,6 +4,8 @@ in ibid accessed + retrieved + from forthcoming References nd diff --git a/scrapers.sql b/scrapers.sql index 133bb57293..e65775fe11 100644 --- a/scrapers.sql +++ b/scrapers.sql @@ -1,4 +1,4 @@ --- 100 +-- 101 -- ***** BEGIN LICENSE BLOCK ***** -- @@ -687,7 +687,7 @@ function doWeb(doc, url) { Zotero.wait(); }'); -REPLACE INTO "translators" VALUES ('e85a3134-8c1a-8644-6926-584c8565f23e', '2006-10-02 17:00:00', 1, 100, 4, 'History Cooperative', 'Simon Kornblith', '^http://www\.historycooperative\.org/(?:journals/.+/.+/.+\.s?html$|cgi-bin/search.cgi)', +REPLACE INTO "translators" VALUES ('e85a3134-8c1a-8644-6926-584c8565f23e', '2006-10-23 00:23:00', 1, 100, 4, 'History Cooperative', 'Simon Kornblith', '^http://www\.historycooperative\.org/(?:journals/.+/.+/.+\.s?html$|cgi-bin/search.cgi)', 'function detectWeb(doc, url) { if(doc.title == "History Cooperative: Search Results") { return "multiple"; @@ -708,7 +708,13 @@ function scrape(doc) { var month, year; var metaTags = doc.getElementsByTagName("meta"); - associateMeta(newItem, metaTags, "Title", "title"); + + // grab title without using meta tag, since when titles have quotes History + // Cooperative can''t create a proper meta tag + var titleRe = /(.*)/; + var m = titleRe.exec(doc.getElementsByTagName("body")[0].innerHTML); + newItem.title = m[1]; + associateMeta(newItem, metaTags, "Journal", "publicationTitle"); associateMeta(newItem, metaTags, "Volume", "volume"); associateMeta(newItem, metaTags, "Issue", "issue"); @@ -2572,11 +2578,17 @@ REPLACE INTO "translators" VALUES ('c54d1932-73ce-dfd4-a943-109380e06574', '2006 } }'); -REPLACE INTO "translators" VALUES ('fcf41bed-0cbc-3704-85c7-8062a0068a7a', '2006-10-02 17:00:00', 1, 100, 12, 'PubMed', 'Simon Kornblith', '^http://www\.ncbi\.nlm\.nih\.gov/entrez/query\.fcgi\?(?:.*db=PubMed.*list_uids=[0-9]|.*list_uids=[0-9].*db=PubMed|.*db=PubMed.*CMD=search|.*CMD=search.*db=PubMed)', +REPLACE INTO "translators" VALUES ('fcf41bed-0cbc-3704-85c7-8062a0068a7a', '2006-10-23 00:23:00', 1, 100, 12, 'PubMed', 'Simon Kornblith', '^http://www\.ncbi\.nlm\.nih\.gov/entrez/query\.fcgi\?.*db=PubMed', 'function detectWeb(doc, url) { + var namespace = doc.documentElement.namespaceURI; + var nsResolver = namespace ? function(prefix) { + if (prefix == ''x'') return namespace; else return null; + } : null; + if(doc.location.href.indexOf("list_uids=") >= 0) { return "journalArticle"; - } else { + } else if(doc.evaluate(''//div[@class="ResultSet"]/table/tbody'', doc, + nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) { return "multiple"; } } @@ -2754,6 +2766,8 @@ REPLACE INTO "translators" VALUES ('951c027d-74ac-47d4-a107-9c3069ab7b48', '2006 var translator = Zotero.loadTranslator("import"); translator.setTranslator("5e3ad958-ac79-463d-812b-a86a9235c28f"); translator.setHandler("itemDone", function(obj, newItem) { + newItem.itemType = "webpage"; + // use document title if none given in dublin core if(!newItem.title) { newItem.title = doc.title; @@ -7336,13 +7350,13 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '200 - + - + @@ -7579,7 +7593,7 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/chicago-note.c '); -REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/mla.csl', '2006-10-02 17:00:00', 'Modern Language Association', +REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/mla.csl', '2006-10-23 00:21:00', 'Modern Language Association', '