1f0d24ceef
- fix accessibility of createContextObject in Zotero.Utilities - improved CrossRef translator
141 lines
No EOL
4.5 KiB
JavaScript
141 lines
No EOL
4.5 KiB
JavaScript
{
|
|
"translatorID":"11645bd1-0420-45c1-badb-53fb41eeb753",
|
|
"translatorType":8,
|
|
"label":"CrossRef",
|
|
"creator":"Simon Kornblith",
|
|
"target":"http://partneraccess.oclc.org/",
|
|
"minVersion":"1.0.0b3.r1",
|
|
"maxVersion":"",
|
|
"priority":100,
|
|
"inRepository":true,
|
|
"lastUpdated":"2007-09-15 21:00:00"
|
|
}
|
|
|
|
function detectSearch(item) {
|
|
if(item.itemType == "journalArticle") {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function fixAuthorCapitalization(string) {
|
|
if(string.toUpperCase() == string) {
|
|
string = string.toLowerCase().replace(/\b[a-z]/g, function(m) { return m[0].toUpperCase() });
|
|
}
|
|
return string;
|
|
}
|
|
|
|
function processCrossRef(xmlOutput) {
|
|
xmlOutput = xmlOutput.replace(/<\?xml[^>]*\?>/, "");
|
|
|
|
// parse XML with E4X
|
|
try {
|
|
var xml = new XML(xmlOutput);
|
|
} catch(e) {
|
|
return false;
|
|
}
|
|
|
|
// ensure status is valid
|
|
if(!xml.doi_record.length()) return false;
|
|
if(xml.doi_record[0].crossref.journal.length()) {
|
|
var item = new Zotero.Item("journalArticle");
|
|
var itemXML = xml.doi_record.crossref.journal;
|
|
var refXML = itemXML.journal_article;
|
|
var metadataXML = itemXML.journal_metadata;
|
|
|
|
item.ISSN = itemXML.journal_metadata.issn.toString();
|
|
item.publicationTitle = itemXML.journal_metadata.full_title.toString();
|
|
item.journalAbbreviation = itemXML.journal_metadata.abbrev_title.toString();
|
|
item.volume = itemXML.journal_issue.journal_volume.volume.toString();
|
|
item.issue = itemXML.journal_issue.issue.toString();
|
|
} else if(xml.doi_record[0].crossref.book.length()) {
|
|
var item = new Zotero.Item("book");
|
|
var refXML = xml.doi_record[0].crossref.book.book_metadata;
|
|
var metadataXML = refXML;
|
|
var seriesXML = metadataXML.series_metadata;
|
|
|
|
item.place = metadataXML.publisher.publisher_place.toString();
|
|
} else if(xml.doi_record[0].crossref.conference.length()) {
|
|
var item = new Zotero.Item("conferencePaper");
|
|
var itemXML = xml.doi_record[0].crossref.conference;
|
|
var refXML = itemXML.conference_paper;
|
|
var metadataXML = itemXML.proceedingsMetadata;
|
|
var seriesXML = metadataXML.series_metadata;
|
|
|
|
item.publicationTitle = itemXML.proceedings_metadata.proceedings_title.toString();
|
|
item.place = itemXML.event_metadata.conference_location.toString();
|
|
item.conferenceName = itemXML.event_metadata.conference_name.toString();
|
|
}
|
|
|
|
var contributors = refXML.contributors.children();
|
|
|
|
if(metadataXML.isbn.length()) item.ISBN = metadataXML.isbn[0].toString();
|
|
if(metadataXML.issn.length()) item.ISSN = metadataXML.issn[0].toString();
|
|
item.publisher = metadataXML.publisher.publisher_name.toString();
|
|
item.edition = metadataXML.edition_number.toString();
|
|
if(!item.volume) item.volume = metadataXML.volume.toString();
|
|
|
|
if(seriesXML && seriesXML.length()) {
|
|
if(seriesXML.contributors.length()) {
|
|
contributors += seriesXML.contributors.children();
|
|
}
|
|
item.seriesNumber = seriesXML.series_number.toString();
|
|
}
|
|
|
|
for each(var creatorXML in contributors) {
|
|
var creator = {creatorType:"author"};
|
|
if(creatorXML.contributor_role == "editor") {
|
|
creator.creatorType = "editor";
|
|
} else if(creatorXML.contributor_role == "translator") {
|
|
creator.creatorType = "translator";
|
|
} else if(creatorXML.contributor_role == "chair") {
|
|
creator.creatorType = "contributor";
|
|
}
|
|
|
|
if(creatorXML.localName() == "organization") {
|
|
creator.fieldMode = 1;
|
|
creator.lastName = creatorXML.toString();
|
|
} else if(creatorXML.localName() == "person_name") {
|
|
creator.firstName = fixAuthorCapitalization(creatorXML.given_name.toString());
|
|
creator.lastName = fixAuthorCapitalization(creatorXML.surname.toString());
|
|
}
|
|
item.creators.push(creator);
|
|
}
|
|
|
|
item.date = refXML.publication_date.year.toString();
|
|
if(refXML.publication_date.month.length()) {
|
|
item.date = refXML.publication_date.month.toString()+"/"+item.date;
|
|
}
|
|
|
|
if(refXML.pages.length()) {
|
|
item.pages = refXML.pages.first_page.toString();
|
|
if(refXML.pages.last_page.length()) {
|
|
item.pages += "-"+refXML.pages.last_page.toString();
|
|
}
|
|
}
|
|
|
|
item.DOI = refXML.doi_data.doi.toString();
|
|
item.url = refXML.doi_data.resource.toString();
|
|
item.title = refXML.titles.title.toString();
|
|
|
|
item.complete();
|
|
return true;
|
|
}
|
|
|
|
function doSearch(item) {
|
|
if(item.contextObject) {
|
|
var co = item.contextObject;
|
|
if(co.indexOf("url_ver=") == -1) {
|
|
co = "url_ver=Z39.88-2004&"+co;
|
|
}
|
|
} else {
|
|
var co = Zotero.Utilities.createContextObject(item);
|
|
}
|
|
|
|
Zotero.Utilities.HTTP.doGet("http://www.crossref.org/openurl?req_dat=zter:zter321&"+co+"&noredirect=true&format=unixref", function(responseText) {
|
|
processCrossRef(responseText);
|
|
Zotero.done();
|
|
});
|
|
|
|
Zotero.wait();
|
|
} |