{ "translatorID":"32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7", "translatorType":3, "label":"RIS", "creator":"Simon Kornblith", "target":"ris", "minVersion":"2.1.3", "maxVersion":"", "priority":100, "inRepository":true, "displayOptions":{"exportCharset":"UTF-8", "exportNotes":true}, "lastUpdated":"2011-04-01 20:50:00" } function detectImport() { var line; var i = 0; while((line = Zotero.read()) !== false) { line = line.replace(/^\s+/, ""); if(line != "") { if(line.substr(0, 6).match(/^TY {1,2}- /)) { return true; } else { if(i++ > 3) { return false; } } } } } var fieldMap = { ID:"itemID", T1:"title", T3:"series", JF:"publicationTitle", CY:"place", JA:"journalAbbreviation", M3:"DOI" }; var bookSectionFieldMap = { ID:"itemID", T1:"title", T3:"series", T2:"bookTitle", CY:"place", JA:"journalAbbreviation", M3:"DOI" }; var inputFieldMap = { TI:"title", CT:"title", CY:"place" }; // TODO: figure out if these are the best types for letter, interview, webpage var typeMap = { book:"BOOK", bookSection:"CHAP", journalArticle:"JOUR", magazineArticle:"MGZN", newspaperArticle:"NEWS", thesis:"THES", letter:"PCOMM", manuscript:"PAMP", interview:"PCOMM", film:"MPCT", artwork:"ART", report:"RPRT", bill:"BILL", "case":"CASE", hearing:"HEAR", patent:"PAT", statute:"STAT", map:"MAP", blogPost:"ELEC", webpage:"ELEC", instantMessage:"ICOMM", forumPost:"ICOMM", email:"ICOMM", audioRecording:"SOUND", presentation:"GEN", videoRecording:"VIDEO", tvBroadcast:"GEN", radioBroadcast:"GEN", podcast:"GEN", computerProgram:"COMP", conferencePaper:"CONF", document:"GEN" }; // supplements outputTypeMap for importing // TODO: DATA, MUSIC var inputTypeMap = { ABST:"journalArticle", ADVS:"film", CTLG:"magazineArticle", INPR:"manuscript", JFULL:"journalArticle", PAMP:"manuscript", SER:"book", SLIDE:"artwork", UNBILL:"manuscript", CPAPER:"conferencePaper", WEB:"webpage", EDBOOK:"book", MANSCPT:"manuscript", GOVDOC:"document" }; function processTag(item, tag, value) { if (tag != "N1" && tag != "AB" && Zotero.Utilities.unescapeHTML) { value = Zotero.Utilities.unescapeHTML(value); } if(fieldMap[tag]) { item[fieldMap[tag]] = value; } else if(inputFieldMap[tag]) { item[inputFieldMap[tag]] = value; } else if(tag == "TY") { // look for type // trim the whitespace that some providers (e.g. ProQuest) include value = Zotero.Utilities.trim(value); // first check typeMap for(var i in typeMap) { if(value == typeMap[i]) { item.itemType = i; } } // then check inputTypeMap if(!item.itemType) { if(inputTypeMap[value]) { item.itemType = inputTypeMap[value]; } else { // default to document item.itemType = "document"; } } } else if(tag == "JO") { if (item.itemType == "conferencePaper"){ item.conferenceName = value; } else { item.publicationTitle = value; } } else if(tag == "BT") { // ignore, unless this is a book or unpublished work, as per spec if(item.itemType == "book" || item.itemType == "manuscript") { item.title = value; } else { item.backupPublicationTitle = value; } } else if(tag == "T2") { item.backupPublicationTitle = value; } else if(tag == "A1" || tag == "AU") { // primary author (patent: inventor) // store Zotero "creator type" in temporary variable var tempType; if (item.itemType == "patent") { tempType = "inventor"; } else { tempType = "author"; } var names = value.split(/, ?/); item.creators.push({lastName:names[0], firstName:names[1], creatorType:tempType}); } else if(tag == "ED") { var names = value.split(/, ?/); item.creators.push({lastName:names[0], firstName:names[1], creatorType:"editor"}); } else if(tag == "A2") { // contributing author (patent: assignee) if (item.itemType == "patent") { if (item.assignee) { // Patents can have multiple assignees (applicants) but Zotero only allows a single // assignee field, so we have to concatenate them together item.assignee += ", "+value; } else { item.assignee = value; } } else { var names = value.split(/, ?/); item.creators.push({lastName:names[0], firstName:names[1], creatorType:"contributor"}); } } else if(tag == "Y1" || tag == "PY") { // year or date var dateParts = value.split("/"); if(dateParts.length == 1) { // technically, if there's only one date part, the file isn't valid // RIS, but EndNote writes this, so we have to too // Nick: RIS spec example records also only contain a single part // even though it says the slashes are not optional (?) item.date = value; } else { // in the case that we have a year and other data, format that way var month = parseInt(dateParts[1]); if(month) { month--; } else { month = undefined; } item.date = Zotero.Utilities.formatDate({year:dateParts[0], month:month, day:dateParts[2], part:dateParts[3]}); } } else if(tag == "Y2") { // the secondary date field can mean two things, a secondary date, or an // invalid EndNote-style date. let's see which one this is. // patent: application (filing) date -- do not append to date field var dateParts = value.split("/"); if(dateParts.length != 4 && item.itemType != "patent") { // an invalid date and not a patent. // It's from EndNote or Delphion (YYYY-MM-DD) if(item.date && value.indexOf(item.date) == -1) { // append existing year value += " " + item.date; } item.date = value; } else if (item.itemType == "patent") { // Date-handling code copied from above if(dateParts.length == 1) { // technically, if there's only one date part, the file isn't valid // RIS, but EndNote writes this, so we have to too // Nick: RIS spec example records also only contain a single part // even though it says the slashes are not optional (?) item.filingDate = value; } else { // in the case that we have a year and other data, format that way var month = parseInt(dateParts[1]); if(month) { month--; } else { month = undefined; } item.filingDate = Zotero.Utilities.formatDate({year:dateParts[0], month:month, day:dateParts[2], part:dateParts[3]}); } } // ToDo: Handle correctly formatted Y2 fields (secondary date) } else if(tag == "N1" || tag == "AB") { // notes if(value != item.title) { // why does EndNote do this!? var clean = Zotero.Utilities.cleanTags(value); if (clean == value) { // \n\n =>
, \n =>
//str = Zotero.Utilities.htmlSpecialChars(str);
value = '
' + value.replace(/\n\n/g, '
')
.replace(/\n/g, '
')
.replace(/\t/g, ' ')
.replace(/ /g, ' ')
+ '