Skip to content

Commit

Permalink
Fix export of corporate author to MSOffice (#4337)
Browse files Browse the repository at this point in the history
* Fix export of corporate author to MSOffice
Fix tests

* add comment
  • Loading branch information
Siedlerchr authored Sep 13, 2018
1 parent a47e826 commit b991648
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/jabref/logic/msbib/MSBibConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static MSBibEntry convert(BibEntry entry) {
// Value must be converted
//Currently only english is supported
entry.getLatexFreeField(FieldName.LANGUAGE)
.ifPresent(lang -> result.fields.put("LCID", String.valueOf(MSBibMapping.getLCID(lang))));
.ifPresent(lang -> result.fields.put("LCID", String.valueOf(MSBibMapping.getLCID(lang))));
StringBuilder sbNumber = new StringBuilder();
entry.getLatexFreeField(FieldName.ISBN).ifPresent(isbn -> sbNumber.append(" ISBN: " + isbn));
entry.getLatexFreeField(FieldName.ISSN).ifPresent(issn -> sbNumber.append(" ISSN: " + issn));
Expand Down Expand Up @@ -106,21 +106,28 @@ public static MSBibEntry convert(BibEntry entry) {
result.publicationTitle = entry.getLatexFreeField(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.getLatexFreeField(FieldName.TRANSLATOR).ifPresent(translator -> result.translators = getAuthors(translator));
entry.getField(FieldName.AUTHOR).ifPresent(authors -> result.authors = getAuthors(entry, authors, FieldName.AUTHOR));
entry.getField(FieldName.EDITOR).ifPresent(editors -> result.editors = getAuthors(entry, editors, FieldName.EDITOR));
entry.getField(FieldName.TRANSLATOR).ifPresent(translator -> result.translators = getAuthors(entry, translator, FieldName.EDITOR));

return result;
}

private static List<MsBibAuthor> getAuthors(String authors) {
private static List<MsBibAuthor> getAuthors(BibEntry entry, String authors, String fieldName) {
List<MsBibAuthor> result = new ArrayList<>();
boolean corporate = false;
//Only one corporate authors is supported
//Only one corporate author is supported
//We have the possible rare case that are multiple authors which start and end with latex , this is currently not considered
if (authors.startsWith("{") && authors.endsWith("}")) {
corporate = true;
}
AuthorList authorList = AuthorList.parse(authors);
//FIXME: #4152 This is an ugly hack because the latex2unicode formatter kills of all curly braces, so no more corporate author parsing possible
String authorLatexFree = entry.getLatexFreeField(fieldName).orElse("");
if (corporate) {
authorLatexFree = "{" + authorLatexFree + "}";
}

AuthorList authorList = AuthorList.parse(authorLatexFree);

for (Author author : authorList.getAuthors()) {
result.add(new MsBibAuthor(author, corporate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -64,7 +63,6 @@ void setUp(@TempDirectory.TempDir Path testFolder) throws Exception {
testImporter = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor());
}

@Disabled
@ParameterizedTest
@MethodSource("fileNames")
void testPerformExport(String filename) throws IOException, SaveException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Year>2002</b:Year>
<b:Volume>44</b:Volume>
<b:BIBTEX_Entry>phdthesis</b:BIBTEX_Entry>
Expand All @@ -16,8 +16,6 @@
<b:JournalName>Wirtschaftsinformatik</b:JournalName>
<b:Number>3</b:Number>
<b:City>a</b:City>
<b:StateProvince/>
<b:CountryRegion/>
<b:ThesisType>type</b:ThesisType>
</b:Source>
</b:Sources>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Year>2002</b:Year>
<b:Volume>44</b:Volume>
<b:BIBTEX_Entry>manual</b:BIBTEX_Entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Year>2002</b:Year>
<b:Volume>44</b:Volume>
<b:BIBTEX_Entry>inbook</b:BIBTEX_Entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Issue>3</b:Issue>
<b:Year>2002</b:Year>
<b:Volume>44</b:Volume>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Year>2002</b:Year>
<b:Volume>44</b:Volume>
<b:BIBTEX_Entry>mastersthesis</b:BIBTEX_Entry>
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/org/jabref/logic/exporter/MsBibLCID.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="">
<b:Source>
<b:SourceType>JournalArticle</b:SourceType>
<b:LCID>0</b:LCID>
<b:LCID>1033</b:LCID>
<b:Author/>
<b:BIBTEX_Entry>article</b:BIBTEX_Entry>
</b:Source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
</b:Author>
</b:Author>
<b:City>Berlin</b:City>
<b:StateProvince/>
<b:CountryRegion/>
</b:Source>
</b:Sources>

0 comments on commit b991648

Please sign in to comment.