Trans: Change PubMed to support import

This commit is contained in:
Avram Lyon 2011-01-27 05:44:14 +00:00
parent 5ff4bd6326
commit 6958518063

View File

@ -1,14 +1,15 @@
{
"translatorID":"fcf41bed-0cbc-3704-85c7-8062a0068a7a",
"translatorType":12,
"translatorType":13,
"label":"NCBI PubMed",
"creator":"Simon Kornblith, Michael Berkowitz, Avram Lyon, and Rintze Zelle",
"target":"https?://[^/]*(www|preview)\\.ncbi\\.nlm\\.nih\\.gov[^/]*/(pubmed|sites/pubmed|sites/entrez|entrez/query\\.fcgi\\?.*db=PubMed)",
"minVersion":"2.1b1",
"maxVersion":"",
"priority":100,
"configOptions":{"dataMode":"block"},
"inRepository":true,
"lastUpdated":"2010-11-17 10:15:00"
"lastUpdated":"2011-01-27 10:15:00"
}
function detectWeb(doc, url) {
@ -61,12 +62,45 @@ function detectSearch(item) {
function lookupPMIDs(ids, doc) {
var newUri = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=PubMed&tool=Zotero&retmode=xml&rettype=citation&id="+ids.join(",");
Zotero.debug(newUri);
Zotero.Utilities.HTTP.doGet(newUri, doImportFromText, function () {Zotero.done()});
Zotero.wait();
var newUri = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=PubMed&retmode=xml&rettype=citation&id="+ids.join(",");
Zotero.Utilities.HTTP.doGet(newUri, function(text) {
}
function doImport() {
var text = "";
var line;
while((line = Zotero.read(4096)) !== false) {
text += line;
}
return doImportFromText(text);
}
function detectImport() {
Zotero.debug("Detecting Pubmed content....");
var text = "";
var line;
while(line = Zotero.read(1000)) {
text += line;
// Look for the PubmedArticle tag in the first 1000 characters
if (text.match(/<PubmedArticle>/)) return "journalArticle";
else if (text.length > 1000) return false;
}
return false;
}
function doImportFromText(text) {
// Remove xml parse instruction and doctype
text = text.replace(/<!DOCTYPE[^>]*>/, "").replace(/<\?xml[^>]*\?>/, "");
if (!text.substr(0,1000).match(/<PubmedArticleSet>/)) {
// Pubmed data in the wild, perhaps copied from the web site's search results,
// can be missing the <PubmedArticleSet> root tag. Let's add a pair!
Zotero.debug("No root <PubmedArticleSet> tag found, wrapping in a new root tag.");
text = "<PubmedArticleSet>" + text + "</PubmedArticleSet>";
}
var xml = new XML(text);
for(var i=0; i<xml.PubmedArticle.length(); i++) {
@ -167,9 +201,6 @@ function lookupPMIDs(ids, doc) {
newItem.publicationTitle = Zotero.Utilities.capitalizeTitle(newItem.publicationTitle);
newItem.complete();
}
Zotero.done();
});
}
function doWeb(doc, url) {