Skip to content

Commit

Permalink
Export single corporate author to ms office xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Mar 26, 2017
1 parent 9205a02 commit c877ade
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/logic/msbib/MSBibConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ public static MSBibEntry convert(BibEntry entry) {
result.publicationTitle = entry.getField(FieldName.TITLE).orElse(null);
}

entry.getLatexFreeField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors));
entry.getLatexFreeField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors));
entry.getField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(authors));
entry.getField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(editors));

return result;
}

private static List<PersonName> getAuthors(String authors) {
List<PersonName> result = new ArrayList<>();
if (authors.startsWith("{") && authors.endsWith("}")) {
result.add(new PersonName(authors, true));
return result;
}

if (authors.toUpperCase(Locale.ENGLISH).contains(" AND ")) {
String[] names = authors.split(" (?i)and ");
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/org/jabref/logic/msbib/MSBibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -321,16 +322,31 @@ private void addAuthor(Document document, Element allAuthors, String entryName,
return;
}
Element authorTop = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + entryName);
Element nameList = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "NameList");
for (PersonName name : authorsLst) {
Element person = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "Person");
addField(document, person, "Last", name.getSurname());
addField(document, person, "Middle", name.getMiddlename());
addField(document, person, "First", name.getFirstname());
nameList.appendChild(person);

Optional<PersonName> personName = authorsLst.stream().filter(PersonName::isCorporateAuthor)
.findFirst();
if (personName.isPresent()) {
PersonName person = personName.get();

Element corporate = document.createElementNS(MSBibDatabase.NAMESPACE,
MSBibDatabase.PREFIX + "Corporate");
corporate.setTextContent(person.getFullname());
authorTop.appendChild(corporate);
} else {

Element nameList = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "NameList");
for (PersonName name : authorsLst) {
Element person = document.createElementNS(MSBibDatabase.NAMESPACE, MSBibDatabase.PREFIX + "Person");
addField(document, person, "Last", name.getSurname());
addField(document, person, "Middle", name.getMiddlename());
addField(document, person, "First", name.getFirstname());
nameList.appendChild(person);

}
authorTop.appendChild(nameList);
}
authorTop.appendChild(nameList);
allAuthors.appendChild(authorTop);

}

private void addAddress(Document document, Element parent, String addressToSplit) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/org/jabref/logic/msbib/PersonName.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PersonName {
private String givenName;
private String surname;
private String middleName;

private boolean isCorporate;

public PersonName() {
// Empty constructor
Expand All @@ -30,6 +30,12 @@ public PersonName(String name) {
parseName(name);
}

public PersonName(String name, boolean isCorporate) {
this(name);
this.isCorporate = isCorporate;

}

public PersonName(String firstName, String middleName, String lastName) {
givenName = firstName;
this.middleName = middleName;
Expand Down Expand Up @@ -59,8 +65,7 @@ private void parseName(String author) {
} else if (amountOfNames == 2) {
givenName = names.get(0);
surname = names.get(1);
}
else {
} else {
givenName = names.get(0);
middleName = "";
for (int i = 1; i < (amountOfNames - 1); i++) {
Expand Down Expand Up @@ -106,6 +111,10 @@ public void setMiddlename(String middleName) {
this.middleName = middleName;
}

public boolean isCorporateAuthor() {
return isCorporate;
}

public String getFullname() {
StringBuilder fullName = new StringBuilder();
if ((givenName != null) && !givenName.isEmpty()) {
Expand Down

0 comments on commit c877ade

Please sign in to comment.