Search in sources :

Example 1 with PartDefinition

use of org.jabref.logic.importer.fileformat.mods.PartDefinition 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);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ModsCollectionDefinition(org.jabref.logic.importer.fileformat.mods.ModsCollectionDefinition) ModsDefinition(org.jabref.logic.importer.fileformat.mods.ModsDefinition) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) PartDefinition(org.jabref.logic.importer.fileformat.mods.PartDefinition) NamePartDefinition(org.jabref.logic.importer.fileformat.mods.NamePartDefinition) JAXBElement(javax.xml.bind.JAXBElement) OriginInfoDefinition(org.jabref.logic.importer.fileformat.mods.OriginInfoDefinition) RelatedItemDefinition(org.jabref.logic.importer.fileformat.mods.RelatedItemDefinition) Map(java.util.Map)

Example 2 with PartDefinition

use of org.jabref.logic.importer.fileformat.mods.PartDefinition in project jabref by JabRef.

the class ModsImporter method parseRelatedModsGroup.

/**
     * Puts the Information from the RelatedModsGroup. It has the same elements like the ModsGroup.
     * But Informations like volume, issue and the pages appear here instead of in the ModsGroup.
     * Also if there appears a title field, then this indicates that is the name of journal which the article belongs to.
     */
private void parseRelatedModsGroup(Map<String, String> fields, List<Object> relatedModsGroup) {
    for (Object groupElement : relatedModsGroup) {
        if (groupElement instanceof PartDefinition) {
            PartDefinition part = (PartDefinition) groupElement;
            List<Object> detailOrExtentOrDate = part.getDetailOrExtentOrDate();
            for (Object object : detailOrExtentOrDate) {
                if (object instanceof DetailDefinition) {
                    DetailDefinition detail = (DetailDefinition) object;
                    List<JAXBElement<StringPlusLanguage>> numberOrCaptionOrTitle = detail.getNumberOrCaptionOrTitle();
                    //In the for loop should only be the value of the element that belongs to the detail not be null
                    for (JAXBElement<StringPlusLanguage> jaxbElement : numberOrCaptionOrTitle) {
                        StringPlusLanguage value = jaxbElement.getValue();
                        //put details like volume, issue,...
                        putIfValueNotNull(fields, detail.getType(), value.getValue());
                    }
                } else if (object instanceof ExtentDefinition) {
                    ExtentDefinition extentDefinition = (ExtentDefinition) object;
                    putPageInformation(extentDefinition, fields);
                }
            }
        } else if (groupElement instanceof TitleInfoDefinition) {
            TitleInfoDefinition titleInfo = (TitleInfoDefinition) groupElement;
            List<Object> titleOrSubTitleOrPartNumber = titleInfo.getTitleOrSubTitleOrPartNumber();
            for (Object object : titleOrSubTitleOrPartNumber) {
                if (object instanceof JAXBElement) {
                    @SuppressWarnings("unchecked") JAXBElement<StringPlusLanguage> element = (JAXBElement<StringPlusLanguage>) object;
                    if ("title".equals(element.getName().getLocalPart())) {
                        StringPlusLanguage journal = element.getValue();
                        fields.put(FieldName.JOURNAL, journal.getValue());
                    }
                }
            }
        }
    }
}
Also used : ExtentDefinition(org.jabref.logic.importer.fileformat.mods.ExtentDefinition) TitleInfoDefinition(org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition) DetailDefinition(org.jabref.logic.importer.fileformat.mods.DetailDefinition) StringPlusLanguage(org.jabref.logic.importer.fileformat.mods.StringPlusLanguage) PartDefinition(org.jabref.logic.importer.fileformat.mods.PartDefinition) NamePartDefinition(org.jabref.logic.importer.fileformat.mods.NamePartDefinition) List(java.util.List) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)2 NamePartDefinition (org.jabref.logic.importer.fileformat.mods.NamePartDefinition)2 PartDefinition (org.jabref.logic.importer.fileformat.mods.PartDefinition)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 JAXBException (javax.xml.bind.JAXBException)1 QName (javax.xml.namespace.QName)1 DetailDefinition (org.jabref.logic.importer.fileformat.mods.DetailDefinition)1 ExtentDefinition (org.jabref.logic.importer.fileformat.mods.ExtentDefinition)1 ModsCollectionDefinition (org.jabref.logic.importer.fileformat.mods.ModsCollectionDefinition)1 ModsDefinition (org.jabref.logic.importer.fileformat.mods.ModsDefinition)1 OriginInfoDefinition (org.jabref.logic.importer.fileformat.mods.OriginInfoDefinition)1 RelatedItemDefinition (org.jabref.logic.importer.fileformat.mods.RelatedItemDefinition)1 StringPlusLanguage (org.jabref.logic.importer.fileformat.mods.StringPlusLanguage)1 TitleInfoDefinition (org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition)1 BibEntry (org.jabref.model.entry.BibEntry)1