Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zotero/translators
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Aug 21, 2011
2 parents eb80aa7 + d7f3cca commit 0fa6371
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 317 deletions.
6 changes: 4 additions & 2 deletions Ab Imperio.js

Large diffs are not rendered by default.

234 changes: 55 additions & 179 deletions AlterNet.js

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions Bezneng Gajit.js

Large diffs are not rendered by default.

116 changes: 66 additions & 50 deletions EBSCOhost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@
"priority": 100,
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2011-08-03 01:00:36"
"lastUpdated": "2011-08-07 11:11:54"
}

function detectWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') { return namespace; } else { return null; }
} : null;
// The Scientific American Archive breaks this translator, disabling
try {
var databases = doc.evaluate("//span[@class = 'selected-databases']", doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
if(databases.indexOf("Scientific American Archive Online") != -1) {
return false;
}
} catch(e) {
}


// See if this is a search results or folder results page
var searchResult = doc.evaluate('//ul[@class="result-list" or @class="folder-list"]/li/div[@class="result-list-record" or @class="folder-item"]', doc, nsResolver,
XPathResult.ANY_TYPE, null).iterateNext();
var searchResult = doc.evaluate('//ul[@class="result-list" or @class="folder-list"]/li/div[@class="result-list-record" or @class="folder-item"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
if(searchResult) {
return "multiple";
}
Expand All @@ -44,19 +34,26 @@ function detectWeb(doc, url) {
* given the text of the delivery page, downloads an item
*/
function downloadFunction(text, url) {
var an = url.match(/_(\d+)_AN/);
var pdf = false;
var risDate = false;
var queryString = {};
url.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
pdf = "/ehost/pdfviewer/pdfviewer?sid="+queryString["sid"]+"&vid="+queryString["vid"];

if (text.match(/^Y1\s+-(.*)$/m)) {
risDate = text.match(/^Y1\s+-(.*)$/m);
}

if (!text.match(/^TY\s\s-/m)) { text = text+"\nTY - JOUR\n"; }
// load translator for RIS
var translator = Zotero.loadTranslator("import");
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
translator.setString(text);
Zotero.debug(text);
translator.setHandler("itemDone", function(obj, item) {
if (text.match(/^L3\s+-\s*(.*)/m)) {
item.DOI = text.match(/^L3\s+\-\s*(.*)/m)[1];
Expand All @@ -70,42 +67,56 @@ function downloadFunction(text, url) {
if (text.match(/^T1\s+-/m)) {
item.title = text.match(/^T1\s+-\s*(.*)/m)[1];
}

// If we have a double year, eliminate one
var year = item.date.match(/\d{4}/);
if (year && item.date.replace(year[0],"").indexOf(year[0]) !== -1) {
item.date = item.date.replace(year[0],"");

// Get the accession number from URL or elsewhere
if (an) {
an = an[1];
item.callNumber = an;
} else {
an = item.url.match(/AN=([0-9]+)/);
if (an) an = an[1];
}

// RIS translator tries to download the link in "UR" this leads to unhappyness
item.attachments = [];

if (risDate) {
var year = risDate[1].match(/\d{4}/);
var extra = risDate[1].match(/\/([^\/]+)$/);
// If we have a double year in risDate, use last section
if (year && extra && extra[1].indexOf(year[0]) !== -1) {
item.date = extra[1];
}
}

// RIS translator tries to download the link in "UR"
item.attachments = [];

// But keep the stable link as a link attachment
if(item.url) {
item.attachments.push({url: item.url,
// Trim the ⟨=cs suffix -- EBSCO can't find the record with it!
item.url = item.url.replace(/(AN=[0-9]+)=[a-z]{2}/,"$1");
item.attachments.push({url: item.url+"&scope=cite",
title: "EBSCO Record",
mimeType: "text/html",
snapshot: false});
item.url = "";
}
// A lot of extra info is jammed into notes by the RIS translator
item.notes = [];
Zotero.Utilities.doGet(pdf, function (text) {
//Z.debug(text);
// Since order of requests might matter, let's grab the stable link, then the PDF
Zotero.Utilities.doGet(item.url, function (doc) { Zotero.Utilities.doGet(pdf, function (text) {
var realpdf = text.match(/<embed id="pdfEmbed"[^>]*>/);
if(realpdf) {
realpdf = text.match(/<embed[^>]*src="([^"]+)"/);
if (realpdf) {
realpdf = realpdf[1];
item.attachments.push({url:realpdf.replace(/&amp;/g, "&"),
realpdf = realpdf[1].replace(/&amp;/g, "&").replace(/K=\d+/,"K="+an);
Zotero.debug("PDF for "+item.title+": "+realpdf);
item.attachments.push({url:realpdf,
title: "EBSCO Full Text",
mimeType:"application/pdf"});
}
}
}, function () { item.complete(); });
}, function () { item.complete(); }); }, function () { return true; });
});
translator.translate();

Zotero.done();
}

var host;
Expand Down Expand Up @@ -159,16 +170,15 @@ function doWeb(doc, url) {

var run = function(urls, infos) {
var url, info;
if (urls.length == 0 || folderInfos.length == 0) {
if (urls.length == 0 || infos.length == 0) {
Zotero.done();
return true;
}
url = urls.shift();
info = infos.shift();
Zotero.Utilities.processDocuments(url,
function (newDoc) { doDelivery(doc, nsResolver, info); },
function () {run(urls, infos);
});
function (newDoc) { doDelivery(doc, nsResolver, info, function () { run(urls, infos) }); },
function () { return true; });
};

run(urls, infos);
Expand All @@ -177,30 +187,37 @@ function doWeb(doc, url) {
});
} else {
/* Individual record. Record key exists in attribute for add to folder link in DOM */
doDelivery(doc, nsResolver, null);
doDelivery(doc, nsResolver, null, function () { Zotero.done(); return true; });
Zotero.wait();
}
}
function doDelivery(doc, nsResolver, folderData) {
function doDelivery(doc, nsResolver, folderData, onDone) {
if(folderData === null) {
/* Get the db, AN, and tag from ep.clientData instead */
var script;
var scripts = doc.evaluate('//script[@type="text/javascript"]', doc, nsResolver, XPathResult.ANY_TYPE, null);
while (script = scripts.iterateNext().textContent) {
if (script.indexOf("var ep") > -1) { break; }
script = "";
var clientData = script.match(/var ep\s*=\s*({[^;]*});/);
if (clientData) break;
}
}
if (!clientData) {return false;}
/* We now have the script containing ep.clientData */

if (script === "") { return; }
/* We now have the script containing ep.clientData */

/* The JSON is technically invalid, since it doesn't quote the
attribute names-- we pull out the valid bit inside it. */
var clientData = script.match(/var ep\s*=\s*({[^;]*});/);
if (!clientData) { return false; }
clientData = clientData[1].match(/"currentRecord"\s*:\s*({[^}]*})/);
/* If this starts throwing exceptions, we should probably start try-elsing it */
clientData = JSON.parse(clientData[1]);
/* The JSON is technically invalid, since it doesn't quote the
attribute names-- we pull out the valid bit inside it. */
var clientData = script.match(/var ep\s*=\s*({[^;]*});/);
if (!clientData) { return false; }
clientData = clientData[1].match(/"currentRecord"\s*:\s*({[^}]*})/);
/* If this starts throwing exceptions, we should probably start try-elsing it */
folderData = JSON.parse(clientData[1]);
} else {
/* Ditto for this. */
// The attributes are a little different
folderData = JSON.parse(folderData);
folderData.Db = folderData.db;
folderData.Term = folderData.uiTerm;
folderData.Tag = folderData.uiTag;
}

var postURL = doc.evaluate('//form[@id="aspnetForm"]/@action', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;

Expand All @@ -211,9 +228,8 @@ function doDelivery(doc, nsResolver, folderData) {
);

/* ExportFormat = 1 for RIS file */
postURL = host+"/ehost/delivery/ExportPanelSave/"+clientData.Db+"_"+clientData.Term+"_"+clientData.Tag+"?sid="+queryString["sid"]+"&vid="+queryString["vid"]+"&bdata="+queryString["bdata"]+"&theExportFormat=1";

Zotero.Utilities.HTTP.doGet(postURL, function (text) { downloadFunction(text, postURL); });
postURL = host+"/ehost/delivery/ExportPanelSave/"+folderData.Db+"_"+folderData.Term+"_"+folderData.Tag+"?sid="+queryString["sid"]+"&vid="+queryString["vid"]+"&bdata="+queryString["bdata"]+"&theExportFormat=1";
Zotero.Utilities.HTTP.doGet(postURL, function (text) { downloadFunction(text, postURL); }, onDone);
}
/** BEGIN TEST CASES **/
var testCases = [
Expand Down
18 changes: 18 additions & 0 deletions Google Blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
"lastUpdated": "2011-07-30 03:19:03"
}

/*
Google Blogs Translator
Copyright (C) 2011 Avram Lyon, [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function detectWeb(doc, url) {
return "multiple";
}
Expand Down
39 changes: 25 additions & 14 deletions ISI Web of Knowledge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"translatorID": "594ebe3c-90a0-4830-83bc-9502825a6810",
"label": "ISI Web of Knowledge",
"creator": "Michael Berkowitz, Avram Lyon",
"target": "(WOS_GeneralSearch|product=WOS|product=CABI)",
"target": "^https?://[^/]*webofknowledge\\.com/",
"minVersion": "2.1",
"maxVersion": "",
"priority": 100,
Expand All @@ -12,9 +12,9 @@
}

function detectWeb(doc, url) {
if ((doc.title.indexOf("Web of Science Results") != -1) | (doc.title.indexOf("CABI Results") != -1)) {
if (url.indexOf("full_record.do") !== -1) {
return "multiple";
} else if (url.indexOf("full_record.do") != -1) {
} else if ((doc.title.indexOf(" Results") !== -1)) {
return "journalArticle";
}
}
Expand Down Expand Up @@ -55,13 +55,24 @@ function fetchIds(ids, url) {
var product = url.match("product=([^\&]+)\&")[1];
Zotero.Utilities.processDocuments(ids, function (newDoc) {
var url = newDoc.location.href;
var sid = newDoc.evaluate('//input[@name="selectedIds"]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().value;
var nid = newDoc.evaluate('//input[@name="SID"]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().value;
var post2 = 'product='+product+'&product_sid=' + nid + '&plugin=&product_st_thomas=http://esti.isiknowledge.com:8360/esti/xrpc&export_ref.x=0&export_ref.y=0';
var post = 'action=go&mode=quickOutput&product='+product+'&SID=' + nid + '&format=ref&fields=BibAbs&mark_id='+product+'&count_new_items_marked=0&selectedIds=' + sid + '&qo_fields=bib&endnote.x=95&endnote.y=12&save_options=default';
Zotero.Utilities.doPost('http://apps.isiknowledge.com/OutboundService.do', post, function (text, obj) {
Zotero.Utilities.doPost('http://pcs.isiknowledge.com/uml/uml_view.cgi', post2, function (text, obj) {
//Zotero.debug(text);
var names = ["recordID", "colName", "SID", "selectedIds", "sortBy", "qid", "product" ];
var values = {};
var n;
for each (n in names) {
values[n] = newDoc.evaluate('//input[@name="'+n+'"]', newDoc, null, XPathResult.ANY_TYPE, null).iterateNext().value;
}
var post2 = 'locale=en_US&fileOpt=fieldtagged'+
'&colName=' + values.colName + '&action=saveDataToRef'+
'&qid='+values.qid+'&sortBy='+values.sortBy.replace(/;/g,"%3;")+
'&SID='+values.SID+'&product='+values.product+'&filters=FUNDING+SUBJECT_CATEGORY+JCR_CATEGORY+LANG+IDS+PAGEC+SABBR+CITREFC+ISSN+PUBINFO+KEYWORDS+CITTIMES+ADDRS+CONFERENCE_SPONSORS+DOCTYPE+ABSTRACT+CONFERENCE_INFO+SOURCE+TITLE+AUTHORS++&numRecords=1&locale=en_US';
var post = 'action=go&viewType=fullRecord&product='+values.product
+'&mark_id='+values.product+'&colName=' + values.colName
+'&recordID='+values.recordID.replace(/;/g,"%3;")
+'&sortBy='+values.sortBy.replace(/;/g,"%3;")+'&mode=outputService'
+'&qid='+values.qid+'&SID='+values.SID+
+'&format=saveToRef&filters=FUNDING+SUBJECT_CATEGORY+JCR_CATEGORY+LANG+IDS+PAGEC+SABBR+CITREFC+ISSN+PUBINFO+KEYWORDS+CITTIMES+ADDRS+CONFERENCE_SPONSORS+DOCTYPE+ABSTRACT+CONFERENCE_INFO+SOURCE+TITLE+AUTHORS++&selectedIds=3&mark_to=&mark_from=&count_new_items_marked=0&value%28record_select_type%29=selrecords&marked_list_candidates=3&LinksAreAllowedRightClick=CitedRefList.do&LinksAreAllowedRightClick=CitingArticles.do&LinksAreAllowedRightClick=OneClickSearch.do&LinksAreAllowedRightClick=full_record.do&fields_selection=FUNDING+SUBJECT_CATEGORY+JCR_CATEGORY+LANG+IDS+PAGEC+SABBR+CITREFC+ISSN+PUBINFO+KEYWORDS+CITTIMES+ADDRS+CONFERENCE_SPONSORS+DOCTYPE+ABSTRACT+CONFERENCE_INFO+SOURCE+TITLE+AUTHORS++&save_options=fieldtagged';
Zotero.Utilities.doPost('http://apps.webofknowledge.com/OutboundService.do',post, function (text, obj) {
Zotero.Utilities.doPost('http://ets.webofknowledge.com/ETS/saveDataToRef.do',post2, function (text, obj) {
importer.setString(text);
importer.setHandler("itemDone", function (obj, item) {
item.attachments = [{url: url, type: "text/html", title: "ISI Web of Knowledge Record"}];
Expand All @@ -87,8 +98,8 @@ function detectImport() {
return false;
}
}
}
}
}
}

function processTag(item, field, content) {
Expand Down Expand Up @@ -140,8 +151,8 @@ function processTag(item, field, content) {
}
var year = item.date.match(/\d{4}/);
// If we have a double year, eliminate one
if (year && item.date.replace(year,"").indexOf(year) !== -1)
item.date = item.date.replace(year,"");
if (year && item.date.replace(year[0],"").indexOf(year[0]) !== -1)
item.date = item.date.replace(year[0],"");
} else if (field == "VL") {
item.volume = content;
} else if (field == "IS") {
Expand Down Expand Up @@ -863,4 +874,4 @@ var testCases = [
]
}
]
/** END TEST CASES **/
/** END TEST CASES **/
13 changes: 9 additions & 4 deletions ProQuest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"priority": 100,
"inRepository": true,
"translatorType": 4,
"lastUpdated": "2011-08-02 02:41:31"
"lastUpdated": "2011-08-03 11:08:32"
}

/*
Expand Down Expand Up @@ -102,8 +102,8 @@ function scrape (doc) {
var record_rows = doc.evaluate('//div[@class="display_record_indexing_row"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
var abstract_link = doc.evaluate('//a[@class="formats_base_sprite format_abstract"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
if (!record_rows && abstract_link) {
Zotero.Utilities.processDocuments(abstract_link.href, scrape, function() {Zotero.done();});
return true;
Zotero.Utilities.processDocuments(abstract_link.href, scrape, function() {Zotero.done();});
return true;
}
var url = doc.location.href;

Expand Down Expand Up @@ -191,11 +191,15 @@ function scrape (doc) {
case "Copyright":
item.rights = value; break;
case "Database":
value = value.replace(/^\d\s+databasesView list\s+Hide list/,'');
value = value.replace(/(ProQuest.*)(ProQuest.*)/,'$1; $2');
item.libraryCatalog = value; break;
case "Document URL":
item.attachments.push({url:value.replace(/\?accountid=[0-9]+$/,''),
item.attachments.push({url:value.replace(/\?accountid=[0-9]+$/,'')+"/abstract",
title: "ProQuest Record",
mimeType: "text/html"}); break;
case "ProQuest Document ID":
item.callNumber = value; break;
case "Language of Publication":
item.language = value; break;
case "Section":
Expand Down Expand Up @@ -337,6 +341,7 @@ var testCases = [
"publisher": "Menno Simons College",
"ISSN": "00084697",
"language": "English",
"callNumber": "213445241",
"rights": "Copyright Peace Research May 1995",
"proceedingsTitle": "Peace Research",
"libraryCatalog": "ProQuest",
Expand Down
20 changes: 19 additions & 1 deletion Tatknigafund.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
"lastUpdated":"2009-12-31 16:20:00"
}

/*
Tatknigafund Translator
Copyright (C) 2009-2011 Avram Lyon, [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
This translator is designed for the Tatar Book Repository, http://www.tatknigafund.ru/ .
At present, it imports the limited metadata that the repository exposes about its books,
Expand Down Expand Up @@ -108,4 +126,4 @@ function doWeb(doc, url) {
item.complete();
}, function() {Zotero.done();});
Zotero.wait();
}
}
Loading

0 comments on commit 0fa6371

Please sign in to comment.