closes #336, Some metadata fields are not exported with notes and attachments

closes #165, verify import/export can carry all data for all fields and item types
closes #168, make sure MODS import works with files from external sources
This commit is contained in:
Simon Kornblith 2006-10-05 08:45:44 +00:00
parent 7a717614e5
commit cbe7c086e1
3 changed files with 867 additions and 782 deletions

View File

@ -278,6 +278,8 @@ var Zotero_File_Interface = new function() {
var newDialog = window.openDialog("chrome://zotero/content/bibliography.xul", var newDialog = window.openDialog("chrome://zotero/content/bibliography.xul",
"_blank","chrome,modal,centerscreen", io); "_blank","chrome,modal,centerscreen", io);
if(!io.output) return;
// determine output format // determine output format
var format = "HTML"; var format = "HTML";
if(io.output == "save-as-rtf") { if(io.output == "save-as-rtf") {

View File

@ -1018,49 +1018,6 @@ Zotero.Translate.prototype._closeStreams = function() {
this._inputStream = null; this._inputStream = null;
} }
/*
* imports an attachment from the disk
*/
Zotero.Translate.prototype._itemImportAttachment = function(attachment, sourceID) {
if(!attachment.path) {
// create from URL
if(attachment.url) {
var attachmentID = Zotero.Attachments.linkFromURL(attachment.url, sourceID,
(attachment.mimeType ? attachment.mimeType : undefined),
(attachment.title ? attachment.title : undefined));
var attachmentItem = Zotero.Items.get(attachmentID);
} else {
Zotero.debug("not adding attachment: no path or url specified");
return false;
}
} else {
// generate nsIFile
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = IOService.newURI(attachment.path, "", null);
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
if(attachment.url) {
// import from nsIFile
var attachmentID = Zotero.Attachments.importSnapshotFromFile(file,
attachment.url, attachment.title, attachment.mimeType,
(attachment.charset ? attachment.charset : null), sourceID);
var attachmentItem = Zotero.Items.get(attachmentID);
} else {
// import from nsIFile
var attachmentID = Zotero.Attachments.importFromFile(file, sourceID);
// get attachment item
var attachmentItem = Zotero.Items.get(attachmentID);
if(attachment.title) {
// set title
attachmentItem.setField("title", attachment.title);
}
}
}
return attachmentItem;
}
/* /*
* handles tags and see also data for notes and attachments * handles tags and see also data for notes and attachments
*/ */
@ -1085,7 +1042,7 @@ Zotero.Translate.prototype._itemTagsAndSeeAlso = function(item, newItem) {
/* /*
* executed when an item is done and ready to be loaded into the database * executed when an item is done and ready to be loaded into the database
*/ */
Zotero.Translate.prototype._itemDone = function(item) { Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
if(!this.saveItem) { // if we're not supposed to save the item, just if(!this.saveItem) { // if we're not supposed to save the item, just
// return the item array // return the item array
@ -1099,11 +1056,12 @@ Zotero.Translate.prototype._itemDone = function(item) {
return; return;
} }
if(!attachedTo) {
var notifierStatus = Zotero.Notifier.isEnabled(); var notifierStatus = Zotero.Notifier.isEnabled();
if(notifierStatus) { if(notifierStatus) {
Zotero.Notifier.disable(); Zotero.Notifier.disable();
} }
}
try { // make sure notifier gets turned back on when done try { // make sure notifier gets turned back on when done
// Get typeID, defaulting to "webpage" // Get typeID, defaulting to "webpage"
@ -1113,22 +1071,69 @@ Zotero.Translate.prototype._itemDone = function(item) {
var myID = Zotero.Notes.add(item.note); var myID = Zotero.Notes.add(item.note);
// re-retrieve the item // re-retrieve the item
var newItem = Zotero.Items.get(myID); var newItem = Zotero.Items.get(myID);
} else if(type == "attachment") {
if(this.type == "import") {
var newItem = this._itemImportAttachment(item, null);
var myID = newItem.getID();
} else {
Zotero.debug("discarding standalone attachment");
return false;
}
} else { } else {
if(!item.title && this.type == "web") { if(!item.title && this.type == "web") {
throw("item has no title"); throw("item has no title");
} }
// create new item // create new item
if(type == "attachment") {
if(this.type != "import") {
Zotero.debug("discarding standalone attachment");
return;
}
Zotero.debug("adding attachment");
Zotero.debug(item);
if(!item.path) {
// create from URL
if(item.url) {
var myID = Zotero.Attachments.linkFromURL(item.url, attachedTo,
(item.mimeType ? item.mimeType : undefined),
(item.title ? item.title : undefined));
Zotero.debug("created attachment; id is "+myID);
if(!myID) {
// if we didn't get an ID, don't continue adding
// notes, because we can't without knowing the ID
return;
}
var newItem = Zotero.Items.get(myID);
} else {
Zotero.debug("not adding attachment: no path or url specified");
return;
}
} else {
// generate nsIFile
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = IOService.newURI(item.path, "", null);
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
if(item.url) {
// import from nsIFile
var myID = Zotero.Attachments.importSnapshotFromFile(file,
item.url, item.title, item.mimeType,
(item.charset ? item.charset : null), attachedTo);
var newItem = Zotero.Items.get(myID);
} else {
// import from nsIFile
var myID = Zotero.Attachments.importFromFile(file, attachedTo);
// get attachment item
var newItem = Zotero.Items.get(myID);
}
}
var typeID = Zotero.ItemTypes.getID("attachment");
// add note if necessary
if(item.note) {
newItem.updateNote(item.note);
}
} else {
var typeID = Zotero.ItemTypes.getID(type); var typeID = Zotero.ItemTypes.getID(type);
var newItem = Zotero.Items.getNewItemByType(typeID); var newItem = Zotero.Items.getNewItemByType(typeID);
}
// makes looping through easier // makes looping through easier
item.itemType = item.complete = undefined; item.itemType = item.complete = undefined;
@ -1180,10 +1185,14 @@ Zotero.Translate.prototype._itemDone = function(item) {
} }
// save item // save item
if(myID) {
newItem.save();
} else {
var myID = newItem.save(); var myID = newItem.save();
if(myID == true) { if(myID == true || !myID) {
myID = newItem.getID(); myID = newItem.getID();
} }
}
// handle notes // handle notes
if(item.notes) { if(item.notes) {
@ -1234,10 +1243,8 @@ Zotero.Translate.prototype._itemDone = function(item) {
}*/ }*/
} }
} else if(this.type == "import") { } else if(this.type == "import") {
var attachmentItem = this._itemImportAttachment(attachment, myID); // create new attachments attached here
if(attachmentItem) { this._itemDone(attachment, myID);
this._itemTagsAndSeeAlso(attachment, attachmentItem);
}
} }
} }
} }
@ -1246,7 +1253,9 @@ Zotero.Translate.prototype._itemDone = function(item) {
if(item.itemID) { if(item.itemID) {
this._IDMap[item.itemID] = myID; this._IDMap[item.itemID] = myID;
} }
if(!attachedTo) {
this.newItems.push(myID); this.newItems.push(myID);
}
// handle see also // handle see also
if(item.seeAlso) { if(item.seeAlso) {
@ -1272,10 +1281,12 @@ Zotero.Translate.prototype._itemDone = function(item) {
} }
// only re-enable if notifier was enabled at the beginning of scraping // only re-enable if notifier was enabled at the beginning of scraping
if(!attachedTo) {
if(notifierStatus) { if(notifierStatus) {
Zotero.Notifier.enable(); Zotero.Notifier.enable();
} }
this._runHandler("itemDone", newItem); this._runHandler("itemDone", newItem);
}
} }
/* /*
@ -1738,7 +1749,7 @@ Zotero.Translate.prototype._exportConfigureIO = function() {
* copies attachment and returns data, given an attachment object * copies attachment and returns data, given an attachment object
*/ */
Zotero.Translate.prototype._exportGetAttachment = function(attachment) { Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
var attachmentArray = new Object(); var attachmentArray = attachment.toArray();
var attachmentID = attachment.getID(); var attachmentID = attachment.getID();
var linkMode = attachment.getAttachmentLinkMode(); var linkMode = attachment.getAttachmentLinkMode();
@ -1754,8 +1765,6 @@ Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
} }
// add item ID // add item ID
attachmentArray.itemID = attachmentID; attachmentArray.itemID = attachmentID;
// get title
attachmentArray.title = attachment.getField("title");
// get mime type // get mime type
attachmentArray.mimeType = attachment.getAttachmentMimeType(); attachmentArray.mimeType = attachment.getAttachmentMimeType();
// get charset // get charset
@ -1788,7 +1797,7 @@ Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
} }
} }
Zotero.debug(attachmentArray); attachmentArray.itemType = "attachment";
return attachmentArray; return attachmentArray;
} }
@ -1799,19 +1808,14 @@ Zotero.Translate.prototype._exportGetAttachment = function(attachment) {
Zotero.Translate.prototype._exportGetItem = function() { Zotero.Translate.prototype._exportGetItem = function() {
if(this._itemsLeft.length != 0) { if(this._itemsLeft.length != 0) {
var returnItem = this._itemsLeft.shift(); var returnItem = this._itemsLeft.shift();
// skip files if exportFileData is off, or if the file isn't standalone
if(returnItem.isAttachment() &&
(!this._displayOptions["exportFileData"] ||
returnItem.getSource())) {
return this._exportGetItem();
}
// export file data for single files // export file data for single files
if(returnItem.isAttachment()) { // an independent attachment if(returnItem.isAttachment()) { // an independent attachment
var returnItemArray = this._exportGetAttachment(returnItem); var returnItemArray = this._exportGetAttachment(returnItem);
returnItemArray.itemType = "attachment"; if(returnItemArray) {
return returnItemArray; return returnItemArray;
} else {
return this._exportGetItem();
}
} else { } else {
var returnItemArray = returnItem.toArray(); var returnItemArray = returnItem.toArray();
// get attachments, although only urls will be passed if exportFileData // get attachments, although only urls will be passed if exportFileData

View File

@ -1,4 +1,4 @@
-- 98 -- 99
DROP TABLE IF EXISTS translators; DROP TABLE IF EXISTS translators;
CREATE TABLE translators ( CREATE TABLE translators (
@ -664,7 +664,7 @@ function doWeb(doc, url) {
} else if(fieldCode == "NO") { } else if(fieldCode == "NO") {
newItem.issue = fieldContent; newItem.issue = fieldContent;
} else if(fieldCode == "SE") { } else if(fieldCode == "SE") {
newItem.seriesTitle = fieldContent; newItem.series = fieldContent;
} else if(fieldCode == "DA") { } else if(fieldCode == "DA") {
newItem.date = fieldContent; newItem.date = fieldContent;
} else if(fieldCode == "PP") { } else if(fieldCode == "PP") {
@ -4366,20 +4366,6 @@ function doExport() {
/** SUPPLEMENTAL FIELDS **/ /** SUPPLEMENTAL FIELDS **/
// XML tag relatedItem.titleInfo; object field series
if(item.seriesTitle) {
var series = <relatedItem type="series">
<titleInfo><title>{item.seriesTitle}</title></titleInfo>
</relatedItem>;
if(item.itemType == "bookSection") {
// For a book section, series info must go inside host tag
mods.relatedItem.relatedItem = series;
} else {
mods.relatedItem += series;
}
}
// Make part its own tag so we can figure out where it goes later // Make part its own tag so we can figure out where it goes later
var part = new XML(); var part = new XML();
@ -4523,7 +4509,37 @@ function doExport() {
/** TAGS **/ /** TAGS **/
for(var j in item.tags) { for(var j in item.tags) {
mods.subject += <subject>{item.tags[j]}</subject>; mods.subject += <subject><topic>{item.tags[j]}</topic></subject>;
}
// XML tag relatedItem.titleInfo; object field series
if(item.seriesTitle || item.series || item.seriesNumber || item.seriesText) {
var series = <relatedItem type="series"/>;
if(item.series) {
series.titleInfo.title = item.series;
}
if(item.seriesTitle) {
series.titleInfo.partTitle = item.seriesTitle;
}
if(item.seriesText) {
series.titleInfo.subTitle = item.seriesText;
}
if(item.seriesNumber) {
series.titleInfo.partNumber = item.seriesNumber;
}
// TODO: make this work in import
/*if(item.itemType == "bookSection") {
// For a book section, series info must go inside host tag
mods.relatedItem.relatedItem = series;
} else {*/
mods.relatedItem += series;
//}
} }
modsCollection.mods += mods; modsCollection.mods += mods;
@ -4568,7 +4584,6 @@ function doImport() {
while(read = Zotero.read(16384)) { while(read = Zotero.read(16384)) {
text += read; text += read;
} }
Zotero.Utilities.debug("read in");
// parse with E4X // parse with E4X
var m = new Namespace("http://www.loc.gov/mods/v3"); var m = new Namespace("http://www.loc.gov/mods/v3");
@ -4576,25 +4591,28 @@ function doImport() {
default xml namespace = m; default xml namespace = m;
var xml = new XML(text); var xml = new XML(text);
for each(var mods in xml.m::mods) { if(xml.m::mods.length()) {
Zotero.Utilities.debug("item is: "); var modsElements = xml.m::mods;
for(var i in mods) { } else {
Zotero.Utilities.debug(i+" = "+mods[i].toString()); var modsElements = [xml];
} }
for each(var mods in modsElements) {
var newItem = new Zotero.Item(); var newItem = new Zotero.Item();
// title // title
newItem.title = mods.m::titleInfo.(m::title.@type!="abbreviated").m::title; for each(var titleInfo in mods.m::titleInfo) {
if(titleInfo.@type != "abbreviated") {
newItem.title = titleInfo.m::title;
}
}
// try to get genre from local genre // try to get genre from local genre
var localGenre = mods.m::genre.(@authority=="local").text().toString(); for each(var genre in mods.m::genre) {
if(localGenre && Zotero.Utilities.itemTypeExists(localGenre)) { if(genre.@authority == "local" && Zotero.Utilities.itemTypeExists(genre)) {
newItem.itemType = localGenre; newItem.itemType = genre.text().toString();
} else { } else if(!newItem.itemType && genre.@authority == "marcgt") {
// otherwise, look at the marc genre // otherwise, look at the marc genre
var marcGenre = mods.m::genre.(@authority=="marcgt").text().toString();
if(marcGenre) {
if(marcGenre == "book") { if(marcGenre == "book") {
newItem.itemType = "book"; newItem.itemType = "book";
} else if(marcGenre == "periodical") { } else if(marcGenre == "periodical") {
@ -4615,11 +4633,11 @@ function doImport() {
newItem.itemType = "webpage"; newItem.itemType = "webpage";
} }
} }
}
if(!newItem.itemType) { if(!newItem.itemType) {
newItem.itemType = "book"; newItem.itemType = "book";
} }
}
var isPartialItem = Zotero.Utilities.inArray(newItem.itemType, partialItemTypes); var isPartialItem = Zotero.Utilities.inArray(newItem.itemType, partialItemTypes);
@ -4628,18 +4646,33 @@ function doImport() {
for each(var name in mods.m::name) { for each(var name in mods.m::name) {
// TODO: institutional authors // TODO: institutional authors
var creator = new Array(); var creator = new Array();
creator.firstName = name.m::namePart.(@type=="given").text().toString(); for each(var namePart in name.m::namePart) {
creator.lastName = name.m::namePart.(@type=="family").text().toString(); if(namePart.@type == "given") {
creator.firstName = namePart.text().toString();
} else if(namePart.@type == "family") {
creator.lastName = namePart.text().toString();
} else {
var backupName = namePart.text().toString();
}
}
if(backupName && !creator.firstName && !creator.lastName) {
creator = Zotero.Utilities.cleanAuthor(backupName, "author", true);
}
// look for roles // look for roles
var role = name.m::role.m::roleTerm.(@type=="code").(@authority=="marcrelator").text().toString(); for(var role in name.m::role.m::roleTerm) {
if(role.@type == "code" && role.@authority == "marcrelator") {
if(role == "edt") { if(role == "edt") {
creator.creatorType = "editor"; creator.creatorType = "editor";
} else if(role == "ctb") { } else if(role == "ctb") {
creator.creatorType = "contributor"; creator.creatorType = "contributor";
} else { } else if(role == "trl") {
creator.creatorType = "author"; creator.creatorType = "translator";
} }
}
}
if(!creator.creatorType) creator.creatorType = "author";
newItem.creators.push(creator); newItem.creators.push(creator);
} }
@ -4653,87 +4686,123 @@ function doImport() {
/** SUPPLEMENTAL FIELDS **/ /** SUPPLEMENTAL FIELDS **/
var part = false, originInfo = false, identifier = false;
// series // series
if(newItem.itemType == "bookSection") { for each(var relatedItem in mods.m::relatedItem) {
newItem.seriesTitle = mods.m::relatedItem.(@type=="host").m::relatedItem.(@type=="series").m::titleInfo.m::title.text().toString(); if(relatedItem.@type == "host") {
for each(var titleInfo in relatedItem.m::titleInfo) {
if(titleInfo.@type == "abbreviated") {
newItem.journalAbbreviation = titleInfo.m::title.text().toString()
} else { } else {
newItem.seriesTitle = mods.m::relatedItem.(@type=="series").m::titleInfo.m::title.text().toString(); newItem.publicationTitle = titleInfo.m::title.text().toString();
}
}
part = relatedItem.m::part;
originInfo = relatedItem.m::originInfo;
identifier = relatedItem.m::identifier;
} else if(relatedItem.@type == "series") {
newItem.series = relatedItem.m::titleInfo.m::title.text().toString();
newItem.seriesTitle = relatedItem.m::titleInfo.m::partTitle.text().toString();
newItem.seriesText = relatedItem.m::titleInfo.m::subTitle.text().toString();
newItem.seriesNumber = relatedItem.m::titleInfo.m::partNumber.text().toString();
}
} }
// get part // get part
if(isPartialItem) { if(!part) {
var part = mods.m::relatedItem.m::part; part = mods.m::part;
var originInfo = mods.m::relatedItem.m::originInfo; originInfo = mods.m::originInfo;
var identifier = mods.m::relatedItem.m::identifier; identifier = mods.m::identifier;
} else {
var part = mods.m::part;
var originInfo = mods.m::originInfo;
var identifier = mods.m::identifier;
} }
if(part) {
for each(var detail in part.m::detail) {
// volume // volume
newItem.volume = part.m::detail.(@type=="volume").m::number.text().toString(); if(detail.@type == "volume") {
newItem.volume = detail.m::number.text().toString();
if(!newItem.volume) { if(!newItem.volume) {
newItem.volume = part.m::detail.(@type=="volume").m::text.text().toString(); newItem.volume = detail.m::text.text().toString();
}
} }
// number // number
newItem.issue = part.m::detail.(@type=="issue").m::number.text().toString(); if(detail.@type == "issue") {
newItem.issue = detail.m::number.text().toString();
if(!newItem.issue) { if(!newItem.issue) {
newItem.issue = part.m::detail.(@type=="issue").m::text.text().toString(); newItem.issue = detail.m::text.text().toString();
}
} }
// section // section
newItem.section = part.m::detail.(@type=="section").m::number.text().toString(); if(detail.@type == "section") {
newItem.section = detail.m::number.text().toString();
if(!newItem.section) { if(!newItem.section) {
newItem.section = part.m::detail.(@type=="section").m::text.text().toString(); newItem.section = detail.m::text.text().toString();
}
}
} }
// pages // pages
var pagesStart = part.m::extent.(@unit=="pages").m::start.text().toString(); for each(var extent in part.m::extent) {
var pagesEnd = part.m::extent.(@unit=="pages").m::end.text().toString(); if(extent.@unit == "pages") {
var pagesStart = extent.m::start.text().toString();
var pagesEnd = extent.m::end.text().toString();
if(pagesStart || pagesEnd) { if(pagesStart || pagesEnd) {
if(pagesStart && pagesEnd && pagesStart != pagesEnd) { if(pagesStart == pagesEnd) {
newItem.pages = pagesStart;
} else if(pagesStart && pagesEnd) {
newItem.pages = pagesStart+"-"+pagesEnd; newItem.pages = pagesStart+"-"+pagesEnd;
} else { } else {
newItem.pages = pagesStart+pagesEnd; newItem.pages = pagesStart+pagesEnd;
} }
} }
}
}
}
// edition // edition
newItem.edition = originInfo.m::edition.text().toString(); newItem.edition = originInfo.m::edition.text().toString();
// place // place
newItem.place = originInfo.m::place.m::placeTerm.text().toString(); for each(var placeTerm in originInfo.m::place.m::placeTerm) {
// publisher/distributor if(placeTerm.@type == "text") {
newItem.publisher = newItem.distributor = originInfo.m::publisher.text().toString(); newItem.place = placeTerm.text().toString();
// date
newItem.date = originInfo.m::copyrightDate.text().toString();
if(!newItem.date) {
newItem.date = originInfo.m::dateIssued.text().toString();
if(!newItem.date) {
newItem.date = originInfo.dateCreated.text().toString();
} }
} }
// publisher/distributor
if(originInfo.m::publisher.length()) {
newItem.publisher = newItem.distributor = originInfo.m::publisher[0].text().toString();
}
// date
if(originInfo.m::copyrightDate.length()) {
newItem.date = originInfo.m::copyrightDate[0].text().toString();
} else if(originInfo.m::dateIssued.length()) {
newItem.date = originInfo.m::dateIssued[0].text().toString();
} else if(originInfo.m::dateCreated.length()) {
newItem.date = originInfo.m::dateCreated[0].text().toString();
}
// lastModified // lastModified
newItem.lastModified = originInfo.m::dateModified.text().toString(); newItem.lastModified = originInfo.m::dateModified.text().toString();
// accessDate // accessDate
newItem.accessDate = originInfo.m::dateCaptured.text().toString(); newItem.accessDate = originInfo.m::dateCaptured.text().toString();
// ISBN
newItem.ISBN = identifier.(@type=="isbn").text().toString() // identifiers
// ISSN for each(var myIdentifier in identifier) {
newItem.ISSN = identifier.(@type=="issn").text().toString() if(myIdentifier.@type == "isbn") {
// DOI newItem.ISBN = myIdentifier.text().toString()
newItem.DOI = identifier.(@type=="doi").text().toString() } else if(myIdentifier.@type == "issn") {
// publication newItem.ISSN = myIdentifier.text().toString()
newItem.publicationTitle = mods.m::relatedItem.m::publication.text().toString(); } else if(myIdentifier.@type == "doi") {
newItem.DOI = myIdentifier.text().toString()
}
}
// call number // call number
newItem.callNumber = mods.m::classification.text().toString(); newItem.callNumber = mods.m::classification.text().toString();
// archiveLocation // archiveLocation
newItem.archiveLocation = mods.m::location.m::physicalLocation.text().toString(); newItem.archiveLocation = mods.m::location.m::physicalLocation.text().toString();
// url // url
newItem.url = mods.m::location.m::url.text().toString(); newItem.url = mods.m::location.m::url.text().toString();
// journalAbbreviation
newItem.journalAbbreviation = mods.m::relatedItem.(m::titleInfo.@type=="abbreviated").m::titleInfo.m::title.text().toString();
/** NOTES **/ /** NOTES **/
for each(var note in mods.m::note) { for each(var note in mods.m::note) {
@ -4741,10 +4810,12 @@ function doImport() {
} }
/** TAGS **/ /** TAGS **/
for each(var subject in mods.m::subject) { for each(var subject in mods.m::subject.m::topic) {
newItem.tags.push(subject.text().toString()); newItem.tags.push(subject.text().toString());
} }
Zotero.Utilities.debug(newItem);
newItem.complete(); newItem.complete();
} }
}'); }');
@ -4785,94 +4856,7 @@ function generateCollection(collection) {
} }
} }
function handleAttachment(attachmentResource, attachment) { function generateItem(item, zoteroType, resource) {
Zotero.RDF.addStatement(attachmentResource, rdf+"type", n.fs+"Attachment", false);
if(attachment.path) {
Zotero.RDF.addStatement(attachmentResource, rdf+"resource", attachment.path, false);
}
if(attachment.url) {
// add url as identifier
var term = Zotero.RDF.newResource();
// set term type
Zotero.RDF.addStatement(term, rdf+"type", n.dcterms+"URI", false);
// set url value
Zotero.RDF.addStatement(term, rdf+"value", attachment.url, true);
// add relationship to resource
Zotero.RDF.addStatement(attachmentResource, n.dc+"identifier", term, false);
}
// set mime type value
Zotero.RDF.addStatement(attachmentResource, n.link+"type", attachment.mimeType, true);
// set charset value
if(attachment.charset) {
Zotero.RDF.addStatement(attachmentResource, n.link+"charset", attachment.charset, true);
}
// add title
Zotero.RDF.addStatement(attachmentResource, n.dc+"title", attachment.title, true);
// Add see also info to RDF
generateSeeAlso(attachmentResource, attachment.seeAlso);
generateTags(attachmentResource, attachment.tags);
}
function doExport() {
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
n = {
bib:"http://purl.org/net/biblio#",
dc:"http://purl.org/dc/elements/1.1/",
dcterms:"http://purl.org/dc/terms/",
prism:"http://prismstandard.org/namespaces/1.2/basic/",
foaf:"http://xmlns.com/foaf/0.1/",
vcard:"http://nwalsh.com/rdf/vCard#",
link:"http://purl.org/rss/1.0/modules/link/",
fs:"http://www.zotero.org/namespaces/export#"
};
// add namespaces
for(var i in n) {
Zotero.RDF.addNamespace(i, n[i]);
}
// leave as global
itemResources = new Array();
// keep track of resources already assigned (in case two book items have the
// same ISBN, or something like that)
var usedResources = new Array();
var items = new Array();
// first, map each ID to a resource
while(item = Zotero.nextItem()) {
items.push(item);
if(item.ISBN && !usedResources["urn:isbn:"+item.ISBN]) {
itemResources[item.itemID] = "urn:isbn:"+item.ISBN;
usedResources[itemResources[item.itemID]] = true;
} else if(item.itemType != "attachment" && item.url && !usedResources[item.url]) {
itemResources[item.itemID] = item.url;
usedResources[itemResources[item.itemID]] = true;
} else {
// just specify a node ID
itemResources[item.itemID] = "#item:"+item.itemID;
}
for(var j in item.notes) {
itemResources[item.notes[j].itemID] = "#item:"+item.notes[j].itemID;
}
for each(var attachment in item.attachments) {
// just specify a node ID
itemResources[attachment.itemID] = "#item:"+attachment.itemID;
}
}
for each(item in items) {
// these items are global
resource = itemResources[item.itemID];
container = null; container = null;
containerElement = null; containerElement = null;
section = null; section = null;
@ -4886,45 +4870,56 @@ function doExport() {
// type // type
var type = null; var type = null;
if(item.itemType == "book") { if(zoteroType == "book") {
type = "Book"; type = n.bib+"Book";
} else if (item.itemType == "bookSection") { } else if (zoteroType == "bookSection") {
type = "BookSection"; type = n.bib+"BookSection";
container = "Book"; container = "Book";
} else if(item.itemType == "journalArticle") { } else if(zoteroType == "journalArticle") {
type = "Article"; type = n.bib+"Article";
container = "Journal"; container = "Journal";
} else if(item.itemType == "magazineArticle") { } else if(zoteroType == "magazineArticle") {
type = "Article"; type = n.bib+"Article";
container = "Periodical"; container = "Periodical";
} else if(item.itemType == "newspaperArticle") { } else if(zoteroType == "newspaperArticle") {
type = "Article"; type = n.bib+"Article";
container = "Newspaper"; container = "Newspaper";
} else if(item.itemType == "thesis") { } else if(zoteroType == "thesis") {
type = "Thesis"; type = n.bib+"Thesis";
} else if(item.itemType == "letter") { } else if(zoteroType == "letter") {
type = "Letter"; type = n.bib+"Letter";
} else if(item.itemType == "manuscript") { } else if(zoteroType == "manuscript") {
type = "Manuscript"; type = n.bib+"Manuscript";
} else if(item.itemType == "interview") { } else if(zoteroType == "interview") {
type = "Interview"; type = n.bib+"Interview";
} else if(item.itemType == "film") { } else if(zoteroType == "film") {
type = "MotionPicture"; type = n.bib+"MotionPicture";
} else if(item.itemType == "artwork") { } else if(zoteroType == "artwork") {
type = "Illustration"; type = n.bib+"Illustration";
} else if(item.itemType == "webpage") { } else if(zoteroType == "webpage") {
type = "Document"; type = n.bib+"Document";
} else if(item.itemType == "note") { } else if(zoteroType == "note") {
type = "Memo"; type = n.bib+"Memo";
if(!Zotero.getOption("exportNotes")) { if(!Zotero.getOption("exportNotes")) {
continue; return;
} }
} else if(item.itemType == "attachment") { } else if(zoteroType == "attachment") {
handleAttachment(resource, item); type = n.fs+"Attachment";
continue;
// set path
if(item.path) {
Zotero.RDF.addStatement(resource, rdf+"resource", item.path, false);
} }
// set mime type value
Zotero.RDF.addStatement(resource, n.link+"type", item.mimeType, true);
// set charset value
if(item.charset) {
Zotero.RDF.addStatement(resource, n.link+"charset", item.charset, true);
}
}
if(type) { if(type) {
Zotero.RDF.addStatement(resource, rdf+"type", n.bib+type, false); Zotero.RDF.addStatement(resource, rdf+"type", type, false);
} }
// authors/editors/contributors // authors/editors/contributors
@ -5034,14 +5029,30 @@ function doExport() {
} }
// series also linked in // series also linked in
if(item.seriesTitle) { if(item.series || item.seriesTitle || item.seriesText || item.seriesNumber) {
var series = Zotero.RDF.newResource(); var series = Zotero.RDF.newResource();
// set series type // set series type
Zotero.RDF.addStatement(series, rdf+"type", n.bib+"Series", false); Zotero.RDF.addStatement(series, rdf+"type", n.bib+"Series", false);
// set series title
Zotero.RDF.addStatement(series, n.dc+"title", item.seriesTitle, true);
// add relationship to resource // add relationship to resource
Zotero.RDF.addStatement((containerElement ? containerElement : resource), n.dcterms+"isPartOf", series, false); Zotero.RDF.addStatement((containerElement ? containerElement : resource), n.dcterms+"isPartOf", series, false);
if(item.series) {
// as far as I know, these are never defined for the same types
Zotero.RDF.addStatement(series, n.dc+"title", item.series, true);
}
if(item.seriesTitle) {
// as far as I know, these are never defined for the same types
Zotero.RDF.addStatement(series, n.dcterms+"alternative", item.seriesTitle, true);
}
if(item.seriesText) {
Zotero.RDF.addStatement(series, n.dc+"description", item.seriesText, true);
}
if(item.seriesNumber) {
Zotero.RDF.addStatement(series, n.dc+"identifier", item.seriesNumber, true);
}
} }
// volume // volume
@ -5104,6 +5115,11 @@ function doExport() {
Zotero.RDF.addStatement(resource, n.dc+"coverage", item.archiveLocation, true); Zotero.RDF.addStatement(resource, n.dc+"coverage", item.archiveLocation, true);
} }
// archiveLocation
if(item.medium) {
Zotero.RDF.addStatement(resource, n.dcterms+"medium", item.medium, true);
}
// type (not itemType) // type (not itemType)
if(item.type) { if(item.type) {
Zotero.RDF.addStatement(resource, n.dc+"type", item.type, true); Zotero.RDF.addStatement(resource, n.dc+"type", item.type, true);
@ -5130,6 +5146,11 @@ function doExport() {
/** NOTES **/ /** NOTES **/
if(Zotero.getOption("exportNotes")) { if(Zotero.getOption("exportNotes")) {
// attachment note
if(item.itemType == "attachment" && item.note) {
Zotero.RDF.addStatement(resource, n.dc+"description", item.note, true);
}
for(var j in item.notes) { for(var j in item.notes) {
var noteResource = itemResources[item.notes[j].itemID]; var noteResource = itemResources[item.notes[j].itemID];
@ -5145,7 +5166,7 @@ function doExport() {
generateTags(noteResource, item.notes[j].tags); generateTags(noteResource, item.notes[j].tags);
} }
if(item.note) { if(item.itemType == "note" && item.note) {
Zotero.RDF.addStatement(resource, rdf+"value", item.note, true); Zotero.RDF.addStatement(resource, rdf+"value", item.note, true);
} }
} }
@ -5155,13 +5176,71 @@ function doExport() {
for each(var attachment in item.attachments) { for each(var attachment in item.attachments) {
var attachmentResource = itemResources[attachment.itemID]; var attachmentResource = itemResources[attachment.itemID];
Zotero.RDF.addStatement(resource, n.link+"link", attachmentResource, false); Zotero.RDF.addStatement(resource, n.link+"link", attachmentResource, false);
handleAttachment(attachmentResource, attachment); generateItem(attachment, "attachment", attachmentResource);
} }
/** SEE ALSO AND TAGS **/ /** SEE ALSO AND TAGS **/
generateSeeAlso(resource, item.seeAlso); generateSeeAlso(resource, item.seeAlso);
generateTags(resource, item.tags); generateTags(resource, item.tags);
}
function doExport() {
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
n = {
bib:"http://purl.org/net/biblio#",
dc:"http://purl.org/dc/elements/1.1/",
dcterms:"http://purl.org/dc/terms/",
prism:"http://prismstandard.org/namespaces/1.2/basic/",
foaf:"http://xmlns.com/foaf/0.1/",
vcard:"http://nwalsh.com/rdf/vCard#",
link:"http://purl.org/rss/1.0/modules/link/",
fs:"http://www.zotero.org/namespaces/export#"
};
// add namespaces
for(var i in n) {
Zotero.RDF.addNamespace(i, n[i]);
}
// leave as global
itemResources = new Array();
// keep track of resources already assigned (in case two book items have the
// same ISBN, or something like that)
var usedResources = new Array();
var items = new Array();
// first, map each ID to a resource
while(item = Zotero.nextItem()) {
items.push(item);
if(item.ISBN && !usedResources["urn:isbn:"+item.ISBN]) {
itemResources[item.itemID] = "urn:isbn:"+item.ISBN;
usedResources[itemResources[item.itemID]] = true;
} else if(item.itemType != "attachment" && item.url && !usedResources[item.url]) {
itemResources[item.itemID] = item.url;
usedResources[itemResources[item.itemID]] = true;
} else {
// just specify a node ID
itemResources[item.itemID] = "#item:"+item.itemID;
}
for(var j in item.notes) {
itemResources[item.notes[j].itemID] = "#item:"+item.notes[j].itemID;
}
for each(var attachment in item.attachments) {
// just specify a node ID
itemResources[attachment.itemID] = "#item:"+attachment.itemID;
}
}
for each(item in items) {
// these items are global
generateItem(item, item.itemType, itemResources[item.itemID]);
} }
/** RDF COLLECTION STRUCTURE **/ /** RDF COLLECTION STRUCTURE **/
@ -5270,6 +5349,11 @@ REPLACE INTO "translators" VALUES ('6e372642-ed9d-4934-b5d1-c11ac758ebb7', '2006
if(item.archiveLocation) { if(item.archiveLocation) {
Zotero.RDF.addStatement(resource, dc+"coverage", item.archiveLocation, true); Zotero.RDF.addStatement(resource, dc+"coverage", item.archiveLocation, true);
} }
// medium
if(item.medium) {
Zotero.RDF.addStatement(resource, dcterms+"medium", item.medium, true);
}
} }
}'); }');
@ -5342,41 +5426,6 @@ function handleCreators(newItem, creators, creatorType) {
} }
} }
// gets attachment info
function handleAttachment(node, attachment) {
if(!attachment) {
attachment = new Array();
}
attachment.title = getFirstResults(node, [n.dc+"title"], true);
var path = getFirstResults(node, [rdf+"resource"]);
if(path) {
attachment.path = Zotero.RDF.getResourceURI(path[0]);
}
attachment.charset = getFirstResults(node, [n.link+"charset"], true);
attachment.mimeType = getFirstResults(node, [n.link+"type"], true);
var identifiers = getFirstResults(node, [n.dc+"identifier"]);
for each(var identifier in identifiers) {
if(typeof(identifier) != "string") {
var identifierType = Zotero.RDF.getTargets(identifier, rdf+"type");
if(identifierType) {
identifierType = Zotero.RDF.getResourceURI(identifierType[0]);
if(identifierType == n.dcterms+"URI") { // uri is url
attachment.url = getFirstResults(identifier, [rdf+"value"], true);
}
}
}
}
// get seeAlso and tags
processSeeAlso(node, attachment);
processTags(node, attachment);
return attachment;
}
// processes collections recursively // processes collections recursively
function processCollection(node, collection) { function processCollection(node, collection) {
if(!collection) { if(!collection) {
@ -5435,7 +5484,7 @@ function getNodeByType(nodes, type) {
return false; return false;
} }
for each(node in nodes) { for each(var node in nodes) {
var nodeType = Zotero.RDF.getTargets(node, rdf+"type"); var nodeType = Zotero.RDF.getTargets(node, rdf+"type");
if(nodeType) { if(nodeType) {
nodeType = Zotero.RDF.getResourceURI(nodeType[0]); nodeType = Zotero.RDF.getResourceURI(nodeType[0]);
@ -5464,47 +5513,9 @@ function isPart(node) {
return skip; return skip;
} }
function doImport() { function importItem(newItem, node, type) {
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
n = {
bib:"http://purl.org/net/biblio#",
dc:"http://purl.org/dc/elements/1.1/",
dcterms:"http://purl.org/dc/terms/",
prism:"http://prismstandard.org/namespaces/1.2/basic/",
foaf:"http://xmlns.com/foaf/0.1/",
vcard:"http://nwalsh.com/rdf/vCard#",
link:"http://purl.org/rss/1.0/modules/link/",
fs:"http://www.zotero.org/namespaces/export#"
};
callNumberTypes = [
n.dcterms+"LCC", n.dcterms+"DDC", n.dcterms+"UDC"
];
var nodes = Zotero.RDF.getAllResources();
if(!nodes) {
return false;
}
// keep track of collections while we''re looping through
var collections = new Array();
for each(var node in nodes) {
var newItem = new Zotero.Item();
newItem.itemID = Zotero.RDF.getResourceURI(node);
var container = undefined; var container = undefined;
// figure out if this is a part of another resource, or a linked
// attachment
if(Zotero.RDF.getSources(node, n.dcterms+"isPartOf") ||
Zotero.RDF.getSources(node, n.link+"link")) {
continue;
}
// type
var type = Zotero.RDF.getTargets(node, rdf+"type");
// also deal with type detection based on parts, so we can differentiate // also deal with type detection based on parts, so we can differentiate
// magazine and journal articles, and find container elements // magazine and journal articles, and find container elements
var isPartOf = getFirstResults(node, [n.dcterms+"isPartOf"]); var isPartOf = getFirstResults(node, [n.dcterms+"isPartOf"]);
@ -5519,7 +5530,7 @@ function doImport() {
} }
} }
if(type && (type = Zotero.RDF.getResourceURI(type[0]))) { if(type) {
if(type == n.bib+"Book") { if(type == n.bib+"Book") {
newItem.itemType = "book"; newItem.itemType = "book";
} else if(type == n.bib+"BookSection") { } else if(type == n.bib+"BookSection") {
@ -5528,6 +5539,7 @@ function doImport() {
} else if(type == n.bib+"Article") { // choose between journal, } else if(type == n.bib+"Article") { // choose between journal,
// newspaper, and magazine // newspaper, and magazine
// articles // articles
// use of container = (not container ==) is intentional
if(container = getNodeByType(isPartOf, n.bib+"Journal")) { if(container = getNodeByType(isPartOf, n.bib+"Journal")) {
newItem.itemType = "journalArticle"; newItem.itemType = "journalArticle";
} else if(container = getNodeByType(isPartOf, n.bib+"Periodical")) { } else if(container = getNodeByType(isPartOf, n.bib+"Periodical")) {
@ -5546,42 +5558,36 @@ function doImport() {
} else if(type == n.bib+"MotionPicture") { } else if(type == n.bib+"MotionPicture") {
newItem.itemType = "film"; newItem.itemType = "film";
} else if(type == n.bib+"Illustration") { } else if(type == n.bib+"Illustration") {
newItem.itemType = "illustration"; newItem.itemType = "artwork";
} else if(type == n.bib+"Document") { } else if(type == n.bib+"Document") {
newItem.itemType = "webpage"; newItem.itemType = "webpage";
} else if(type == n.bib+"Memo") { } else if(type == n.bib+"Memo") {
// check to see if this note is independent
if(isPart(node)) {
continue;
}
newItem.itemType = "note"; newItem.itemType = "note";
} else if(type == n.bib+"Collection") {
// skip collections until all the items are done
collections.push(node);
continue;
} else if(type == n.fs+"Attachment") { } else if(type == n.fs+"Attachment") {
// check to see if file is independent // unless processing of independent attachment is intended, don''t
if(isPart(node)) { // process
continue;
}
// process as file // process as file
newItem.itemType = "attachment"; newItem.itemType = "attachment";
handleAttachment(node, newItem);
Zotero.Utilities.debug(newItem); var path = getFirstResults(node, [rdf+"resource"]);
newItem.complete(); if(path) {
continue; newItem.path = Zotero.RDF.getResourceURI(path[0]);
} else { // default to book }
newItem.itemType = "book"; newItem.charset = getFirstResults(node, [n.link+"charset"], true);
newItem.mimeType = getFirstResults(node, [n.link+"type"], true);
} }
} }
// title // title
newItem.title = getFirstResults(node, [n.dc+"title"], true); newItem.title = getFirstResults(node, [n.dc+"title"], true);
if(newItem.itemType != "note" && !newItem.title) { // require the title if(!newItem.itemType && !newItem.title) { // require the title
// (if not a note) // (if not a known type)
continue; return false;
}
if(!newItem.itemType) {
newItem.itemType = "book";
} }
// regular author-type creators // regular author-type creators
@ -5614,7 +5620,10 @@ function doImport() {
// series // series
var series = getNodeByType(isPartOf, n.bib+"Series"); var series = getNodeByType(isPartOf, n.bib+"Series");
if(series) { if(series) {
newItem.seriesTitle = getFirstResults(container, [n.dc+"title"], true); newItem.series = getFirstResults(series, [n.dc+"title"], true);
newItem.seriesTitle = getFirstResults(series, [n.dcterms+"alternative"], true);
newItem.seriesText = getFirstResults(series, [n.dc+"description"], true);
newItem.seriesNumber = getFirstResults(series, [n.dc+"identifier"], true);
} }
// volume // volume
@ -5626,6 +5635,12 @@ function doImport() {
// edition // edition
newItem.edition = getFirstResults(node, [n.prism+"edition"], true); newItem.edition = getFirstResults(node, [n.prism+"edition"], true);
// pages
newItem.pages = getFirstResults(node, [n.bib+"pages"], true);
// mediums
newItem.medium = getFirstResults(node, [n.dcterms+"medium"], true);
// publisher // publisher
var publisher = getFirstResults(node, [n.dc+"publisher"]); var publisher = getFirstResults(node, [n.dc+"publisher"]);
if(publisher) { if(publisher) {
@ -5699,7 +5714,7 @@ function doImport() {
newItem.archiveLocation = getFirstResults(node, [n.dc+"coverage"], true); newItem.archiveLocation = getFirstResults(node, [n.dc+"coverage"], true);
// type // type
newItem.type = newItem.thesisType = getFirstResults(node, [n.dc+"type"], true); newItem.type = getFirstResults(node, [n.dc+"type"], true);
// journalAbbreviation // journalAbbreviation
newItem.journalAbbreviation = getFirstResults((container ? container : node), [n.dcterms+"alternative"], true); newItem.journalAbbreviation = getFirstResults((container ? container : node), [n.dcterms+"alternative"], true);
@ -5707,8 +5722,12 @@ function doImport() {
// see also // see also
processSeeAlso(node, newItem); processSeeAlso(node, newItem);
// description // description/attachment note
if(newItem.itemType == "attachment") {
newItem.note = getFirstResults(node, [n.dc+"description"], true);
} else {
newItem.extra = getFirstResults(node, [n.dc+"description"], true); newItem.extra = getFirstResults(node, [n.dc+"description"], true);
}
/** NOTES **/ /** NOTES **/
@ -5757,13 +5776,73 @@ function doImport() {
for each(var relation in relations) { for each(var relation in relations) {
var type = Zotero.RDF.getTargets(relation, rdf+"type"); var type = Zotero.RDF.getTargets(relation, rdf+"type");
if(Zotero.RDF.getResourceURI(type[0]) == n.fs+"Attachment") { if(Zotero.RDF.getResourceURI(type[0]) == n.fs+"Attachment") {
newItem.attachments.push(handleAttachment(relation)); var attachment = new Object();
newItem.attachments.push(attachment);
importItem(attachment, relation, n.fs+"Attachment");
} }
} }
Zotero.Utilities.debug(newItem); return true;
}
function doImport() {
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
n = {
bib:"http://purl.org/net/biblio#",
dc:"http://purl.org/dc/elements/1.1/",
dcterms:"http://purl.org/dc/terms/",
prism:"http://prismstandard.org/namespaces/1.2/basic/",
foaf:"http://xmlns.com/foaf/0.1/",
vcard:"http://nwalsh.com/rdf/vCard#",
link:"http://purl.org/rss/1.0/modules/link/",
fs:"http://www.zotero.org/namespaces/export#"
};
callNumberTypes = [
n.dcterms+"LCC", n.dcterms+"DDC", n.dcterms+"UDC"
];
var nodes = Zotero.RDF.getAllResources();
if(!nodes) {
return false;
}
// keep track of collections while we''re looping through
var collections = new Array();
for each(var node in nodes) {
var newItem = new Zotero.Item();
newItem.itemID = Zotero.RDF.getResourceURI(node);
// figure out if this is a part of another resource, or a linked
// attachment
if(Zotero.RDF.getSources(node, n.dcterms+"isPartOf") ||
Zotero.RDF.getSources(node, n.link+"link")) {
continue;
}
// type
var type = Zotero.RDF.getTargets(node, rdf+"type");
if(type) {
type = Zotero.RDF.getResourceURI(type[0]);
// skip if this is not an independent attachment,
if((type == n.fs+"Attachment" || type == n.bib+"Memo") && isPart(node)) {
continue;
} else if(type == n.bib+"Collection") {
// skip collections until all the items are done
collections.push(node);
continue;
}
} else {
type = false;
}
if(importItem(newItem, node, type)) {
newItem.complete(); newItem.complete();
} }
}
/* COLLECTIONS */ /* COLLECTIONS */