Skip to content

Commit 69b4ea1

Browse files
authored
Endnote XML Exporter: Move factory initialization to constructor (#13321)
* Move factory initialization to constructor, rearrange as per Checkstyle, use javadoc Signed-off-by: subhramit <[email protected]> * Use int Signed-off-by: subhramit <[email protected]> --------- Signed-off-by: subhramit <[email protected]>
1 parent f8d6f8c commit 69b4ea1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

jablib/src/main/java/org/jabref/logic/exporter/EndnoteXmlExporter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939

4040
public class EndnoteXmlExporter extends Exporter {
4141

42-
private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
43-
44-
private record EndNoteType(String name, Integer number) {
45-
}
46-
4742
private static final Map<EntryType, EndNoteType> ENTRY_TYPE_MAPPING = new HashMap<>();
4843

4944
static {
@@ -64,8 +59,10 @@ private record EndNoteType(String name, Integer number) {
6459
ENTRY_TYPE_MAPPING.put(StandardEntryType.Misc, new EndNoteType("Generic", 15));
6560
}
6661

67-
// Contains the mapping of all fields not explicitly handled by mapX methods
68-
// We need a fixed order here, so we use a SequencedMap
62+
/**
63+
* Contains the mapping of all fields not explicitly handled by mapX methods.
64+
* We need a fixed order here, so we use a SequencedMap
65+
*/
6966
private static final SequencedMap<Field, String> STANDARD_FIELD_MAPPING = new LinkedHashMap<>();
7067

7168
static {
@@ -95,11 +92,17 @@ private record EndNoteType(String name, Integer number) {
9592

9693
private static final EndNoteType DEFAULT_TYPE = new EndNoteType("Generic", 15);
9794

95+
private final DocumentBuilderFactory documentBuilderFactory;
96+
97+
private record EndNoteType(String name, int number) {
98+
}
99+
98100
private final BibEntryPreferences bibEntryPreferences;
99101

100102
public EndnoteXmlExporter(BibEntryPreferences bibEntryPreferences) {
101103
super("endnote", "EndNote XML", StandardFileType.XML);
102104
this.bibEntryPreferences = bibEntryPreferences;
105+
this.documentBuilderFactory = DocumentBuilderFactory.newInstance();
103106
}
104107

105108
@Override
@@ -112,7 +115,7 @@ public void export(BibDatabaseContext databaseContext, Path file, List<BibEntry>
112115
return;
113116
}
114117

115-
DocumentBuilder dBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
118+
DocumentBuilder dBuilder = documentBuilderFactory.newDocumentBuilder();
116119
Document document = dBuilder.newDocument();
117120

118121
Element rootElement = document.createElement("xml");
@@ -187,7 +190,7 @@ private static void mapJournalTitle(BibEntry entry, Document document, Element r
187190
}
188191

189192
private void mapKeywords(BibDatabase bibDatabase, BibEntry entry, Document document, Element recordElement) {
190-
entry.getFieldOrAlias(StandardField.KEYWORDS).ifPresent(keywords -> {
193+
entry.getFieldOrAlias(StandardField.KEYWORDS).ifPresent(_ -> {
191194
Element keywordsElement = document.createElement("keywords");
192195
entry.getResolvedKeywords(bibEntryPreferences.getKeywordSeparator(), bibDatabase).forEach(keyword -> {
193196
Element keywordElement = document.createElement("keyword");
@@ -258,7 +261,7 @@ private static void mapEntryType(BibEntry entry, Document document, Element reco
258261
EndNoteType endNoteType = ENTRY_TYPE_MAPPING.getOrDefault(entryType, DEFAULT_TYPE);
259262
Element refTypeElement = document.createElement("ref-type");
260263
refTypeElement.setAttribute("name", endNoteType.name());
261-
refTypeElement.setTextContent(endNoteType.number().toString());
264+
refTypeElement.setTextContent(String.valueOf(endNoteType.number()));
262265
recordElement.appendChild(refTypeElement);
263266
}
264267

0 commit comments

Comments
 (0)