Search in sources :

Example 1 with NameDefinition

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

the class ModsExportFormat method addAffiliation.

private void addAffiliation(ModsDefinition mods, String value) {
    NameDefinition nameDefinition = new NameDefinition();
    StringPlusLanguage affiliation = new StringPlusLanguage();
    affiliation.setValue(value);
    JAXBElement<StringPlusLanguage> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "affiliation"), StringPlusLanguage.class, affiliation);
    nameDefinition.getAffiliationOrRoleOrDescription().add(element);
    mods.getModsGroup().add(nameDefinition);
}
Also used : StringPlusLanguage(org.jabref.logic.importer.fileformat.mods.StringPlusLanguage) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) NameDefinition(org.jabref.logic.importer.fileformat.mods.NameDefinition)

Example 2 with NameDefinition

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

the class ModsExportFormat method handleAuthors.

private void handleAuthors(ModsDefinition mods, String value) {
    String[] authors = value.split("and");
    for (String author : authors) {
        NameDefinition name = new NameDefinition();
        name.setAtType("personal");
        NamePartDefinition namePart = new NamePartDefinition();
        if (author.contains(",")) {
            //if author contains ","  then this indicates that the author has a forename and family name
            int commaIndex = author.indexOf(',');
            String familyName = author.substring(0, commaIndex);
            namePart.setAtType("family");
            namePart.setValue(familyName);
            JAXBElement<NamePartDefinition> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "namePart"), NamePartDefinition.class, namePart);
            name.getNamePartOrDisplayFormOrAffiliation().add(element);
            //now take care of the forenames
            String forename = author.substring(commaIndex + 1, author.length());
            String[] forenames = forename.split(" ");
            for (String given : forenames) {
                if (!given.isEmpty()) {
                    NamePartDefinition namePartDefinition = new NamePartDefinition();
                    namePartDefinition.setAtType("given");
                    namePartDefinition.setValue(given);
                    element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "namePart"), NamePartDefinition.class, namePartDefinition);
                    name.getNamePartOrDisplayFormOrAffiliation().add(element);
                }
            }
            mods.getModsGroup().add(name);
        } else {
            //no "," indicates that there should only be a family name
            namePart.setAtType("family");
            namePart.setValue(author);
            JAXBElement<NamePartDefinition> element = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "namePart"), NamePartDefinition.class, namePart);
            name.getNamePartOrDisplayFormOrAffiliation().add(element);
            mods.getModsGroup().add(name);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) NamePartDefinition(org.jabref.logic.importer.fileformat.mods.NamePartDefinition) JAXBElement(javax.xml.bind.JAXBElement) NameDefinition(org.jabref.logic.importer.fileformat.mods.NameDefinition)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)2 QName (javax.xml.namespace.QName)2 NameDefinition (org.jabref.logic.importer.fileformat.mods.NameDefinition)2 NamePartDefinition (org.jabref.logic.importer.fileformat.mods.NamePartDefinition)1 StringPlusLanguage (org.jabref.logic.importer.fileformat.mods.StringPlusLanguage)1