From 445ff98277cbdd0e9937931cd35096b594e36776 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 21 Nov 2006 07:14:27 +0000 Subject: [PATCH] - made doGet handle multiple urls, with processor/done style interface (as in processDocuments). this should be backwards compatible - beginnings of mapping for new item types - fixes for Word integration (because i was using it to write a paper) --- chrome/content/zotero/addCitationDialog.js | 2 +- chrome/content/zotero/bibliography.js | 3 + chrome/content/zotero/xpcom/cite.js | 45 +++++++++++++-- chrome/content/zotero/xpcom/integration.js | 24 ++++---- chrome/content/zotero/xpcom/translate.js | 2 +- chrome/content/zotero/xpcom/utilities.js | 24 +++++++- scrapers.sql | 67 ++++------------------ 7 files changed, 93 insertions(+), 74 deletions(-) diff --git a/chrome/content/zotero/addCitationDialog.js b/chrome/content/zotero/addCitationDialog.js index a5fbc20233..b0eaf819c5 100644 --- a/chrome/content/zotero/addCitationDialog.js +++ b/chrome/content/zotero/addCitationDialog.js @@ -127,7 +127,7 @@ var Zotero_Citation_Dialog = new function () { } function accept() { - var io = window.arguments[0]; + var io = window.arguments[0].wrappedJSObject; if(_multipleSourcesOn) { treeItemSelected(); // store locator info diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js index d20a6429dd..44c1c4dd61 100644 --- a/chrome/content/zotero/bibliography.js +++ b/chrome/content/zotero/bibliography.js @@ -40,6 +40,9 @@ var Zotero_File_Interface_Bibliography = new function() { */ function init() { _io = window.arguments[0]; + if(_io.wrappedJSObject){ + _io = _io.wrappedJSObject; + } var listbox = document.getElementById("style-popup"); var styleMenu = document.getElementById("style-menu"); diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 6829883243..a9c85df019 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -1660,7 +1660,25 @@ Zotero.CSL.FormattedString.prototype.appendDate = function(date, element) { interview:"interview", film:"motion picture", artwork:"graphic", - website:"webpage" + webpage:"webpage", + report:"paper-conference", // ?? + bill:"bill", + case:"legal case", + hearing:"bill", // ?? + patent:"patent", + statute:"bill", // ?? + email:"personal communication", + map:"map", + blogPost:"webpage", + instantMessage:"personal communication", + forumPost:"webpage", + audioRecording:"song", // ?? + presentation:"paper-conference", + videoRecording:"motion picture", + tvBroadcast:"motion picture", + radioBroadcast:"motion picture", + podcast:"speech", // ?? + computerProgram:"book" // ?? }; // TODO: check with Elena/APA/MLA on this Zotero.CSL.Global.fallbackTypeMappings = { @@ -1675,7 +1693,24 @@ Zotero.CSL.Global.fallbackTypeMappings = { interview:"book", film:"book", artwork:"book", - website:"article" + webpage:"article", + report:"book", + bill:"book", + case:"book", + hearing:"book", + patent:"book", + statute:"book", + email:"article", + map:"article", + blogPost:"article", + instantMessage:"article", + audioRecording:"book", + presentation:"article", + videoRecording:"book", + tvBroadcast:"book", + radioBroadcast:"book", + podcast:"book", + computerProgram:"book" }; Zotero.CSL.prototype._getTypeFromItem = function(item) { @@ -1699,8 +1734,10 @@ Zotero.CSL.prototype._separateItemCreators = function(item) { var translatorID = Zotero.CreatorTypes.getID("translator"); var creators = item.getCreators(); - for(var j in creators) { - var creator = creators[j]; + Zotero.debug("here come the creators"); + Zotero.debug(creators); + for each(var creator in creators) { + Zotero.debug(creator); if(creator.creatorTypeID == editorID) { editors.push(creator); diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 83e7c303e8..2dd4a392b2 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -361,12 +361,11 @@ Zotero.Integration.SOAP = new function() { this.setDocPrefs = setDocPrefs; var _sessions = new Array(); - var window; + var watcher; function init() { - window = Components.classes["@mozilla.org/appshell/appShellService;1"] - .getService(Components.interfaces.nsIAppShellService) - .hiddenDOMWindow; + watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher); } /* @@ -391,9 +390,12 @@ Zotero.Integration.SOAP = new function() { for(var i=3; i 1) callAgain = true; + var url = urls.shift(); + } + if(this.translate.locationIsProxied) { url = Zotero.Ingester.ProxyMonitor.properToProxy(url); } @@ -361,9 +370,20 @@ Zotero.Utilities.Ingester.HTTP.prototype.doGet = function(url, onDone) { } var translate = this.translate; + var me = this; + Zotero.Utilities.HTTP.doGet(url, function(xmlhttp) { try { - onDone(xmlhttp.responseText, xmlhttp); + if(processor) { + processor(xmlhttp.responseText, xmlhttp); + } + + // call again if multiple urls were passed + if(callAgain) { + me.doGet(urls, processor, done); + } else if(done) { + done(); + } } catch(e) { translate._translationComplete(false, e); } diff --git a/scrapers.sql b/scrapers.sql index f58c4d8b1c..4ea0a3a756 100644 --- a/scrapers.sql +++ b/scrapers.sql @@ -1,4 +1,4 @@ --- 103 +-- 104 -- ***** BEGIN LICENSE BLOCK ***** -- @@ -22,7 +22,7 @@ -- Set the following timestamp to the most recent scraper update date -REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-11-01 16:30:00')); +REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-11-20 23:10:00')); REPLACE INTO "translators" VALUES ('96b9f483-c44d-5784-cdad-ce21b984fe01', '2006-10-02 17:00:00', 1, 100, 4, 'Amazon.com', 'Simon Kornblith', '^http://www\.amazon\.com/', 'function detectWeb(doc, url) { @@ -482,7 +482,7 @@ REPLACE INTO "translators" VALUES ('88915634-1af6-c134-0171-56fd198235ed', '2006 Zotero.wait(); }'); -REPLACE INTO "translators" VALUES ('d921155f-0186-1684-615c-ca57682ced9b', '2006-10-02 17:00:00', 1, 100, 4, 'JSTOR', 'Simon Kornblith', '^http://www\.jstor\.org/(?:view|browse|search/)', +REPLACE INTO "translators" VALUES ('d921155f-0186-1684-615c-ca57682ced9b', '2006-11-20 23:10:00', 1, 100, 4, 'JSTOR', 'Simon Kornblith', '^http://www\.jstor\.org/(?:view|browse|search/)', 'function detectWeb(doc, url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { @@ -501,22 +501,7 @@ REPLACE INTO "translators" VALUES ('d921155f-0186-1684-615c-ca57682ced9b', '2006 return "journalArticle"; } }', -'function getList(urls, each, done) { - var url = urls.shift(); - Zotero.Utilities.HTTP.doGet(url, function(text) { - if(each) { - each(text); - } - - if(urls.length) { - getList(urls, each, done); - } else if(done) { - done(text); - } - }); -} - -function getJSTORAttachment(viewURL) { +'function getJSTORAttachment(viewURL) { var viewRe = new RegExp("(^http://[^/]+/)view([^?]+)"); var m = viewRe.exec(viewURL); if(m) { @@ -615,7 +600,7 @@ function doWeb(doc, url) { Zotero.Utilities.HTTP.doGet(''http://www.jstor.org/browse?citationAction=removeAll&confirmRemAll=on&viewCitations=1'', function() { // clear marked // Mark all our citations - getList(saveCitations, null, function() { // mark this + Zotero.Utilities.HTTP.doGet(saveCitations, null, function() { // mark this Zotero.Utilities.HTTP.doGet(''http://www.jstor.org/browse/citations.txt?exportAction=Save+as+Text+File&exportFormat=cm&viewCitations=1'', function(text) { // get marked var k = 0; @@ -3065,26 +3050,11 @@ REPLACE INTO "translators" VALUES ('3e684d82-73a3-9a34-095f-19b112d88bbf', '2006 Zotero.wait(); }'); -REPLACE INTO "translators" VALUES ('57a00950-f0d1-4b41-b6ba-44ff0fc30289', '2006-08-26 1:10:00', 1, 100, 4, 'Google Zotero', 'Simon Kornblith', '^http://scholar\.google\.com/scholar', +REPLACE INTO "translators" VALUES ('57a00950-f0d1-4b41-b6ba-44ff0fc30289', '2006-11-20 23:00:00', 1, 100, 4, 'Google Scholar', 'Simon Kornblith', '^http://scholar\.google\.com/scholar', 'function detectWeb(doc, url) { return "multiple"; }', -'function getList(urls, each, done) { - var url = urls.shift(); - Zotero.Utilities.HTTP.doGet(url, function(text) { - if(each) { - each(text); - } - - if(urls.length) { - getList(urls, each, done); - } else if(done) { - done(text); - } - }); -} - -function doWeb(doc, url) { +'function doWeb(doc, url) { var namespace = doc.documentElement.namespaceURI; var nsResolver = namespace ? function(prefix) { if (prefix == ''x'') return namespace; else return null; @@ -3168,7 +3138,7 @@ function doWeb(doc, url) { item.complete(); }); - getList(urls, function(text) { + Zotero.Utilities.HTTP.doGet(urls, function(text) { translator.setString(text); translator.translate(); }, function() { Zotero.done() }); @@ -3419,7 +3389,7 @@ function doWeb(doc, url) { Zotero.wait(); }'); -REPLACE INTO "translators" VALUES ('ce7a3727-d184-407f-ac12-52837f3361ff', '2006-10-02 17:00:00', 1, 100, 4, 'New York Times', 'Simon Kornblith', '^http://(?:query\.nytimes\.com/search/query|(?:www\.)?nytimes\.com/.+)', +REPLACE INTO "translators" VALUES ('ce7a3727-d184-407f-ac12-52837f3361ff', '2006-11-20 23:10:00', 1, 100, 4, 'New York Times', 'Simon Kornblith', '^http://(?:query\.nytimes\.com/search/query|(?:www\.)?nytimes\.com/.+)', 'function detectWeb(doc, url) { if(doc.title.substr(0, 30) == "The New York Times: Search for") { var namespace = doc.documentElement.namespaceURI; @@ -3439,22 +3409,7 @@ REPLACE INTO "translators" VALUES ('ce7a3727-d184-407f-ac12-52837f3361ff', '2006 } } }', -'function getList(urls, each, done) { - var url = urls.shift(); - Zotero.Utilities.HTTP.doGet(url, function(text) { - if(each) { - each(text, url); - } - - if(urls.length) { - getList(urls, each, done); - } else if(done) { - done(text); - } - }); -} - -function associateMeta(newItem, metaTags, field, zoteroField) { +'function associateMeta(newItem, metaTags, field, zoteroField) { if(metaTags[field]) { newItem[zoteroField] = metaTags[field]; } @@ -3566,7 +3521,7 @@ function doWeb(doc, url) { urls.push(i); } - getList(urls, scrape, function() { Zotero.done(); }, null); + Zotero.Utilities.HTTP.doGet(urls, scrape, function() { Zotero.done(); }, null); Zotero.wait(); } else {