use of org.jabref.logic.importer.fileformat.mods.RelatedItemDefinition in project jabref by JabRef.
the class ModsExportFormat method performExport.
@Override
public void performExport(final BibDatabaseContext databaseContext, final String file, final Charset encoding, List<BibEntry> entries) throws SaveException, IOException {
Objects.requireNonNull(databaseContext);
Objects.requireNonNull(entries);
if (entries.isEmpty()) {
// Only export if entries exist
return;
}
try {
ModsCollectionDefinition modsCollection = new ModsCollectionDefinition();
for (BibEntry bibEntry : entries) {
ModsDefinition mods = new ModsDefinition();
bibEntry.getCiteKeyOptional().ifPresent(citeKey -> addIdentifier("citekey", citeKey, mods));
Map<String, String> fieldMap = bibEntry.getFieldMap();
addGenre(bibEntry, mods);
OriginInfoDefinition originInfo = new OriginInfoDefinition();
PartDefinition partDefinition = new PartDefinition();
RelatedItemDefinition relatedItem = new RelatedItemDefinition();
for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
switch(key) {
case FieldName.AUTHOR:
handleAuthors(mods, value);
break;
case "affiliation":
addAffiliation(mods, value);
break;
case FieldName.ABSTRACT:
addAbstract(mods, value);
break;
case FieldName.TITLE:
addTitle(mods, value);
break;
case FieldName.LANGUAGE:
addLanguage(mods, value);
break;
case FieldName.LOCATION:
addLocation(mods, value);
break;
case FieldName.URL:
addUrl(mods, value);
break;
case FieldName.NOTE:
addNote(mods, value);
break;
case FieldName.KEYWORDS:
addKeyWords(mods, value);
break;
case FieldName.VOLUME:
addDetail(FieldName.VOLUME, value, partDefinition);
break;
case FieldName.ISSUE:
addDetail(FieldName.ISSUE, value, partDefinition);
break;
case FieldName.PAGES:
addPages(partDefinition, value);
break;
case FieldName.URI:
addIdentifier(FieldName.URI, value, mods);
break;
case FieldName.ISBN:
addIdentifier(FieldName.ISBN, value, mods);
break;
case FieldName.ISSN:
addIdentifier(FieldName.ISSN, value, mods);
break;
case FieldName.DOI:
addIdentifier(FieldName.DOI, value, mods);
break;
case FieldName.PMID:
addIdentifier(FieldName.PMID, value, mods);
break;
case FieldName.JOURNAL:
addJournal(value, relatedItem);
break;
default:
break;
}
addOriginInformation(key, value, originInfo);
}
mods.getModsGroup().add(originInfo);
addRelatedAndOriginInfoToModsGroup(relatedItem, partDefinition, mods);
modsCollection.getMods().add(mods);
}
JAXBElement<ModsCollectionDefinition> jaxbElement = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "modsCollection"), ModsCollectionDefinition.class, modsCollection);
createMarshallerAndWriteToFile(file, jaxbElement);
} catch (JAXBException ex) {
throw new SaveException(ex);
}
}
Aggregations