Search in sources :

Example 86 with JAXBElement

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);
    }
}
Also used : QName(javax.xml.namespace.QName) PlaceTermDefinition(org.jabref.logic.importer.fileformat.mods.PlaceTermDefinition) PlaceDefinition(org.jabref.logic.importer.fileformat.mods.PlaceDefinition) JAXBElement(javax.xml.bind.JAXBElement) IssuanceDefinition(org.jabref.logic.importer.fileformat.mods.IssuanceDefinition) StringPlusLanguagePlusSupplied(org.jabref.logic.importer.fileformat.mods.StringPlusLanguagePlusSupplied)

Example 87 with JAXBElement

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);
    }
}
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 88 with JAXBElement

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);
}
Also used : TitleInfoDefinition(org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition) StringPlusLanguage(org.jabref.logic.importer.fileformat.mods.StringPlusLanguage) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement)

Example 89 with JAXBElement

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);
}
Also used : TitleInfoDefinition(org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition) StringPlusLanguage(org.jabref.logic.importer.fileformat.mods.StringPlusLanguage) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement)

Example 90 with JAXBElement

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);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) QName(javax.xml.namespace.QName) BigInteger(java.math.BigInteger) JAXBElement(javax.xml.bind.JAXBElement) Map(java.util.Map)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)650 QName (javax.xml.namespace.QName)194 Element (org.w3c.dom.Element)124 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)95 ArrayList (java.util.ArrayList)93 MessageImpl (org.apache.cxf.message.MessageImpl)92 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 Test (org.junit.Test)87 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 JAXBException (javax.xml.bind.JAXBException)81 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 JAXBContext (javax.xml.bind.JAXBContext)75 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 Unmarshaller (javax.xml.bind.Unmarshaller)65 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58