use of javax.xml.bind.JAXBElement in project jabref by JabRef.
the class ModsExportFormat method addOriginInformation.
private void addOriginInformation(String key, String value, OriginInfoDefinition originInfo) {
if (FieldName.YEAR.equals(key)) {
addDate("dateIssued", value, originInfo);
} else if ("created".equals(key)) {
addDate("dateCreated", value, originInfo);
} else if ("modified".equals(key)) {
addDate("dateModified", value, originInfo);
} else if ("captured".equals(key)) {
addDate("dateCaptured", value, originInfo);
} else if (FieldName.PUBLISHER.equals(key)) {
StringPlusLanguagePlusSupplied publisher = new StringPlusLanguagePlusSupplied();
publisher.setValue(value);
JAXBElement<StringPlusLanguagePlusSupplied> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "publisher"), StringPlusLanguagePlusSupplied.class, publisher);
originInfo.getPlaceOrPublisherOrDateIssued().add(element);
} else if ("issuance".equals(key)) {
IssuanceDefinition issuance = IssuanceDefinition.fromValue(value);
JAXBElement<IssuanceDefinition> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "issuance"), IssuanceDefinition.class, issuance);
originInfo.getPlaceOrPublisherOrDateIssued().add(element);
} else if ("address".equals(key)) {
PlaceDefinition placeDefinition = new PlaceDefinition();
//There can be more than one place, so we split to get all places and add them
String[] places = value.split(", ");
for (String place : places) {
PlaceTermDefinition placeTerm = new PlaceTermDefinition();
//There's no possibility to see from a bib entry whether it is code or text, but since it is in the bib entry
//we assume that it is text
placeTerm.setType(CodeOrText.TEXT);
placeTerm.setValue(place);
placeDefinition.getPlaceTerm().add(placeTerm);
}
JAXBElement<PlaceDefinition> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "place"), PlaceDefinition.class, placeDefinition);
originInfo.getPlaceOrPublisherOrDateIssued().add(element);
} else if ("edition".equals(key)) {
StringPlusLanguagePlusSupplied edition = new StringPlusLanguagePlusSupplied();
edition.setValue(value);
JAXBElement<StringPlusLanguagePlusSupplied> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "edition"), StringPlusLanguagePlusSupplied.class, edition);
originInfo.getPlaceOrPublisherOrDateIssued().add(element);
}
}
use of javax.xml.bind.JAXBElement 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);
}
}
use of javax.xml.bind.JAXBElement in project jabref by JabRef.
the class ModsExportFormat method addTitle.
private void addTitle(ModsDefinition mods, String value) {
TitleInfoDefinition titleInfo = new TitleInfoDefinition();
StringPlusLanguage title = new StringPlusLanguage();
title.setValue(value);
JAXBElement<StringPlusLanguage> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "title"), StringPlusLanguage.class, title);
titleInfo.getTitleOrSubTitleOrPartNumber().add(element);
mods.getModsGroup().add(titleInfo);
}
use of javax.xml.bind.JAXBElement in project jabref by JabRef.
the class ModsExportFormat method addJournal.
private void addJournal(String value, RelatedItemDefinition relatedItem) {
TitleInfoDefinition titleInfo = new TitleInfoDefinition();
StringPlusLanguage title = new StringPlusLanguage();
title.setValue(value);
JAXBElement<StringPlusLanguage> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "title"), StringPlusLanguage.class, title);
titleInfo.getTitleOrSubTitleOrPartNumber().add(element);
relatedItem.getModsGroup().add(titleInfo);
}
use of javax.xml.bind.JAXBElement in project jabref by JabRef.
the class BibTeXMLExportFormat method parseInbook.
/**
* Contains same logic as the {@link parse()} method, but inbook needs a special treatment, because
* the contents of inbook are stored in a List of JAXBElements. So we first need to create
* a JAXBElement for every field and then add it to the content list.
*/
private void parseInbook(Inbook inbook, BibEntry bibEntry, Entry entry) {
Map<String, String> fieldMap = bibEntry.getFieldMap();
for (Map.Entry<String, String> entryField : fieldMap.entrySet()) {
String value = entryField.getValue();
String key = entryField.getKey();
if ("year".equals(key)) {
XMLGregorianCalendar calendar;
try {
calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
JAXBElement<XMLGregorianCalendar> year = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, "year"), XMLGregorianCalendar.class, calendar);
inbook.getContent().add(year);
} catch (DatatypeConfigurationException e) {
LOGGER.error("A configuration error occured");
}
} else if ("number".equals(key)) {
JAXBElement<BigInteger> number = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, "number"), BigInteger.class, new BigInteger(value));
inbook.getContent().add(number);
} else {
JAXBElement<String> element = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, key), String.class, value);
inbook.getContent().add(element);
}
}
//set the entryType to the entry
entry.setInbook(inbook);
}
Aggregations