use of org.jabref.logic.importer.fileformat.mods.NamePartDefinition 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);
}
}
}
use of org.jabref.logic.importer.fileformat.mods.NamePartDefinition in project jabref by JabRef.
the class ModsImporter method handleAuthorsInNamePart.
private void handleAuthorsInNamePart(NameDefinition name, List<String> authors, Map<String, String> fields) {
List<JAXBElement<?>> namePartOrDisplayFormOrAffiliation = name.getNamePartOrDisplayFormOrAffiliation();
List<String> foreName = new ArrayList<>();
String familyName = "";
String author = "";
for (JAXBElement<?> element : namePartOrDisplayFormOrAffiliation) {
Object value = element.getValue();
String elementName = element.getName().getLocalPart();
if (value instanceof NamePartDefinition) {
NamePartDefinition namePart = (NamePartDefinition) value;
String type = namePart.getAtType();
if ((type == null) && (namePart.getValue() != null)) {
authors.add(namePart.getValue());
} else if ("family".equals(type) && (namePart.getValue() != null)) {
//we have to check if forename and family name are not empty in case it's the first author
if (!foreName.isEmpty() && !familyName.isEmpty()) {
//now set and add the old author
author = familyName + ", " + Joiner.on(" ").join(foreName);
authors.add(author);
//remove old forenames
foreName.clear();
} else if (foreName.isEmpty() && !familyName.isEmpty()) {
authors.add(familyName);
}
familyName = namePart.getValue();
} else if ("given".equals(type) && (namePart.getValue() != null)) {
foreName.add(namePart.getValue());
}
} else if ((value instanceof StringPlusLanguage) && "affiliation".equals(elementName)) {
StringPlusLanguage affiliation = (StringPlusLanguage) value;
putIfValueNotNull(fields, "affiliation", affiliation.getValue());
}
}
//last author is not added, so do it here
if (!foreName.isEmpty() && !familyName.isEmpty()) {
author = familyName + ", " + Joiner.on(" ").join(foreName);
authors.add(author.trim());
foreName.clear();
} else if (foreName.isEmpty() && !familyName.isEmpty()) {
authors.add(familyName.trim());
}
}
Aggregations