From 89c48ffdcd9e8a39c9c3058dbf0e3f992e8157a9 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Fri, 19 May 2023 23:38:45 +0200 Subject: [PATCH 01/11] Simple code maintenance (moving around, simplifying, extracting) --- .../logic/exporter/ExporterFactory.java | 2 - .../logic/exporter/TemplateExporter.java | 29 +- .../jabref/preferences/JabRefPreferences.java | 333 +++++++++--------- .../preferences/PreferencesService.java | 76 +--- 4 files changed, 201 insertions(+), 239 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index bf7b03ab6a4..e81316bf5dd 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -54,8 +54,6 @@ public static ExporterFactory create(List customFormats, List exporters = new ArrayList<>(); - // Initialize build-in exporters - // Initialize build-in exporters exporters.add(new TemplateExporter("HTML", "html", "html", null, StandardFileType.HTML, layoutPreferences, saveConfiguration)); exporters.add(new TemplateExporter(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, StandardFileType.HTML, layoutPreferences, saveConfiguration)); diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index 37a9716cdf3..e33635cd3b6 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -59,7 +59,11 @@ public class TemplateExporter extends Exporter { * @param directory Directory in which to find the layout file. * @param extension Should contain the . (for instance .txt). */ - public TemplateExporter(String displayName, String consoleName, String lfFileName, String directory, FileType extension) { + public TemplateExporter(String displayName, + String consoleName, + String lfFileName, + String directory, + FileType extension) { this(displayName, consoleName, lfFileName, directory, extension, null, null); } @@ -72,7 +76,10 @@ public TemplateExporter(String displayName, String consoleName, String lfFileNam * @param layoutPreferences Preferences for the layout * @param saveConfiguration Preferences for saving */ - public TemplateExporter(String name, String lfFileName, String extension, LayoutFormatterPreferences layoutPreferences, + public TemplateExporter(String name, + String lfFileName, + String extension, + LayoutFormatterPreferences layoutPreferences, SaveConfiguration saveConfiguration) { this(name, name, lfFileName, null, StandardFileType.fromExtensions(extension), layoutPreferences, saveConfiguration); } @@ -88,8 +95,13 @@ public TemplateExporter(String name, String lfFileName, String extension, Layout * @param layoutPreferences Preferences for layout * @param saveConfiguration Preferences for saving */ - public TemplateExporter(String displayName, String consoleName, String lfFileName, String directory, FileType extension, - LayoutFormatterPreferences layoutPreferences, SaveConfiguration saveConfiguration) { + public TemplateExporter(String displayName, + String consoleName, + String lfFileName, + String directory, + FileType extension, + LayoutFormatterPreferences layoutPreferences, + SaveConfiguration saveConfiguration) { super(consoleName, displayName, extension); if (Objects.requireNonNull(lfFileName).endsWith(LAYOUT_EXTENSION)) { this.lfFileName = lfFileName.substring(0, lfFileName.length() - LAYOUT_EXTENSION.length()); @@ -113,8 +125,13 @@ public TemplateExporter(String displayName, String consoleName, String lfFileNam * @param saveConfiguration Preferences for saving * @param blankLineBehaviour how to behave regarding blank lines. */ - public TemplateExporter(String displayName, String consoleName, String lfFileName, String directory, FileType extension, - LayoutFormatterPreferences layoutPreferences, SaveConfiguration saveConfiguration, + public TemplateExporter(String displayName, + String consoleName, + String lfFileName, + String directory, + FileType extension, + LayoutFormatterPreferences layoutPreferences, + SaveConfiguration saveConfiguration, BlankLineBehaviour blankLineBehaviour) { super(consoleName, displayName, extension); if (Objects.requireNonNull(lfFileName).endsWith(LAYOUT_EXTENSION)) { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 53ddba0445a..567013b5f30 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -33,6 +33,7 @@ import javafx.beans.InvalidationListener; import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; import javafx.collections.SetChangeListener; import javafx.scene.control.TableColumn.SortType; @@ -763,6 +764,23 @@ private JabRefPreferences() { setLanguageDependentDefaultValues(); } + public void setLanguageDependentDefaultValues() { + // Entry editor tab 0: + defaults.put(CUSTOM_TAB_NAME + "_def0", Localization.lang("General")); + String fieldNames = FieldFactory.getDefaultGeneralFields().stream().map(Field::getName).collect(Collectors.joining(STRINGLIST_DELIMITER.toString())); + defaults.put(CUSTOM_TAB_FIELDS + "_def0", fieldNames); + + // Entry editor tab 1: + defaults.put(CUSTOM_TAB_FIELDS + "_def1", StandardField.ABSTRACT.getName()); + defaults.put(CUSTOM_TAB_NAME + "_def1", Localization.lang("Abstract")); + + // Entry editor tab 2: Comments Field - used for research comments, etc. + defaults.put(CUSTOM_TAB_FIELDS + "_def2", StandardField.COMMENT.getName()); + defaults.put(CUSTOM_TAB_NAME + "_def2", Localization.lang("Comments")); + + defaults.put(EMAIL_SUBJECT, Localization.lang("References")); + } + /** * @return Instance of JaRefPreferences * @deprecated Use {@link PreferencesService} instead @@ -775,6 +793,10 @@ public static JabRefPreferences getInstance() { return JabRefPreferences.singleton; } + //************************************************************************************************************* + // Common serializer logic + //************************************************************************************************************* + private static String convertListToString(List value) { return value.stream().map(val -> StringUtil.quote(val, STRINGLIST_DELIMITER.toString(), '\\')).collect(Collectors.joining(STRINGLIST_DELIMITER.toString())); } @@ -841,22 +863,9 @@ private static Optional getNextUnit(Reader data) throws IOException { } } - public void setLanguageDependentDefaultValues() { - // Entry editor tab 0: - defaults.put(CUSTOM_TAB_NAME + "_def0", Localization.lang("General")); - String fieldNames = FieldFactory.getDefaultGeneralFields().stream().map(Field::getName).collect(Collectors.joining(STRINGLIST_DELIMITER.toString())); - defaults.put(CUSTOM_TAB_FIELDS + "_def0", fieldNames); - - // Entry editor tab 1: - defaults.put(CUSTOM_TAB_FIELDS + "_def1", StandardField.ABSTRACT.getName()); - defaults.put(CUSTOM_TAB_NAME + "_def1", Localization.lang("Abstract")); - - // Entry editor tab 2: Comments Field - used for research comments, etc. - defaults.put(CUSTOM_TAB_FIELDS + "_def2", StandardField.COMMENT.getName()); - defaults.put(CUSTOM_TAB_NAME + "_def2", Localization.lang("Comments")); - - defaults.put(EMAIL_SUBJECT, Localization.lang("References")); - } + //************************************************************************************************************* + // Backingstore access logic + //************************************************************************************************************* /** * Check whether a key is set (differently from null). @@ -1117,6 +1126,10 @@ public void importPreferences(Path file) throws JabRefException { } } + //************************************************************************************************************* + // ToDo: Cleanup + //************************************************************************************************************* + @Override public LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviationRepository repository) { return new LayoutFormatterPreferences( @@ -1125,24 +1138,6 @@ public LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviat repository); } - @Override - public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { - if (Objects.nonNull(journalAbbreviationPreferences)) { - return journalAbbreviationPreferences; - } - - journalAbbreviationPreferences = new JournalAbbreviationPreferences( - getStringList(EXTERNAL_JOURNAL_LISTS), - getBoolean(USE_AMS_FJOURNAL)); - - journalAbbreviationPreferences.getExternalJournalLists().addListener((InvalidationListener) change -> - putStringList(EXTERNAL_JOURNAL_LISTS, journalAbbreviationPreferences.getExternalJournalLists())); - EasyBind.listen(journalAbbreviationPreferences.useFJournalFieldProperty(), - (obs, oldValue, newValue) -> putBoolean(USE_AMS_FJOURNAL, newValue)); - - return journalAbbreviationPreferences; - } - @Override public KeyBindingRepository getKeyBindingRepository() { return new KeyBindingRepository(getStringList(BIND_NAMES), getStringList(BINDINGS)); @@ -1162,6 +1157,24 @@ public void setPreviewStyle(String previewStyle) { put(PREVIEW_STYLE, previewStyle); } + @Override + public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { + if (Objects.nonNull(journalAbbreviationPreferences)) { + return journalAbbreviationPreferences; + } + + journalAbbreviationPreferences = new JournalAbbreviationPreferences( + getStringList(EXTERNAL_JOURNAL_LISTS), + getBoolean(USE_AMS_FJOURNAL)); + + journalAbbreviationPreferences.getExternalJournalLists().addListener((InvalidationListener) change -> + putStringList(EXTERNAL_JOURNAL_LISTS, journalAbbreviationPreferences.getExternalJournalLists())); + EasyBind.listen(journalAbbreviationPreferences.useFJournalFieldProperty(), + (obs, oldValue, newValue) -> putBoolean(USE_AMS_FJOURNAL, newValue)); + + return journalAbbreviationPreferences; + } + //************************************************************************************************************* // CustomEntryTypes //************************************************************************************************************* @@ -1233,6 +1246,10 @@ private static Preferences getPrefsNodeForCustomizedEntryTypes(BibDatabaseMode m : PREFS_NODE.node(CUSTOMIZED_BIBLATEX_TYPES); } + //************************************************************************************************************* + // Misc + //************************************************************************************************************* + @Override public OpenOfficePreferences getOpenOfficePreferences() { if (Objects.nonNull(openOfficePreferences)) { @@ -1274,13 +1291,6 @@ public LibraryPreferences getLibraryPreferences() { return libraryPreferences; } - private Language getLanguage() { - return Stream.of(Language.values()) - .filter(language -> language.getId().equalsIgnoreCase(get(LANGUAGE))) - .findFirst() - .orElse(Language.ENGLISH); - } - @Override public TelemetryPreferences getTelemetryPreferences() { if (Objects.nonNull(telemetryPreferences)) { @@ -1369,10 +1379,6 @@ public TimestampPreferences getTimestampPreferences() { return timestampPreferences; } - //************************************************************************************************************* - // GroupsPreferences - //************************************************************************************************************* - @Override public GroupsPreferences getGroupsPreferences() { if (Objects.nonNull(groupsPreferences)) { @@ -1650,19 +1656,11 @@ public CitationKeyPatternPreferences getCitationKeyPatternPreferences() { return citationKeyPatternPreferences; } - CitationKeyPatternPreferences.KeySuffix keySuffix = - CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_B; - if (getBoolean(KEY_GEN_ALWAYS_ADD_LETTER)) { - keySuffix = CitationKeyPatternPreferences.KeySuffix.ALWAYS; - } else if (getBoolean(KEY_GEN_FIRST_LETTER_A)) { - keySuffix = CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_A; - } - citationKeyPatternPreferences = new CitationKeyPatternPreferences( getBoolean(AVOID_OVERWRITING_KEY), getBoolean(WARN_BEFORE_OVERWRITING_KEY), getBoolean(GENERATE_KEYS_BEFORE_SAVING), - keySuffix, + getKeySuffix(), get(KEY_PATTERN_REGEX), get(KEY_PATTERN_REPLACEMENT), get(UNWANTED_CITATION_KEY_CHARACTERS), @@ -1677,22 +1675,9 @@ public CitationKeyPatternPreferences getCitationKeyPatternPreferences() { EasyBind.listen(citationKeyPatternPreferences.shouldGenerateCiteKeysBeforeSavingProperty(), (obs, oldValue, newValue) -> putBoolean(GENERATE_KEYS_BEFORE_SAVING, newValue)); EasyBind.listen(citationKeyPatternPreferences.keySuffixProperty(), (obs, oldValue, newValue) -> { - switch (newValue) { - case ALWAYS -> { - putBoolean(KEY_GEN_ALWAYS_ADD_LETTER, true); - putBoolean(KEY_GEN_FIRST_LETTER_A, false); - } - case SECOND_WITH_A -> { - putBoolean(KEY_GEN_ALWAYS_ADD_LETTER, false); - putBoolean(KEY_GEN_FIRST_LETTER_A, true); - } - case SECOND_WITH_B -> { - putBoolean(KEY_GEN_ALWAYS_ADD_LETTER, false); - putBoolean(KEY_GEN_FIRST_LETTER_A, false); - } - } - } - ); + putBoolean(KEY_GEN_ALWAYS_ADD_LETTER, newValue == CitationKeyPatternPreferences.KeySuffix.ALWAYS); + putBoolean(KEY_GEN_FIRST_LETTER_A, newValue == CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_A); + }); EasyBind.listen(citationKeyPatternPreferences.keyPatternRegexProperty(), (obs, oldValue, newValue) -> put(KEY_PATTERN_REGEX, newValue)); EasyBind.listen(citationKeyPatternPreferences.keyPatternReplacementProperty(), @@ -1705,6 +1690,17 @@ public CitationKeyPatternPreferences getCitationKeyPatternPreferences() { return citationKeyPatternPreferences; } + private CitationKeyPatternPreferences.KeySuffix getKeySuffix() { + CitationKeyPatternPreferences.KeySuffix keySuffix = + CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_B; + if (getBoolean(KEY_GEN_ALWAYS_ADD_LETTER)) { + keySuffix = CitationKeyPatternPreferences.KeySuffix.ALWAYS; + } else if (getBoolean(KEY_GEN_FIRST_LETTER_A)) { + keySuffix = CitationKeyPatternPreferences.KeySuffix.SECOND_WITH_A; + } + return keySuffix; + } + //************************************************************************************************************* // ExternalApplicationsPreferences //************************************************************************************************************* @@ -1731,31 +1727,32 @@ public PushToApplicationPreferences getPushToApplicationPreferences() { ); EasyBind.listen(pushToApplicationPreferences.activeApplicationNameProperty(), (obs, oldValue, newValue) -> put(PUSH_TO_APPLICATION, newValue)); - - pushToApplicationPreferences.getCommandPaths().addListener((obs, oldValue, newValue) -> - newValue.forEach((key, value) -> { - switch (key) { - case PushToApplications.EMACS -> - put(PUSH_EMACS_PATH, value); - case PushToApplications.LYX -> - put(PUSH_LYXPIPE, value); - case PushToApplications.TEXMAKER -> - put(PUSH_TEXMAKER_PATH, value); - case PushToApplications.TEXSTUDIO -> - put(PUSH_TEXSTUDIO_PATH, value); - case PushToApplications.VIM -> - put(PUSH_VIM, value); - case PushToApplications.WIN_EDT -> - put(PUSH_WINEDT_PATH, value); - } - })); - + pushToApplicationPreferences.getCommandPaths().addListener((obs, oldValue, newValue) -> storePushToApplicationPath(newValue)); EasyBind.listen(pushToApplicationPreferences.emacsArgumentsProperty(), (obs, oldValue, newValue) -> put(PUSH_EMACS_ADDITIONAL_PARAMETERS, newValue)); EasyBind.listen(pushToApplicationPreferences.vimServerProperty(), (obs, oldValue, newValue) -> put(PUSH_VIM_SERVER, newValue)); return pushToApplicationPreferences; } + private void storePushToApplicationPath(Map commandPair) { + commandPair.forEach((key, value) -> { + switch (key) { + case PushToApplications.EMACS -> + put(PUSH_EMACS_PATH, value); + case PushToApplications.LYX -> + put(PUSH_LYXPIPE, value); + case PushToApplications.TEXMAKER -> + put(PUSH_TEXMAKER_PATH, value); + case PushToApplications.TEXSTUDIO -> + put(PUSH_TEXSTUDIO_PATH, value); + case PushToApplications.VIM -> + put(PUSH_VIM, value); + case PushToApplications.WIN_EDT -> + put(PUSH_WINEDT_PATH, value); + } + }); + } + @Override public ExternalApplicationsPreferences getExternalApplicationsPreferences() { if (Objects.nonNull(externalApplicationsPreferences)) { @@ -1790,7 +1787,7 @@ public ExternalApplicationsPreferences getExternalApplicationsPreferences() { } //************************************************************************************************************* - // MainTablePreferences, SearchDialogColumnPreferences and ColumnPreferences + // Main table and search dialog preferences //************************************************************************************************************* @Override @@ -1935,25 +1932,9 @@ public NameDisplayPreferences getNameDisplayPreferences() { return nameDisplayPreferences; } - DisplayStyle displayStyle = DisplayStyle.LASTNAME_FIRSTNAME; // default - if (getBoolean(NAMES_NATBIB)) { - displayStyle = DisplayStyle.NATBIB; - } else if (getBoolean(NAMES_AS_IS)) { - displayStyle = DisplayStyle.AS_IS; - } else if (getBoolean(NAMES_FIRST_LAST)) { - displayStyle = DisplayStyle.FIRSTNAME_LASTNAME; - } - - AbbreviationStyle abbreviationStyle = AbbreviationStyle.NONE; // default - if (getBoolean(ABBR_AUTHOR_NAMES)) { - abbreviationStyle = AbbreviationStyle.FULL; - } else if (getBoolean(NAMES_LAST_ONLY)) { - abbreviationStyle = AbbreviationStyle.LASTNAME_ONLY; - } - nameDisplayPreferences = new NameDisplayPreferences( - displayStyle, - abbreviationStyle); + getNameDisplayStyle(), + getNameAbbreviationStyle()); EasyBind.listen(nameDisplayPreferences.displayStyleProperty(), (obs, oldValue, newValue) -> { putBoolean(NAMES_NATBIB, newValue == DisplayStyle.NATBIB); @@ -1968,6 +1949,28 @@ public NameDisplayPreferences getNameDisplayPreferences() { return nameDisplayPreferences; } + private AbbreviationStyle getNameAbbreviationStyle() { + AbbreviationStyle abbreviationStyle = AbbreviationStyle.NONE; // default + if (getBoolean(ABBR_AUTHOR_NAMES)) { + abbreviationStyle = AbbreviationStyle.FULL; + } else if (getBoolean(NAMES_LAST_ONLY)) { + abbreviationStyle = AbbreviationStyle.LASTNAME_ONLY; + } + return abbreviationStyle; + } + + private DisplayStyle getNameDisplayStyle() { + DisplayStyle displayStyle = DisplayStyle.LASTNAME_FIRSTNAME; // default + if (getBoolean(NAMES_NATBIB)) { + displayStyle = DisplayStyle.NATBIB; + } else if (getBoolean(NAMES_AS_IS)) { + displayStyle = DisplayStyle.AS_IS; + } else if (getBoolean(NAMES_FIRST_LAST)) { + displayStyle = DisplayStyle.FIRSTNAME_LASTNAME; + } + return displayStyle; + } + //************************************************************************************************************* // BibEntryPreferences //************************************************************************************************************* @@ -2031,7 +2034,7 @@ private String getUserAndHost() { } //************************************************************************************************************* - // AppearancePreferences + // WorkspacePreferences //************************************************************************************************************* @Override @@ -2069,19 +2072,11 @@ public WorkspacePreferences getWorkspacePreferences() { return workspacePreferences; } - //************************************************************************************************************* - // File preferences - //************************************************************************************************************* - - @Override - public ImportFormatPreferences getImportFormatPreferences() { - return new ImportFormatPreferences( - getBibEntryPreferences(), - getCitationKeyPatternPreferences(), - getFieldPreferences(), - getXmpPreferences(), - getDOIPreferences(), - getGrobidPreferences()); + private Language getLanguage() { + return Stream.of(Language.values()) + .filter(language -> language.getId().equalsIgnoreCase(get(LANGUAGE))) + .findFirst() + .orElse(Language.ENGLISH); } @Override @@ -2108,6 +2103,10 @@ public FieldPreferences getFieldPreferences() { return fieldPreferences; } + //************************************************************************************************************* + // Linked files preferences + //************************************************************************************************************* + @Override public FilePreferences getFilePreferences() { if (Objects.nonNull(filePreferences)) { @@ -2149,43 +2148,36 @@ public AutoLinkPreferences getAutoLinkPreferences() { return autoLinkPreferences; } - AutoLinkPreferences.CitationKeyDependency citationKeyDependency = - AutoLinkPreferences.CitationKeyDependency.START; // default - if (getBoolean(AUTOLINK_EXACT_KEY_ONLY)) { - citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.EXACT; - } else if (getBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY)) { - citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.REGEX; - } - autoLinkPreferences = new AutoLinkPreferences( - citationKeyDependency, + getAutoLinkKeyDependency(), get(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY), getBoolean(ASK_AUTO_NAMING_PDFS_AGAIN), bibEntryPreferences.keywordSeparatorProperty()); EasyBind.listen(autoLinkPreferences.citationKeyDependencyProperty(), (obs, oldValue, newValue) -> { - // Starts bibtex only omitted, as it is not being saved - switch (newValue) { - case START -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); - } - case EXACT -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, true); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); - } - case REGEX -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, true); - } - } - }); - EasyBind.listen(autoLinkPreferences.askAutoNamingPdfsProperty(), (obs, oldValue, newValue) -> putBoolean(ASK_AUTO_NAMING_PDFS_AGAIN, newValue)); - EasyBind.listen(autoLinkPreferences.regularExpressionProperty(), (obs, oldValue, newValue) -> put(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY, newValue)); + // Starts bibtex only omitted, as it is not being saved + putBoolean(AUTOLINK_EXACT_KEY_ONLY, newValue == AutoLinkPreferences.CitationKeyDependency.EXACT); + putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, newValue == AutoLinkPreferences.CitationKeyDependency.REGEX); + }); + EasyBind.listen(autoLinkPreferences.askAutoNamingPdfsProperty(), + (obs, oldValue, newValue) -> putBoolean(ASK_AUTO_NAMING_PDFS_AGAIN, newValue)); + EasyBind.listen(autoLinkPreferences.regularExpressionProperty(), + (obs, oldValue, newValue) -> put(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY, newValue)); return autoLinkPreferences; } + private AutoLinkPreferences.CitationKeyDependency getAutoLinkKeyDependency() { + AutoLinkPreferences.CitationKeyDependency citationKeyDependency = + AutoLinkPreferences.CitationKeyDependency.START; // default + if (getBoolean(AUTOLINK_EXACT_KEY_ONLY)) { + citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.EXACT; + } else if (getBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY)) { + citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.REGEX; + } + return citationKeyDependency; + } + //************************************************************************************************************* // Import/Export preferences //************************************************************************************************************* @@ -2208,7 +2200,7 @@ public ExportPreferences getExportPreferences() { return exportPreferences; } - public SaveOrder getExportSaveOrder() { + private SaveOrder getExportSaveOrder() { List sortCriteria = List.of( new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)), new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)), @@ -2221,7 +2213,7 @@ public SaveOrder getExportSaveOrder() { ); } - public void storeExportSaveOrder(SaveOrder saveOrder) { + private void storeExportSaveOrder(SaveOrder saveOrder) { putBoolean(EXPORT_IN_ORIGINAL_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.ORIGINAL); putBoolean(EXPORT_IN_SPECIFIED_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.SPECIFIED); @@ -2321,15 +2313,7 @@ public PreviewPreferences getPreviewPreferences() { (String) defaults.get(PREVIEW_STYLE), getBoolean(PREVIEW_AS_TAB)); - previewPreferences.getLayoutCycle().addListener((InvalidationListener) c -> - putStringList(CYCLE_PREVIEW, previewPreferences.getLayoutCycle().stream() - .map(layout -> { - if (layout instanceof CitationStylePreviewLayout citationStyleLayout) { - return citationStyleLayout.getFilePath(); - } else { - return layout.getDisplayName(); - } - }).collect(Collectors.toList()))); + previewPreferences.getLayoutCycle().addListener((InvalidationListener) c -> storePreviewLayouts(previewPreferences.getLayoutCycle())); EasyBind.listen(previewPreferences.layoutCyclePositionProperty(), (obs, oldValue, newValue) -> putInt(CYCLE_PREVIEW_POS, newValue)); EasyBind.listen(previewPreferences.customPreviewLayoutProperty(), (obs, oldValue, newValue) -> put(PREVIEW_STYLE, newValue.getText())); EasyBind.listen(previewPreferences.showPreviewAsExtraTabProperty(), (obs, oldValue, newValue) -> putBoolean(PREVIEW_AS_TAB, newValue)); @@ -2359,6 +2343,18 @@ private List getPreviewLayouts(String style) { .collect(Collectors.toList()); } + private void storePreviewLayouts(ObservableList previewCycle) { + putStringList(CYCLE_PREVIEW, previewCycle.stream() + .map(layout -> { + if (layout instanceof CitationStylePreviewLayout citationStyleLayout) { + return citationStyleLayout.getFilePath(); + } else { + return layout.getDisplayName(); + } + }).collect(Collectors.toList()) + ); + } + private int getPreviewCyclePosition(List layouts) { int storedCyclePos = getInt(CYCLE_PREVIEW_POS); if (storedCyclePos < layouts.size()) { @@ -2567,7 +2563,7 @@ private void storeFileHistory(FileHistory history) { } //************************************************************************************************************* - // Search preferences + // Misc preferences //************************************************************************************************************* @Override @@ -2609,10 +2605,6 @@ public SearchPreferences getSearchPreferences() { return searchPreferences; } - //************************************************************************************************************* - // Misc preferences - //************************************************************************************************************* - @Override public XmpPreferences getXmpPreferences() { if (Objects.nonNull(xmpPreferences)) { @@ -2859,4 +2851,15 @@ public GrobidPreferences getGrobidPreferences() { return grobidPreferences; } + +@Override + public ImportFormatPreferences getImportFormatPreferences() { + return new ImportFormatPreferences( + getBibEntryPreferences(), + getCitationKeyPatternPreferences(), + getFieldPreferences(), + getXmpPreferences(), + getDOIPreferences(), + getGrobidPreferences()); + } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 5231b78c9c4..ec0cc48e6a7 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -41,6 +41,16 @@ public interface PreferencesService { + void clear() throws BackingStoreException; + + void deleteKey(String key) throws IllegalArgumentException; + + void flush(); + + void exportPreferences(Path file) throws JabRefException; + + void importPreferences(Path file) throws JabRefException; + InternalPreferences getInternalPreferences(); BibEntryPreferences getBibEntryPreferences(); @@ -61,22 +71,12 @@ public interface PreferencesService { Map getDefaults(); - void exportPreferences(Path file) throws JabRefException; - - void importPreferences(Path file) throws JabRefException; - LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviationRepository repository); ImportFormatPreferences getImportFormatPreferences(); SaveConfiguration getExportConfiguration(); - void clear() throws BackingStoreException; - - void deleteKey(String key) throws IllegalArgumentException; - - void flush(); - BibEntryTypesManager getCustomEntryTypesRepository(); void storeCustomEntryTypesRepository(BibEntryTypesManager entryTypesManager); @@ -95,78 +95,38 @@ public interface PreferencesService { TimestampPreferences getTimestampPreferences(); - //************************************************************************************************************* - // GroupsPreferences - //************************************************************************************************************* - GroupsPreferences getGroupsPreferences(); - //************************************************************************************************************* - // EntryEditorPreferences - //************************************************************************************************************* - Map> getDefaultTabNamesAndFields(); List getAllDefaultTabFieldNames(); EntryEditorPreferences getEntryEditorPreferences(); - //************************************************************************************************************* - // Network preferences - //************************************************************************************************************* - RemotePreferences getRemotePreferences(); ProxyPreferences getProxyPreferences(); SSLPreferences getSSLPreferences(); - //************************************************************************************************************* - // CitationKeyPatternPreferences - //************************************************************************************************************* - CitationKeyPatternPreferences getCitationKeyPatternPreferences(); - //************************************************************************************************************* - // ExternalApplicationsPreferences - //************************************************************************************************************* - PushToApplicationPreferences getPushToApplicationPreferences(); ExternalApplicationsPreferences getExternalApplicationsPreferences(); - //************************************************************************************************************* - // MainTablePreferences - //************************************************************************************************************* - ColumnPreferences getMainTableColumnPreferences(); MainTablePreferences getMainTablePreferences(); NameDisplayPreferences getNameDisplayPreferences(); - //************************************************************************************************************* - // SearchDialogColumnPreferences - //************************************************************************************************************* - ColumnPreferences getSearchDialogColumnPreferences(); - //************************************************************************************************************* - // AppearancePreferences - //************************************************************************************************************* - WorkspacePreferences getWorkspacePreferences(); - //************************************************************************************************************* - // File preferences - //************************************************************************************************************* - AutoLinkPreferences getAutoLinkPreferences(); - //************************************************************************************************************* - // Import/Export preferences - //************************************************************************************************************* - ExportPreferences getExportPreferences(); List getCustomExportFormats(JournalAbbreviationRepository repository); @@ -177,28 +137,12 @@ public interface PreferencesService { GrobidPreferences getGrobidPreferences(); - //************************************************************************************************************* - // Preview preferences - //************************************************************************************************************* - PreviewPreferences getPreviewPreferences(); - //************************************************************************************************************* - // SidePanePreferences - //************************************************************************************************************* - SidePanePreferences getSidePanePreferences(); - //************************************************************************************************************* - // GuiPreferences - //************************************************************************************************************* - GuiPreferences getGuiPreferences(); - //************************************************************************************************************* - // Misc preferences - //************************************************************************************************************* - XmpPreferences getXmpPreferences(); NameFormatterPreferences getNameFormatterPreferences(); From 2213d4400316c45e94d9e0cfba60b0a499841f65 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 22 May 2023 17:04:59 +0200 Subject: [PATCH 02/11] Removed get-set-PreviewStyle, added javadoc, simplified tests --- .../migrations/PreferencesMigrations.java | 27 ++-- .../jabref/preferences/JabRefPreferences.java | 20 +-- .../migrations/PreferencesMigrationsTest.java | 127 ++---------------- 3 files changed, 33 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index 3bb54a1b3f7..9d88661ed15 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -52,14 +52,13 @@ public static void runMigrations(JabRefPreferences preferences) { upgradeStoredBibEntryTypes(preferences, mainPrefsNode); upgradeKeyBindingsToJavaFX(preferences); addCrossRefRelatedFieldsForAutoComplete(preferences); - upgradePreviewStyleFromReviewToComment(preferences); + upgradePreviewStyle(preferences); // changeColumnVariableNamesFor51 needs to be run before upgradeColumnPre50Preferences to ensure // backwardcompatibility, as it copies the old values to new variable names and keeps th old sored with the old // variable names. However, the variables from 5.0 need to be copied to the new variable name too. changeColumnVariableNamesFor51(preferences); upgradeColumnPreferences(preferences); restoreVariablesForBackwardCompatibility(preferences); - upgradePreviewStyleAllowMarkdown(preferences); upgradeCleanups(preferences); } @@ -310,21 +309,21 @@ private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences ol prefs.storeGlobalCitationKeyPattern(keyPattern); } - static void upgradePreviewStyleFromReviewToComment(JabRefPreferences prefs) { - String currentPreviewStyle = prefs.getPreviewStyle(); + /** + * Customizable preview style migrations + *
    + *
  • Since v5.0-alpha the custom preview layout shows the 'comment' field instead of the 'review' field (#4100).
  • + *
  • Since v5.1 a marker enables markdown in comments (#6232).
  • + *
  • Since v5.2 'bibtexkey' is rebranded as citationkey (#6875).
  • + *
+ */ + protected static void upgradePreviewStyle(JabRefPreferences prefs) { + String currentPreviewStyle = prefs.get(JabRefPreferences.PREVIEW_STYLE); String migratedStyle = currentPreviewStyle.replace("\\begin{review}

Review: \\format[HTMLChars]{\\review} \\end{review}", "\\begin{comment}

Comment: \\format[HTMLChars]{\\comment} \\end{comment}") + .replace("\\format[HTMLChars]{\\comment}", "\\format[Markdown,HTMLChars]{\\comment}") .replace("\\bibtextype\\begin{bibtexkey} (\\bibtexkey)", "\\bibtextype\\begin{citationkey} (\\citationkey)") .replace("\\end{bibtexkey}
__NEWLINE__", "\\end{citationkey}

__NEWLINE__"); - prefs.setPreviewStyle(migratedStyle); - } - - static void upgradePreviewStyleAllowMarkdown(JabRefPreferences prefs) { - String currentPreviewStyle = prefs.getPreviewStyle(); - String migratedStyle = currentPreviewStyle.replace("\\format[HTMLChars]{\\comment}", "\\format[Markdown,HTMLChars]{\\comment}") - .replace("\\bibtextype\\begin{bibtexkey} (\\bibtexkey)", "\\bibtextype\\begin{citationkey} (\\citationkey)") - .replace("\\end{bibtexkey}
__NEWLINE__", "\\end{citationkey}

__NEWLINE__"); - - prefs.setPreviewStyle(migratedStyle); + prefs.put(JabRefPreferences.PREVIEW_STYLE, migratedStyle); } /** diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 567013b5f30..1e55425e3f7 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -343,15 +343,15 @@ public class JabRefPreferences implements PreferencesService { // String delimiter public static final Character STRINGLIST_DELIMITER = ';'; + // Preview - public for pref migrations + public static final String PREVIEW_STYLE = "previewStyle"; + public static final String CYCLE_PREVIEW_POS = "cyclePreviewPos"; + public static final String CYCLE_PREVIEW = "cyclePreview"; + public static final String PREVIEW_AS_TAB = "previewAsTab"; + // UI private static final String FONT_FAMILY = "fontFamily"; - // Preview - private static final String PREVIEW_STYLE = "previewStyle"; - private static final String CYCLE_PREVIEW_POS = "cyclePreviewPos"; - private static final String CYCLE_PREVIEW = "cyclePreview"; - private static final String PREVIEW_AS_TAB = "previewAsTab"; - // Proxy private static final String PROXY_PORT = "proxyPort"; private static final String PROXY_HOSTNAME = "proxyHostname"; @@ -1149,14 +1149,6 @@ public void storeKeyBindingRepository(KeyBindingRepository keyBindingRepository) putStringList(BINDINGS, keyBindingRepository.getBindings()); } - public String getPreviewStyle() { - return get(PREVIEW_STYLE); - } - - public void setPreviewStyle(String previewStyle) { - put(PREVIEW_STYLE, previewStyle); - } - @Override public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { if (Objects.nonNull(journalAbbreviationPreferences)) { diff --git a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java index 03d6aa23fcf..099327a7518 100644 --- a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java +++ b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java @@ -69,123 +69,24 @@ void testArbitraryBibtexkeyPattern() { } @Test - void testPreviewStyle() { - String oldPreviewStyle = "" - + "\\bibtextype\\begin{bibtexkey} (\\bibtexkey)" - + "\\end{bibtexkey}
__NEWLINE__" - + "\\begin{author} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\author}
\\end{author}__NEWLINE__" - + "\\begin{editor} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\editor} " - + "(\\format[IfPlural(Eds.,Ed.)]{\\editor})
\\end{editor}__NEWLINE__" - + "\\begin{title} \\format[HTMLChars]{\\title} \\end{title}
__NEWLINE__" - + "\\begin{chapter} \\format[HTMLChars]{\\chapter}
\\end{chapter}__NEWLINE__" - + "\\begin{journal} \\format[HTMLChars]{\\journal}, \\end{journal}__NEWLINE__" - // Include the booktitle field for @inproceedings, @proceedings, etc. - + "\\begin{booktitle} \\format[HTMLChars]{\\booktitle}, \\end{booktitle}__NEWLINE__" - + "\\begin{school} \\format[HTMLChars]{\\school}, \\end{school}__NEWLINE__" - + "\\begin{institution} \\format[HTMLChars]{\\institution}, \\end{institution}__NEWLINE__" - + "\\begin{publisher} \\format[HTMLChars]{\\publisher}, \\end{publisher}__NEWLINE__" - + "\\begin{year}\\year\\end{year}\\begin{volume}, \\volume\\end{volume}" - + "\\begin{pages}, \\format[FormatPagesForHTML]{\\pages} \\end{pages}__NEWLINE__" - + "\\begin{abstract}

Abstract: \\format[HTMLChars]{\\abstract} \\end{abstract}__NEWLINE__" - + "\\begin{review}

Review: \\format[HTMLChars]{\\review} \\end{review}" - + "__NEWLINE__

"; - - String newPreviewStyle = "" - + "\\bibtextype\\begin{citationkey} (\\citationkey)" - + "\\end{citationkey}
__NEWLINE__" - + "\\begin{author} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\author}
\\end{author}__NEWLINE__" - + "\\begin{editor} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\editor} " - + "(\\format[IfPlural(Eds.,Ed.)]{\\editor})
\\end{editor}__NEWLINE__" - + "\\begin{title} \\format[HTMLChars]{\\title} \\end{title}
__NEWLINE__" - + "\\begin{chapter} \\format[HTMLChars]{\\chapter}
\\end{chapter}__NEWLINE__" - + "\\begin{journal} \\format[HTMLChars]{\\journal}, \\end{journal}__NEWLINE__" - // Include the booktitle field for @inproceedings, @proceedings, etc. - + "\\begin{booktitle} \\format[HTMLChars]{\\booktitle}, \\end{booktitle}__NEWLINE__" - + "\\begin{school} \\format[HTMLChars]{\\school}, \\end{school}__NEWLINE__" - + "\\begin{institution} \\format[HTMLChars]{\\institution}, \\end{institution}__NEWLINE__" - + "\\begin{publisher} \\format[HTMLChars]{\\publisher}, \\end{publisher}__NEWLINE__" - + "\\begin{year}\\year\\end{year}\\begin{volume}, \\volume\\end{volume}" - + "\\begin{pages}, \\format[FormatPagesForHTML]{\\pages} \\end{pages}__NEWLINE__" - + "\\begin{abstract}

Abstract: \\format[HTMLChars]{\\abstract} \\end{abstract}__NEWLINE__" - + "\\begin{comment}

Comment: \\format[HTMLChars]{\\comment} \\end{comment}" - + "__NEWLINE__

"; - - prefs.setPreviewStyle(oldPreviewStyle); - when(prefs.getPreviewStyle()).thenReturn(oldPreviewStyle); - - PreferencesMigrations.upgradePreviewStyleFromReviewToComment(prefs); - - verify(prefs).setPreviewStyle(newPreviewStyle); - } - - @Test - void upgradePreviewStyleAllowMarkupDefault() { - String oldPreviewStyle = "" - + "\\bibtextype\\begin{bibtexkey} (\\bibtexkey)" - + "\\end{bibtexkey}
__NEWLINE__" - + "\\begin{author} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\author}
\\end{author}__NEWLINE__" - + "\\begin{editor} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\editor} " - + "(\\format[IfPlural(Eds.,Ed.)]{\\editor})
\\end{editor}__NEWLINE__" - + "\\begin{title} \\format[HTMLChars]{\\title} \\end{title}
__NEWLINE__" - + "\\begin{chapter} \\format[HTMLChars]{\\chapter}
\\end{chapter}__NEWLINE__" - + "\\begin{journal} \\format[HTMLChars]{\\journal}, \\end{journal}__NEWLINE__" - // Include the booktitle field for @inproceedings, @proceedings, etc. - + "\\begin{booktitle} \\format[HTMLChars]{\\booktitle}, \\end{booktitle}__NEWLINE__" - + "\\begin{school} \\format[HTMLChars]{\\school}, \\end{school}__NEWLINE__" - + "\\begin{institution} \\format[HTMLChars]{\\institution}, \\end{institution}__NEWLINE__" - + "\\begin{publisher} \\format[HTMLChars]{\\publisher}, \\end{publisher}__NEWLINE__" - + "\\begin{year}\\year\\end{year}\\begin{volume}, \\volume\\end{volume}" - + "\\begin{pages}, \\format[FormatPagesForHTML]{\\pages} \\end{pages}__NEWLINE__" - + "\\begin{abstract}

Abstract: \\format[HTMLChars]{\\abstract} \\end{abstract}__NEWLINE__" - + "\\begin{comment}

Comment: \\format[HTMLChars]{\\comment} \\end{comment}" - + "__NEWLINE__

"; - - String newPreviewStyle = "" - + "\\bibtextype\\begin{citationkey} (\\citationkey)" - + "\\end{citationkey}
__NEWLINE__" - + "\\begin{author} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\author}
\\end{author}__NEWLINE__" - + "\\begin{editor} \\format[Authors(LastFirst,Initials,Semicolon,Amp),HTMLChars]{\\editor} " - + "(\\format[IfPlural(Eds.,Ed.)]{\\editor})
\\end{editor}__NEWLINE__" - + "\\begin{title} \\format[HTMLChars]{\\title} \\end{title}
__NEWLINE__" - + "\\begin{chapter} \\format[HTMLChars]{\\chapter}
\\end{chapter}__NEWLINE__" - + "\\begin{journal} \\format[HTMLChars]{\\journal}, \\end{journal}__NEWLINE__" - // Include the booktitle field for @inproceedings, @proceedings, etc. - + "\\begin{booktitle} \\format[HTMLChars]{\\booktitle}, \\end{booktitle}__NEWLINE__" - + "\\begin{school} \\format[HTMLChars]{\\school}, \\end{school}__NEWLINE__" - + "\\begin{institution} \\format[HTMLChars]{\\institution}, \\end{institution}__NEWLINE__" - + "\\begin{publisher} \\format[HTMLChars]{\\publisher}, \\end{publisher}__NEWLINE__" - + "\\begin{year}\\year\\end{year}\\begin{volume}, \\volume\\end{volume}" - + "\\begin{pages}, \\format[FormatPagesForHTML]{\\pages} \\end{pages}__NEWLINE__" - + "\\begin{abstract}

Abstract: \\format[HTMLChars]{\\abstract} \\end{abstract}__NEWLINE__" - + "\\begin{comment}

Comment: \\format[Markdown,HTMLChars]{\\comment} \\end{comment}" - + "__NEWLINE__

"; - - prefs.setPreviewStyle(oldPreviewStyle); - when(prefs.getPreviewStyle()).thenReturn(oldPreviewStyle); - - PreferencesMigrations.upgradePreviewStyleAllowMarkdown(prefs); - - verify(prefs).setPreviewStyle(newPreviewStyle); - } - - @Test - void upgradePreviewStyleAllowMarkupCustomized() { - String oldPreviewStyle = "" - + "My highly customized format only using comments:
" - + "\\begin{comment} Something: \\format[HTMLChars]{\\comment} special \\end{comment}" - + "__NEWLINE__

"; + void testPreviewStyleReviewToComment() { + String oldPreviewStyle = "__NEWLINE__" + + "Customized preview style using reviews and comments:__NEWLINE__" + + "\\begin{review}

Review: \\format[HTMLChars]{\\review} \\end{review}__NEWLINE__" + + "\\begin{comment} Something: \\format[HTMLChars]{\\comment} special \\end{comment}__NEWLINE__" + + "
__NEWLINE__"; - String newPreviewStyle = "" - + "My highly customized format only using comments:
" - + "\\begin{comment} Something: \\format[Markdown,HTMLChars]{\\comment} special \\end{comment}" - + "__NEWLINE__

"; + String newPreviewStyle = "__NEWLINE__" + + "Customized preview style using reviews and comments:__NEWLINE__" + + "\\begin{comment}

Comment: \\format[Markdown,HTMLChars]{\\comment} \\end{comment}__NEWLINE__" + + "\\begin{comment} Something: \\format[Markdown,HTMLChars]{\\comment} special \\end{comment}__NEWLINE__" + + "
__NEWLINE__"; - prefs.setPreviewStyle(oldPreviewStyle); - when(prefs.getPreviewStyle()).thenReturn(oldPreviewStyle); + when(prefs.get(JabRefPreferences.PREVIEW_STYLE)).thenReturn(oldPreviewStyle); - PreferencesMigrations.upgradePreviewStyleAllowMarkdown(prefs); + PreferencesMigrations.upgradePreviewStyle(prefs); - verify(prefs).setPreviewStyle(newPreviewStyle); + verify(prefs).put(JabRefPreferences.PREVIEW_STYLE, newPreviewStyle); } @Test From 65b08147f31e3913bca70a43c15ae5bdb11b4f75 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 22 May 2023 19:36:06 +0200 Subject: [PATCH 03/11] Moved entryNumber from ExporterFactory to NumberClass --- src/main/java/org/jabref/gui/preview/PreviewViewer.java | 4 ++-- .../java/org/jabref/logic/exporter/ExporterFactory.java | 7 ------- .../java/org/jabref/logic/exporter/TemplateExporter.java | 5 +++-- src/main/java/org/jabref/logic/layout/format/Number.java | 5 +++-- .../java/org/jabref/preferences/JabRefPreferences.java | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/preview/PreviewViewer.java b/src/main/java/org/jabref/gui/preview/PreviewViewer.java index 222478609e0..abec8fcab61 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewViewer.java +++ b/src/main/java/org/jabref/gui/preview/PreviewViewer.java @@ -23,8 +23,8 @@ import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.exporter.ExporterFactory; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.layout.format.Number; import org.jabref.logic.preview.PreviewLayout; import org.jabref.logic.search.SearchQuery; import org.jabref.logic.util.WebViewStore; @@ -249,7 +249,7 @@ private void update() { return; } - ExporterFactory.entryNumber = 1; // Set entry number in case that is included in the preview layout. + Number.serialExportNumber = 1; // Set entry number in case that is included in the preview layout. BackgroundTask .wrap(() -> layout.generatePreview(entry.get(), database)) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index e81316bf5dd..e24be4d6602 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -18,13 +18,6 @@ public class ExporterFactory { - /** - * Global variable that is used for counting output entries when exporting: - * - * @deprecated find a better way to do this - */ - @Deprecated public static int entryNumber; - private final List exporters; private ExporterFactory(List exporters) { diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index e33635cd3b6..923aedcf10e 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -19,6 +19,7 @@ import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.layout.LayoutHelper; +import org.jabref.logic.layout.format.Number; import org.jabref.logic.util.FileType; import org.jabref.logic.util.OS; import org.jabref.logic.util.StandardFileType; @@ -260,9 +261,9 @@ public void export(final BibDatabaseContext databaseContext, Map layouts = new HashMap<>(); Layout layout; - ExporterFactory.entryNumber = 0; + Number.serialExportNumber = 0; for (BibEntry entry : sorted) { - ExporterFactory.entryNumber++; // Increment entry counter. + Number.serialExportNumber++; // Increment entry counter. // Get the layout EntryType type = entry.getType(); if (layouts.containsKey(type)) { diff --git a/src/main/java/org/jabref/logic/layout/format/Number.java b/src/main/java/org/jabref/logic/layout/format/Number.java index e2daa7297f7..18e5415f27e 100644 --- a/src/main/java/org/jabref/logic/layout/format/Number.java +++ b/src/main/java/org/jabref/logic/layout/format/Number.java @@ -1,6 +1,5 @@ package org.jabref.logic.layout.format; -import org.jabref.logic.exporter.ExporterFactory; import org.jabref.logic.layout.ParamLayoutFormatter; /** @@ -9,6 +8,8 @@ */ public class Number implements ParamLayoutFormatter { + public static int serialExportNumber; + @Override public void setArgument(String arg) { // No effect currently. @@ -16,6 +17,6 @@ public void setArgument(String arg) { @Override public String format(String fieldText) { - return String.valueOf(ExporterFactory.entryNumber); + return String.valueOf(serialExportNumber); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 1e55425e3f7..336db303aed 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2784,7 +2784,7 @@ private Set getCustomImportFormats() { return importers; } - public void storeCustomImportFormats(Set importers) { + private void storeCustomImportFormats(Set importers) { purgeSeries(CUSTOM_IMPORT_FORMAT, 0); CustomImporter[] importersArray = importers.toArray(new CustomImporter[0]); for (int i = 0; i < importersArray.length; i++) { From 4beb2591f5ccd7498e02e507f48a55f5e90d0e9f Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Wed, 31 May 2023 15:42:31 +0200 Subject: [PATCH 04/11] Extracted JournalAbbreviationRepository from LayoutFormatterPreferences --- src/main/java/org/jabref/gui/JabRefFrame.java | 14 +- .../org/jabref/gui/edit/CopyMoreAction.java | 9 +- .../CreateModifyExporterDialogViewModel.java | 15 +- .../org/jabref/gui/maintable/MainTable.java | 1 + .../jabref/gui/maintable/RightClickMenu.java | 25 +-- .../gui/openoffice/OpenOfficePanel.java | 10 +- .../gui/preview/CopyCitationAction.java | 23 ++- .../org/jabref/gui/sidepane/SidePane.java | 4 +- .../gui/sidepane/SidePaneContentFactory.java | 6 +- .../gui/sidepane/SidePaneViewModel.java | 3 + .../logic/exporter/ExporterFactory.java | 38 ++-- .../logic/exporter/TemplateExporter.java | 26 ++- .../java/org/jabref/logic/layout/Layout.java | 11 +- .../org/jabref/logic/layout/LayoutEntry.java | 43 +++-- .../layout/LayoutFormatterPreferences.java | 14 +- .../org/jabref/logic/layout/LayoutHelper.java | 17 +- .../logic/layout/TextBasedPreviewLayout.java | 9 +- .../logic/openoffice/style/OOBibStyle.java | 21 ++- .../logic/openoffice/style/StyleLoader.java | 13 +- .../jabref/preferences/JabRefPreferences.java | 12 +- .../preferences/PreferencesService.java | 2 +- .../jabref/gui/edit/CopyMoreActionTest.java | 37 ++-- .../gui/sidepane/SidePaneViewModelTest.java | 4 +- .../logic/exporter/CsvExportFormatTest.java | 20 +- .../logic/exporter/DocBook5ExporterTest.java | 2 + .../logic/exporter/DocbookExporterTest.java | 2 + .../jabref/logic/exporter/ExporterTest.java | 2 + .../logic/exporter/HtmlExportFormatTest.java | 2 + .../OpenOfficeDocumentCreatorTest.java | 2 + .../logic/exporter/YamlExporterTest.java | 2 + .../jabref/logic/layout/LayoutEntryTest.java | 3 +- .../jabref/logic/layout/LayoutHelperTest.java | 14 +- .../org/jabref/logic/layout/LayoutTest.java | 6 +- .../openoffice/style/OOBibStyleTest.java | 171 ++++++++++++------ .../openoffice/style/StyleLoaderTest.java | 38 ++-- 35 files changed, 382 insertions(+), 239 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 0b1d1065aa0..1d25f22bcd2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -643,7 +643,7 @@ public void showLibraryTab(LibraryTab libraryTab) { } public void init() { - sidePane = new SidePane(prefs, taskExecutor, dialogService, stateManager, undoManager); + sidePane = new SidePane(prefs, Globals.journalAbbreviationRepository, taskExecutor, dialogService, stateManager, undoManager); tabbedPane = new TabPane(); tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); @@ -808,12 +808,12 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, this, stateManager)), factory.createSubMenu(StandardActions.COPY_MORE, - factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, Globals.getClipboardManager(), prefs)), - factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, Globals.getClipboardManager(), prefs)), - factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, Globals.getClipboardManager(), prefs)), - factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, Globals.getClipboardManager(), prefs)), - factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, Globals.getClipboardManager(), prefs)), - factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, Globals.getClipboardManager(), Globals.TASK_EXECUTOR, prefs.getPreviewPreferences())), + factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, Globals.getClipboardManager(), prefs, Globals.journalAbbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, Globals.getClipboardManager(), prefs, Globals.journalAbbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, Globals.getClipboardManager(), prefs, Globals.journalAbbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, Globals.getClipboardManager(), prefs, Globals.journalAbbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, Globals.getClipboardManager(), prefs, Globals.journalAbbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, Globals.getClipboardManager(), Globals.TASK_EXECUTOR, prefs, Globals.journalAbbreviationRepository)), factory.createMenuItem(StandardActions.EXPORT_SELECTED_TO_CLIPBOARD, new ExportToClipboardAction(dialogService, stateManager, Globals.getClipboardManager(), Globals.TASK_EXECUTOR, prefs))), factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, this, stateManager)), diff --git a/src/main/java/org/jabref/gui/edit/CopyMoreAction.java b/src/main/java/org/jabref/gui/edit/CopyMoreAction.java index 2da415b3485..0f9bbe3c103 100644 --- a/src/main/java/org/jabref/gui/edit/CopyMoreAction.java +++ b/src/main/java/org/jabref/gui/edit/CopyMoreAction.java @@ -8,12 +8,12 @@ import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.JabRefDialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.StandardActions; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutHelper; @@ -33,17 +33,20 @@ public class CopyMoreAction extends SimpleCommand { private final StateManager stateManager; private final ClipBoardManager clipBoardManager; private final PreferencesService preferencesService; + private final JournalAbbreviationRepository abbreviationRepository; public CopyMoreAction(StandardActions action, DialogService dialogService, StateManager stateManager, ClipBoardManager clipBoardManager, - PreferencesService preferencesService) { + PreferencesService preferencesService, + JournalAbbreviationRepository abbreviationRepository) { this.action = action; this.dialogService = dialogService; this.stateManager = stateManager; this.clipBoardManager = clipBoardManager; this.preferencesService = preferencesService; + this.abbreviationRepository = abbreviationRepository; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -192,7 +195,7 @@ private void copyKeyAndTitle() { StringReader layoutString = new StringReader("\\citationkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); Layout layout; try { - layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)).getLayoutFromText(); + layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(), abbreviationRepository).getLayoutFromText(); } catch (IOException e) { LOGGER.info("Could not get layout.", e); return; diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 2fae491983f..9be5afe75f7 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -8,11 +8,9 @@ import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; import org.jabref.gui.util.FileDialogConfiguration; -import org.jabref.logic.exporter.SaveConfiguration; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.util.StandardFileType; import org.jabref.preferences.PreferencesService; @@ -37,15 +35,15 @@ public class CreateModifyExporterDialogViewModel extends AbstractViewModel { private final StringProperty layoutFile = new SimpleStringProperty(""); private final StringProperty extension = new SimpleStringProperty(""); - private final JournalAbbreviationRepository repository; + private final JournalAbbreviationRepository abbreviationRepository; public CreateModifyExporterDialogViewModel(ExporterViewModel exporter, DialogService dialogService, PreferencesService preferences, - JournalAbbreviationRepository repository) { + JournalAbbreviationRepository abbreviationRepository) { this.dialogService = dialogService; this.preferences = preferences; - this.repository = repository; + this.abbreviationRepository = abbreviationRepository; // Set text of each of the boxes if (exporter != null) { @@ -69,14 +67,13 @@ public ExporterViewModel saveExporter() { } // Create a new exporter to be returned to ExportCustomizationDialogViewModel, which requested it - LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(repository); - SaveConfiguration saveConfiguration = preferences.getExportConfiguration(); TemplateExporter format = new TemplateExporter( name.get(), layoutFile.get(), extension.get(), - layoutPreferences, - saveConfiguration); + preferences.getLayoutFormatterPreferences(), + abbreviationRepository, + preferences.getExportConfiguration()); format.setCustomExport(true); return new ExporterViewModel(format); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 94585b1742e..05f18f3a6b9 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -133,6 +133,7 @@ public MainTable(MainTableDataModel model, undoManager, clipBoardManager, Globals.TASK_EXECUTOR, + Globals.journalAbbreviationRepository, Globals.entryTypesManager)) .setOnDragDetected(this::handleOnDragDetected) .setOnDragDropped(this::handleOnDragDropped) diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index 31409e0ffc0..bef588657e5 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -27,6 +27,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; import org.jabref.logic.citationstyle.CitationStylePreviewLayout; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.SpecialField; import org.jabref.preferences.PreferencesService; @@ -43,13 +44,14 @@ public static ContextMenu create(BibEntryTableViewModel entry, UndoManager undoManager, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor, + JournalAbbreviationRepository abbreviationRepository, BibEntryTypesManager entryTypesManager) { ActionFactory factory = new ActionFactory(keyBindingRepository); ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().addAll( factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, libraryTab.frame(), stateManager)), - createCopySubMenu(factory, dialogService, stateManager, preferencesService, clipBoardManager, taskExecutor), + createCopySubMenu(factory, dialogService, stateManager, preferencesService, clipBoardManager, abbreviationRepository, taskExecutor), factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager)), factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager)), factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, preferencesService.getBibEntryPreferences())), @@ -92,17 +94,18 @@ private static Menu createCopySubMenu(ActionFactory factory, StateManager stateManager, PreferencesService preferencesService, ClipBoardManager clipBoardManager, + JournalAbbreviationRepository abbreviationRepository, TaskExecutor taskExecutor) { Menu copySpecialMenu = factory.createMenu(StandardActions.COPY_MORE); copySpecialMenu.getItems().addAll( - factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_DOI, new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService)), - factory.createMenuItem(StandardActions.COPY_DOI_URL, new CopyMoreAction(StandardActions.COPY_DOI_URL, dialogService, stateManager, clipBoardManager, preferencesService)), + factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_DOI, new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_DOI_URL, new CopyMoreAction(StandardActions.COPY_DOI_URL, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository)), new SeparatorMenuItem() ); @@ -110,10 +113,10 @@ private static Menu createCopySubMenu(ActionFactory factory, PreviewPreferences previewPreferences = preferencesService.getPreviewPreferences(); if (previewPreferences.getSelectedPreviewLayout() instanceof CitationStylePreviewLayout) { copySpecialMenu.getItems().addAll( - factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)), - factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); + factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, preferencesService, abbreviationRepository)), + factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, preferencesService, abbreviationRepository))); } else { - copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences))); + copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, preferencesService, abbreviationRepository))); } copySpecialMenu.getItems().addAll( diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index a0b3e7344ee..a8b06a0b700 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -27,7 +27,6 @@ import javafx.scene.layout.VBox; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.JabRefGUI; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; @@ -43,6 +42,7 @@ import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; import org.jabref.logic.help.HelpFile; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.openoffice.OpenOfficeFileSearch; import org.jabref.logic.openoffice.OpenOfficePreferences; @@ -94,8 +94,8 @@ public class OpenOfficePanel { private OOBibStyle style; public OpenOfficePanel(PreferencesService preferencesService, - OpenOfficePreferences openOfficePreferences, KeyBindingRepository keyBindingRepository, + JournalAbbreviationRepository abbreviationRepository, TaskExecutor taskExecutor, DialogService dialogService, StateManager stateManager, @@ -130,8 +130,10 @@ public OpenOfficePanel(PreferencesService preferencesService, update.setTooltip(new Tooltip(Localization.lang("Sync OpenOffice/LibreOffice bibliography"))); update.setMaxWidth(Double.MAX_VALUE); - loader = new StyleLoader(openOfficePreferences, - preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)); + loader = new StyleLoader( + preferencesService.getOpenOfficePreferences(), + preferencesService.getLayoutFormatterPreferences(), + abbreviationRepository); initPanel(); } diff --git a/src/main/java/org/jabref/gui/preview/CopyCitationAction.java b/src/main/java/org/jabref/gui/preview/CopyCitationAction.java index 453e81b3d9e..164eec87b57 100644 --- a/src/main/java/org/jabref/gui/preview/CopyCitationAction.java +++ b/src/main/java/org/jabref/gui/preview/CopyCitationAction.java @@ -19,15 +19,15 @@ import org.jabref.logic.citationstyle.CitationStyleGenerator; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; import org.jabref.logic.citationstyle.CitationStylePreviewLayout; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.Layout; -import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.layout.LayoutHelper; import org.jabref.logic.layout.TextBasedPreviewLayout; import org.jabref.logic.preview.PreviewLayout; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.PreviewPreferences; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,29 +40,30 @@ public class CopyCitationAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(CopyCitationAction.class); private final List selectedEntries; - private final PreviewLayout previewLayout; - private final TextBasedPreviewLayout customPreviewLayout; private final CitationStyleOutputFormat outputFormat; private final StateManager stateManager; private final DialogService dialogService; private final ClipBoardManager clipBoardManager; private final TaskExecutor taskExecutor; + private final PreferencesService preferencesService; + private final JournalAbbreviationRepository abbreviationRepository; public CopyCitationAction(CitationStyleOutputFormat outputFormat, DialogService dialogService, StateManager stateManager, ClipBoardManager clipBoardManager, TaskExecutor taskExecutor, - PreviewPreferences previewPreferences) { + PreferencesService preferencesService, + JournalAbbreviationRepository abbreviationRepository) { this.outputFormat = outputFormat; this.dialogService = dialogService; this.stateManager = stateManager; this.selectedEntries = stateManager.getSelectedEntries(); this.clipBoardManager = clipBoardManager; this.taskExecutor = taskExecutor; - this.previewLayout = previewPreferences.getSelectedPreviewLayout(); - this.customPreviewLayout = previewPreferences.getCustomPreviewLayout(); + this.preferencesService = preferencesService; + this.abbreviationRepository = abbreviationRepository; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -79,6 +80,7 @@ private List generateCitations() throws IOException { // This worker stored the style as filename. The CSLAdapter and the CitationStyleCache store the source of the // style. Therefore, we extract the style source from the file. String styleSource = null; + PreviewLayout previewLayout = preferencesService.getPreviewPreferences().getSelectedPreviewLayout(); if (previewLayout instanceof CitationStylePreviewLayout citationStyleLayout) { styleSource = citationStyleLayout.getSource(); @@ -96,9 +98,10 @@ private List generateTextBasedPreviewLayoutCitations() throws IOExceptio return Collections.emptyList(); } + TextBasedPreviewLayout customPreviewLayout = preferencesService.getPreviewPreferences().getCustomPreviewLayout(); StringReader customLayoutReader = new StringReader(customPreviewLayout.getText().replace("__NEWLINE__", "\n")); - LayoutFormatterPreferences layoutFormatterPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); - Layout layout = new LayoutHelper(customLayoutReader, layoutFormatterPreferences).getLayoutFromText(); + Layout layout = new LayoutHelper(customLayoutReader, preferencesService.getLayoutFormatterPreferences(), abbreviationRepository) + .getLayoutFromText(); List citations = new ArrayList<>(selectedEntries.size()); for (BibEntry entry : selectedEntries) { @@ -149,6 +152,8 @@ protected static ClipboardContent processHtml(List citations) { } private void setClipBoardContent(List citations) { + PreviewLayout previewLayout = preferencesService.getPreviewPreferences().getSelectedPreviewLayout(); + // if it's not a citation style take care of the preview if (!(previewLayout instanceof CitationStylePreviewLayout)) { clipBoardManager.setContent(processPreview(citations)); diff --git a/src/main/java/org/jabref/gui/sidepane/SidePane.java b/src/main/java/org/jabref/gui/sidepane/SidePane.java index 7edd177786e..f9eb7e89631 100644 --- a/src/main/java/org/jabref/gui/sidepane/SidePane.java +++ b/src/main/java/org/jabref/gui/sidepane/SidePane.java @@ -14,6 +14,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; public class SidePane extends VBox { @@ -26,13 +27,14 @@ public class SidePane extends VBox { private final Map visibleBindings = new HashMap<>(); public SidePane(PreferencesService preferencesService, + JournalAbbreviationRepository abbreviationRepository, TaskExecutor taskExecutor, DialogService dialogService, StateManager stateManager, UndoManager undoManager) { this.stateManager = stateManager; this.preferencesService = preferencesService; - this.viewModel = new SidePaneViewModel(preferencesService, stateManager, taskExecutor, dialogService, undoManager); + this.viewModel = new SidePaneViewModel(preferencesService, abbreviationRepository, stateManager, taskExecutor, dialogService, undoManager); stateManager.getVisibleSidePaneComponents().addListener((ListChangeListener) c -> updateView()); updateView(); diff --git a/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java b/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java index f3da681a510..7fe1f43fcc5 100644 --- a/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java +++ b/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java @@ -10,21 +10,25 @@ import org.jabref.gui.importer.fetcher.WebSearchPaneView; import org.jabref.gui.openoffice.OpenOfficePanel; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; public class SidePaneContentFactory { private final PreferencesService preferences; + private final JournalAbbreviationRepository abbreviationRepository; private final TaskExecutor taskExecutor; private final DialogService dialogService; private final StateManager stateManager; private final UndoManager undoManager; public SidePaneContentFactory(PreferencesService preferences, + JournalAbbreviationRepository abbreviationRepository, TaskExecutor taskExecutor, DialogService dialogService, StateManager stateManager, UndoManager undoManager) { this.preferences = preferences; + this.abbreviationRepository = abbreviationRepository; this.taskExecutor = taskExecutor; this.dialogService = dialogService; this.stateManager = stateManager; @@ -40,8 +44,8 @@ public Node create(SidePaneType sidePaneType) { dialogService); case OPEN_OFFICE -> new OpenOfficePanel( preferences, - preferences.getOpenOfficePreferences(), preferences.getKeyBindingRepository(), + abbreviationRepository, taskExecutor, dialogService, stateManager, diff --git a/src/main/java/org/jabref/gui/sidepane/SidePaneViewModel.java b/src/main/java/org/jabref/gui/sidepane/SidePaneViewModel.java index 03a72d7c073..e27d5c22d08 100644 --- a/src/main/java/org/jabref/gui/sidepane/SidePaneViewModel.java +++ b/src/main/java/org/jabref/gui/sidepane/SidePaneViewModel.java @@ -18,6 +18,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; import org.jabref.preferences.SidePanePreferences; @@ -35,6 +36,7 @@ public class SidePaneViewModel extends AbstractViewModel { private final DialogService dialogService; public SidePaneViewModel(PreferencesService preferencesService, + JournalAbbreviationRepository abbreviationRepository, StateManager stateManager, TaskExecutor taskExecutor, DialogService dialogService, @@ -44,6 +46,7 @@ public SidePaneViewModel(PreferencesService preferencesService, this.dialogService = dialogService; this.sidePaneContentFactory = new SidePaneContentFactory( preferencesService, + abbreviationRepository, taskExecutor, dialogService, stateManager, diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index e24be4d6602..4bc0b982dd3 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -29,7 +29,8 @@ public static ExporterFactory create(PreferencesService preferencesService, JournalAbbreviationRepository abbreviationRepository) { return ExporterFactory.create( preferencesService.getCustomExportFormats(abbreviationRepository), - preferencesService.getLayoutFormatterPreferences(abbreviationRepository), + preferencesService.getLayoutFormatterPreferences(), + abbreviationRepository, preferencesService.getExportConfiguration(), preferencesService.getXmpPreferences(), preferencesService.getFieldPreferences(), @@ -39,6 +40,7 @@ public static ExporterFactory create(PreferencesService preferencesService, public static ExporterFactory create(List customFormats, LayoutFormatterPreferences layoutPreferences, + JournalAbbreviationRepository abbreviationRepository, SaveConfiguration saveConfiguration, XmpPreferences xmpPreferences, FieldPreferences fieldPreferences, @@ -48,23 +50,23 @@ public static ExporterFactory create(List customFormats, List exporters = new ArrayList<>(); // Initialize build-in exporters - exporters.add(new TemplateExporter("HTML", "html", "html", null, StandardFileType.HTML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, StandardFileType.HTML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("DocBook 5.1", "docbook5", "docbook5", null, StandardFileType.XML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("DocBook 4", "docbook4", "docbook4", null, StandardFileType.XML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("DIN 1505", "din1505", "din1505winword", "din1505", StandardFileType.RTF, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("BibO RDF", "bibordf", "bibordf", null, StandardFileType.RDF, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", StandardFileType.HTML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", StandardFileType.HTML, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("Harvard RTF", "harvard", "harvard", "harvard", StandardFileType.RTF, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", StandardFileType.RTF, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("ISO 690", "iso690txt", "iso690", "iso690txt", StandardFileType.TXT, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("Endnote", "endnote", "EndNote", "endnote", StandardFileType.TXT, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", "openoffice", StandardFileType.CSV, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("RIS", "ris", "ris", "ris", StandardFileType.RIS, layoutPreferences, saveConfiguration, BlankLineBehaviour.DELETE_BLANKS)); - exporters.add(new TemplateExporter("MIS Quarterly", "misq", "misq", "misq", StandardFileType.RTF, layoutPreferences, saveConfiguration)); - exporters.add(new TemplateExporter("CSL YAML", "yaml", "yaml", null, StandardFileType.YAML, layoutPreferences, saveConfiguration, BlankLineBehaviour.DELETE_BLANKS)); + exporters.add(new TemplateExporter("HTML", "html", "html", null, StandardFileType.HTML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, StandardFileType.HTML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("DocBook 5.1", "docbook5", "docbook5", null, StandardFileType.XML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("DocBook 4", "docbook4", "docbook4", null, StandardFileType.XML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("DIN 1505", "din1505", "din1505winword", "din1505", StandardFileType.RTF, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("BibO RDF", "bibordf", "bibordf", null, StandardFileType.RDF, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", StandardFileType.HTML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", StandardFileType.HTML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", StandardFileType.HTML, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("Harvard RTF", "harvard", "harvard", "harvard", StandardFileType.RTF, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", StandardFileType.RTF, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("ISO 690", "iso690txt", "iso690", "iso690txt", StandardFileType.TXT, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("Endnote", "endnote", "EndNote", "endnote", StandardFileType.TXT, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", "openoffice", StandardFileType.CSV, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("RIS", "ris", "ris", "ris", StandardFileType.RIS, layoutPreferences, abbreviationRepository, saveConfiguration, BlankLineBehaviour.DELETE_BLANKS)); + exporters.add(new TemplateExporter("MIS Quarterly", "misq", "misq", "misq", StandardFileType.RTF, layoutPreferences, abbreviationRepository, saveConfiguration)); + exporters.add(new TemplateExporter("CSL YAML", "yaml", "yaml", null, StandardFileType.YAML, layoutPreferences, abbreviationRepository, saveConfiguration, BlankLineBehaviour.DELETE_BLANKS)); exporters.add(new OpenOfficeDocumentCreator()); exporters.add(new OpenDocumentSpreadsheetCreator()); exporters.add(new MSBibExporter()); diff --git a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java index 923aedcf10e..0a9ee6668b3 100644 --- a/src/main/java/org/jabref/logic/exporter/TemplateExporter.java +++ b/src/main/java/org/jabref/logic/exporter/TemplateExporter.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.Objects; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.layout.LayoutHelper; @@ -47,6 +48,7 @@ public class TemplateExporter extends Exporter { private final String lfFileName; private final String directory; private final LayoutFormatterPreferences layoutPreferences; + private final JournalAbbreviationRepository abbreviationRepository; private final SaveConfiguration saveConfiguration; private boolean customExport; private BlankLineBehaviour blankLineBehaviour; @@ -65,7 +67,7 @@ public TemplateExporter(String displayName, String lfFileName, String directory, FileType extension) { - this(displayName, consoleName, lfFileName, directory, extension, null, null); + this(displayName, consoleName, lfFileName, directory, extension, null, null, null); } /** @@ -81,8 +83,16 @@ public TemplateExporter(String name, String lfFileName, String extension, LayoutFormatterPreferences layoutPreferences, + JournalAbbreviationRepository abbreviationRepository, SaveConfiguration saveConfiguration) { - this(name, name, lfFileName, null, StandardFileType.fromExtensions(extension), layoutPreferences, saveConfiguration); + this(name, + name, + lfFileName, + null, + StandardFileType.fromExtensions(extension), + layoutPreferences, + abbreviationRepository, + saveConfiguration); } /** @@ -102,6 +112,7 @@ public TemplateExporter(String displayName, String directory, FileType extension, LayoutFormatterPreferences layoutPreferences, + JournalAbbreviationRepository abbreviationRepository, SaveConfiguration saveConfiguration) { super(consoleName, displayName, extension); if (Objects.requireNonNull(lfFileName).endsWith(LAYOUT_EXTENSION)) { @@ -111,6 +122,7 @@ public TemplateExporter(String displayName, } this.directory = directory; this.layoutPreferences = layoutPreferences; + this.abbreviationRepository = abbreviationRepository; this.saveConfiguration = saveConfiguration; } @@ -132,6 +144,7 @@ public TemplateExporter(String displayName, String directory, FileType extension, LayoutFormatterPreferences layoutPreferences, + JournalAbbreviationRepository abbreviationRepository, SaveConfiguration saveConfiguration, BlankLineBehaviour blankLineBehaviour) { super(consoleName, displayName, extension); @@ -142,6 +155,7 @@ public TemplateExporter(String displayName, } this.directory = directory; this.layoutPreferences = layoutPreferences; + this.abbreviationRepository = abbreviationRepository; this.saveConfiguration = saveConfiguration; this.blankLineBehaviour = blankLineBehaviour; } @@ -224,7 +238,7 @@ public void export(final BibDatabaseContext databaseContext, // Print header try (Reader reader = getReader(lfFileName + BEGIN_INFIX + LAYOUT_EXTENSION)) { - LayoutHelper layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences); + LayoutHelper layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences, abbreviationRepository); beginLayout = layoutHelper.getLayoutFromText(); } catch (IOException ex) { // If an exception was cast, export filter doesn't have a begin @@ -249,7 +263,7 @@ public void export(final BibDatabaseContext databaseContext, Layout defLayout; LayoutHelper layoutHelper; try (Reader reader = getReader(lfFileName + LAYOUT_EXTENSION)) { - layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences); + layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences, abbreviationRepository); defLayout = layoutHelper.getLayoutFromText(); } if (defLayout != null) { @@ -271,7 +285,7 @@ public void export(final BibDatabaseContext databaseContext, } else { try (Reader reader = getReader(lfFileName + '.' + type.getName() + LAYOUT_EXTENSION)) { // We try to get a type-specific layout for this entry. - layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences); + layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences, abbreviationRepository); layout = layoutHelper.getLayoutFromText(); layouts.put(type, layout); if (layout != null) { @@ -303,7 +317,7 @@ public void export(final BibDatabaseContext databaseContext, // Print footer Layout endLayout = null; try (Reader reader = getReader(lfFileName + END_INFIX + LAYOUT_EXTENSION)) { - layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences); + layoutHelper = new LayoutHelper(reader, fileDirForDatabase, layoutPreferences, abbreviationRepository); endLayout = layoutHelper.getLayoutFromText(); } catch (IOException ex) { // If an exception was thrown, export filter doesn't have an end diff --git a/src/main/java/org/jabref/logic/layout/Layout.java b/src/main/java/org/jabref/logic/layout/Layout.java index ea566fbe510..a465d578fd0 100644 --- a/src/main/java/org/jabref/logic/layout/Layout.java +++ b/src/main/java/org/jabref/logic/layout/Layout.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -21,7 +22,10 @@ public class Layout { private final List missingFormatters = new ArrayList<>(); - public Layout(List parsedEntries, List fileDirForDatabase, LayoutFormatterPreferences prefs) { + public Layout(List parsedEntries, + List fileDirForDatabase, + LayoutFormatterPreferences layoutPreferences, + JournalAbbreviationRepository abbreviationRepository) { List tmpEntries = new ArrayList<>(parsedEntries.size()); List blockEntries = null; @@ -48,7 +52,8 @@ public Layout(List parsedEntries, List fileDirForDatabase, Layo le = new LayoutEntry(blockEntries, parsedEntry.i == LayoutHelper.IS_FIELD_END ? LayoutHelper.IS_FIELD_START : LayoutHelper.IS_GROUP_START, fileDirForDatabase, - prefs); + layoutPreferences, + abbreviationRepository); tmpEntries.add(le); blockEntries = null; } else { @@ -63,7 +68,7 @@ public Layout(List parsedEntries, List fileDirForDatabase, Layo } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, fileDirForDatabase, prefs)); + tmpEntries.add(new LayoutEntry(parsedEntry, fileDirForDatabase, layoutPreferences, abbreviationRepository)); } else { blockEntries.add(parsedEntry); } diff --git a/src/main/java/org/jabref/logic/layout/LayoutEntry.java b/src/main/java/org/jabref/logic/layout/LayoutEntry.java index 254d2ef2d7e..cafd87dc8bc 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/org/jabref/logic/layout/LayoutEntry.java @@ -12,6 +12,7 @@ import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.format.AuthorAbbreviator; import org.jabref.logic.layout.format.AuthorAndToSemicolonReplacer; import org.jabref.logic.layout.format.AuthorAndsCommaReplacer; @@ -108,31 +109,37 @@ class LayoutEntry { private final List fileDirForDatabase; private final LayoutFormatterPreferences preferences; + private final JournalAbbreviationRepository abbreviationRepository; - public LayoutEntry(StringInt si, List fileDirForDatabase, LayoutFormatterPreferences preferences) { + public LayoutEntry(StringInt si, + List fileDirForDatabase, + LayoutFormatterPreferences preferences, + JournalAbbreviationRepository abbreviationRepository) { this.preferences = preferences; + this.abbreviationRepository = abbreviationRepository; this.fileDirForDatabase = Objects.requireNonNullElse(fileDirForDatabase, Collections.emptyList()); type = si.i; switch (type) { - case LayoutHelper.IS_LAYOUT_TEXT: - text = si.s; - break; - case LayoutHelper.IS_SIMPLE_COMMAND: - text = si.s.trim(); - break; - case LayoutHelper.IS_OPTION_FIELD: - doOptionField(si.s); - break; - case LayoutHelper.IS_FIELD_START: - case LayoutHelper.IS_FIELD_END: - default: - break; + case LayoutHelper.IS_LAYOUT_TEXT -> + text = si.s; + case LayoutHelper.IS_SIMPLE_COMMAND -> + text = si.s.trim(); + case LayoutHelper.IS_OPTION_FIELD -> + doOptionField(si.s); + default -> { + // IS_FIELD_START and IS_FIELD_END + } } } - public LayoutEntry(List parsedEntries, int layoutType, List fileDirForDatabase, LayoutFormatterPreferences preferences) { + public LayoutEntry(List parsedEntries, + int layoutType, + List fileDirForDatabase, + LayoutFormatterPreferences preferences, + JournalAbbreviationRepository abbreviationRepository) { this.preferences = preferences; + this.abbreviationRepository = abbreviationRepository; this.fileDirForDatabase = Objects.requireNonNullElse(fileDirForDatabase, Collections.emptyList()); List tmpEntries = new ArrayList<>(); @@ -159,7 +166,7 @@ public LayoutEntry(List parsedEntries, int layoutType, List fil blockEntries.add(parsedEntry); int groupType = parsedEntry.i == LayoutHelper.IS_GROUP_END ? LayoutHelper.IS_GROUP_START : LayoutHelper.IS_FIELD_START; - LayoutEntry le = new LayoutEntry(blockEntries, groupType, fileDirForDatabase, preferences); + LayoutEntry le = new LayoutEntry(blockEntries, groupType, fileDirForDatabase, preferences, abbreviationRepository); tmpEntries.add(le); blockEntries = null; } else { @@ -175,7 +182,7 @@ public LayoutEntry(List parsedEntries, int layoutType, List fil } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, fileDirForDatabase, preferences)); + tmpEntries.add(new LayoutEntry(parsedEntry, fileDirForDatabase, preferences, abbreviationRepository)); } else { blockEntries.add(parsedEntry); } @@ -446,7 +453,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) { case "HTMLParagraphs" -> new HTMLParagraphs(); case "Iso690FormatDate" -> new Iso690FormatDate(); case "Iso690NamesAuthors" -> new Iso690NamesAuthors(); - case "JournalAbbreviator" -> new JournalAbbreviator(preferences.getJournalAbbreviationRepository()); + case "JournalAbbreviator" -> new JournalAbbreviator(abbreviationRepository); case "LastPage" -> new LastPage(); // For backward compatibility case "FormatChars", "LatexToUnicode" -> new LatexToUnicodeFormatter(); diff --git a/src/main/java/org/jabref/logic/layout/LayoutFormatterPreferences.java b/src/main/java/org/jabref/logic/layout/LayoutFormatterPreferences.java index 64c8e438117..b2177cbd543 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutFormatterPreferences.java +++ b/src/main/java/org/jabref/logic/layout/LayoutFormatterPreferences.java @@ -6,7 +6,6 @@ import javafx.beans.property.StringProperty; -import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.format.NameFormatterPreferences; public class LayoutFormatterPreferences { @@ -14,14 +13,11 @@ public class LayoutFormatterPreferences { private final NameFormatterPreferences nameFormatterPreferences; private final StringProperty mainFileDirectoryProperty; private final Map customExportNameFormatters = new HashMap<>(); - private final JournalAbbreviationRepository journalAbbreviationRepository; public LayoutFormatterPreferences(NameFormatterPreferences nameFormatterPreferences, - StringProperty mainFileDirectoryProperty, - JournalAbbreviationRepository journalAbbreviationRepository) { + StringProperty mainFileDirectoryProperty) { this.nameFormatterPreferences = nameFormatterPreferences; this.mainFileDirectoryProperty = mainFileDirectoryProperty; - this.journalAbbreviationRepository = journalAbbreviationRepository; } public NameFormatterPreferences getNameFormatterPreferences() { @@ -32,8 +28,8 @@ public String getMainFileDirectory() { return mainFileDirectoryProperty.get(); } - public JournalAbbreviationRepository getJournalAbbreviationRepository() { - return journalAbbreviationRepository; + public Optional getCustomExportNameFormatter(String formatterName) { + return Optional.ofNullable(customExportNameFormatters.get(formatterName)); } public void clearCustomExportNameFormatters() { @@ -43,8 +39,4 @@ public void clearCustomExportNameFormatters() { public void putCustomExportNameFormatter(String formatterName, String contents) { customExportNameFormatters.put(formatterName, contents); } - - public Optional getCustomExportNameFormatter(String formatterName) { - return Optional.ofNullable(customExportNameFormatters.get(formatterName)); - } } diff --git a/src/main/java/org/jabref/logic/layout/LayoutHelper.java b/src/main/java/org/jabref/logic/layout/LayoutHelper.java index 69aafdd1dcf..0a01c49dac5 100644 --- a/src/main/java/org/jabref/logic/layout/LayoutHelper.java +++ b/src/main/java/org/jabref/logic/layout/LayoutHelper.java @@ -10,6 +10,8 @@ import java.util.Locale; import java.util.Objects; +import org.jabref.logic.journals.JournalAbbreviationRepository; + /** * Helper class to get a Layout object. * @@ -39,16 +41,23 @@ public class LayoutHelper { private final List parsedEntries = new ArrayList<>(); private final List fileDirForDatabase; private final LayoutFormatterPreferences preferences; + private final JournalAbbreviationRepository abbreviationRepository; private boolean endOfFile; - public LayoutHelper(Reader in, List fileDirForDatabase, LayoutFormatterPreferences preferences) { + public LayoutHelper(Reader in, + List fileDirForDatabase, + LayoutFormatterPreferences preferences, + JournalAbbreviationRepository abbreviationRepository) { this.in = new PushbackReader(Objects.requireNonNull(in)); this.preferences = Objects.requireNonNull(preferences); + this.abbreviationRepository = abbreviationRepository; this.fileDirForDatabase = fileDirForDatabase; } - public LayoutHelper(Reader in, LayoutFormatterPreferences preferences) { - this(in, Collections.emptyList(), preferences); + public LayoutHelper(Reader in, + LayoutFormatterPreferences preferences, + JournalAbbreviationRepository abbreviationRepository) { + this(in, Collections.emptyList(), preferences, abbreviationRepository); } public Layout getLayoutFromText() throws IOException { @@ -62,7 +71,7 @@ public Layout getLayoutFromText() throws IOException { } } - return new Layout(parsedEntries, fileDirForDatabase, preferences); + return new Layout(parsedEntries, fileDirForDatabase, preferences, abbreviationRepository); } public static String getCurrentGroup() { diff --git a/src/main/java/org/jabref/logic/layout/TextBasedPreviewLayout.java b/src/main/java/org/jabref/logic/layout/TextBasedPreviewLayout.java index bb7091dce3f..80bdd02aa2d 100644 --- a/src/main/java/org/jabref/logic/layout/TextBasedPreviewLayout.java +++ b/src/main/java/org/jabref/logic/layout/TextBasedPreviewLayout.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.StringReader; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.preview.PreviewLayout; import org.jabref.model.database.BibDatabaseContext; @@ -12,7 +13,7 @@ import org.slf4j.LoggerFactory; /** - * Implements the preview based JabRef's Custom export fitlters. + * Implements the preview based JabRef's Custom export filters. */ public class TextBasedPreviewLayout implements PreviewLayout { public static final String NAME = "PREVIEW"; @@ -21,9 +22,11 @@ public class TextBasedPreviewLayout implements PreviewLayout { private Layout layout; private String text; private LayoutFormatterPreferences layoutFormatterPreferences; + private JournalAbbreviationRepository abbreviationRepository; - public TextBasedPreviewLayout(String text, LayoutFormatterPreferences layoutFormatterPreferences) { + public TextBasedPreviewLayout(String text, LayoutFormatterPreferences layoutFormatterPreferences, JournalAbbreviationRepository abbreviationRepository) { this.layoutFormatterPreferences = layoutFormatterPreferences; + this.abbreviationRepository = abbreviationRepository; setText(text); } @@ -36,7 +39,7 @@ public void setText(String text) { this.text = text; StringReader sr = new StringReader(text.replace("__NEWLINE__", "\n")); try { - layout = new LayoutHelper(sr, layoutFormatterPreferences).getLayoutFromText(); + layout = new LayoutHelper(sr, layoutFormatterPreferences, abbreviationRepository).getLayoutFromText(); } catch (IOException e) { LOGGER.error("Could not generate layout", e); } diff --git a/src/main/java/org/jabref/logic/openoffice/style/OOBibStyle.java b/src/main/java/org/jabref/logic/openoffice/style/OOBibStyle.java index 6ba2fd664ad..d0e5fa605ab 100644 --- a/src/main/java/org/jabref/logic/openoffice/style/OOBibStyle.java +++ b/src/main/java/org/jabref/logic/openoffice/style/OOBibStyle.java @@ -19,6 +19,7 @@ import java.util.TreeSet; import java.util.regex.Pattern; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutFormatter; import org.jabref.logic.layout.LayoutFormatterPreferences; @@ -130,7 +131,8 @@ public class OOBibStyle implements Comparable { private final Map citProperties = new HashMap<>(); private final boolean fromResource; private final String path; - private final LayoutFormatterPreferences prefs; + private final LayoutFormatterPreferences layoutPreferences; + private final JournalAbbreviationRepository abbreviationRepository; private String name = ""; private Layout defaultBibLayout; private boolean valid; @@ -139,8 +141,9 @@ public class OOBibStyle implements Comparable { private String localCopy; private boolean isDefaultLayoutPresent; - public OOBibStyle(Path styleFile, LayoutFormatterPreferences prefs) throws IOException { - this.prefs = Objects.requireNonNull(prefs); + public OOBibStyle(Path styleFile, LayoutFormatterPreferences layoutPreferences, JournalAbbreviationRepository abbreviationRepository) throws IOException { + this.layoutPreferences = Objects.requireNonNull(layoutPreferences); + this.abbreviationRepository = abbreviationRepository; this.styleFile = Objects.requireNonNull(styleFile); setDefaultProperties(); reload(); @@ -148,8 +151,10 @@ public OOBibStyle(Path styleFile, LayoutFormatterPreferences prefs) throws IOExc path = styleFile.toAbsolutePath().toString(); } - public OOBibStyle(String resourcePath, LayoutFormatterPreferences prefs) throws IOException { - this.prefs = Objects.requireNonNull(prefs); + public OOBibStyle(String resourcePath, LayoutFormatterPreferences layoutPreferences, JournalAbbreviationRepository abbreviationRepository) throws IOException { + this.layoutPreferences = Objects.requireNonNull(layoutPreferences); + this.abbreviationRepository = abbreviationRepository; + Objects.requireNonNull(resourcePath); setDefaultProperties(); initialize(OOBibStyle.class.getResourceAsStream(resourcePath)); @@ -379,7 +384,7 @@ private void handleStructureLine(String line) { try { final String typeName = line.substring(0, index); final String formatString = line.substring(index + 1); - Layout layout = new LayoutHelper(new StringReader(formatString), this.prefs).getLayoutFromText(); + Layout layout = new LayoutHelper(new StringReader(formatString), layoutPreferences, abbreviationRepository).getLayoutFromText(); EntryType type = EntryTypeFactory.parse(typeName); if (!isDefaultLayoutPresent && OOBibStyle.DEFAULT_MARK.equals(typeName)) { @@ -654,8 +659,8 @@ protected void setValid(boolean isValid) { valid = isValid; } - protected LayoutFormatterPreferences getPrefs() { - return prefs; + protected LayoutFormatterPreferences getLayoutPreferences() { + return layoutPreferences; } protected void setDefaultBibLayout(Layout layout) { diff --git a/src/main/java/org/jabref/logic/openoffice/style/StyleLoader.java b/src/main/java/org/jabref/logic/openoffice/style/StyleLoader.java index 90e1bc50158..ad7bad0e9cc 100644 --- a/src/main/java/org/jabref/logic/openoffice/style/StyleLoader.java +++ b/src/main/java/org/jabref/logic/openoffice/style/StyleLoader.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Objects; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.openoffice.OpenOfficePreferences; @@ -27,15 +28,19 @@ public class StyleLoader { private final OpenOfficePreferences openOfficePreferences; private final LayoutFormatterPreferences layoutFormatterPreferences; + private final JournalAbbreviationRepository abbreviationRepository; // Lists of the internal // and external styles private final List internalStyles = new ArrayList<>(); private final List externalStyles = new ArrayList<>(); - public StyleLoader(OpenOfficePreferences openOfficePreferences, LayoutFormatterPreferences formatterPreferences) { + public StyleLoader(OpenOfficePreferences openOfficePreferences, + LayoutFormatterPreferences formatterPreferences, + JournalAbbreviationRepository abbreviationRepository) { this.openOfficePreferences = Objects.requireNonNull(openOfficePreferences); this.layoutFormatterPreferences = Objects.requireNonNull(formatterPreferences); + this.abbreviationRepository = Objects.requireNonNull(abbreviationRepository); loadInternalStyles(); loadExternalStyles(); } @@ -55,7 +60,7 @@ public List getStyles() { public boolean addStyleIfValid(String filename) { Objects.requireNonNull(filename); try { - OOBibStyle newStyle = new OOBibStyle(Path.of(filename), layoutFormatterPreferences); + OOBibStyle newStyle = new OOBibStyle(Path.of(filename), layoutFormatterPreferences, abbreviationRepository); if (externalStyles.contains(newStyle)) { LOGGER.info("External style file {} already existing.", filename); } else if (newStyle.isValid()) { @@ -80,7 +85,7 @@ private void loadExternalStyles() { List lists = openOfficePreferences.getExternalStyles(); for (String filename : lists) { try { - OOBibStyle style = new OOBibStyle(Path.of(filename), layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle(Path.of(filename), layoutFormatterPreferences, abbreviationRepository); if (style.isValid()) { // Problem! externalStyles.add(style); } else { @@ -99,7 +104,7 @@ private void loadInternalStyles() { internalStyles.clear(); for (String filename : internalStyleFiles) { try { - internalStyles.add(new OOBibStyle(filename, layoutFormatterPreferences)); + internalStyles.add(new OOBibStyle(filename, layoutFormatterPreferences, abbreviationRepository)); } catch (IOException e) { LOGGER.info("Problem reading internal style file {}", filename, e); } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 336db303aed..a0bb36ac229 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1131,11 +1131,10 @@ public void importPreferences(Path file) throws JabRefException { //************************************************************************************************************* @Override - public LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviationRepository repository) { + public LayoutFormatterPreferences getLayoutFormatterPreferences() { return new LayoutFormatterPreferences( getNameFormatterPreferences(), - getFilePreferences().mainFileDirectoryProperty(), - repository); + getFilePreferences().mainFileDirectoryProperty()); } @Override @@ -2250,7 +2249,7 @@ public SaveConfiguration getExportConfiguration() { @Override public List getCustomExportFormats(JournalAbbreviationRepository abbreviationRepository) { - LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(abbreviationRepository); + LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(); SaveConfiguration saveConfiguration = getExportConfiguration(); List formats = new ArrayList<>(); @@ -2261,6 +2260,7 @@ public List getCustomExportFormats(JournalAbbreviationReposito formatData.get(EXPORTER_FILENAME_INDEX), formatData.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, + abbreviationRepository, saveConfiguration); format.setCustomExport(true); formats.add(format); @@ -2301,7 +2301,7 @@ public PreviewPreferences getPreviewPreferences() { this.previewPreferences = new PreviewPreferences( layouts, getPreviewCyclePosition(layouts), - new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)), + new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(), Globals.journalAbbreviationRepository), (String) defaults.get(PREVIEW_STYLE), getBoolean(PREVIEW_AS_TAB)); @@ -2328,7 +2328,7 @@ private List getPreviewLayouts(String style) { .map(file -> (PreviewLayout) new CitationStylePreviewLayout(file, Globals.entryTypesManager)) .orElse(null); } else { - return new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)); + return new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(), Globals.journalAbbreviationRepository); } }) .filter(Objects::nonNull) diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index ec0cc48e6a7..82b2dab3232 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -71,7 +71,7 @@ public interface PreferencesService { Map getDefaults(); - LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviationRepository repository); + LayoutFormatterPreferences getLayoutFormatterPreferences(); ImportFormatPreferences getImportFormatPreferences(); diff --git a/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java b/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java index cd6db4c3716..d5fe209a3a0 100644 --- a/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java +++ b/src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java @@ -12,6 +12,7 @@ import org.jabref.gui.JabRefDialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.StandardActions; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; @@ -32,15 +33,17 @@ public class CopyMoreActionTest { + private final DialogService dialogService = spy(DialogService.class); + private final ClipBoardManager clipBoardManager = mock(ClipBoardManager.class); + private final PreferencesService preferencesService = mock(PreferencesService.class); + private final JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); + private final StateManager stateManager = mock(StateManager.class); + private final List titles = new ArrayList<>(); + private final List keys = new ArrayList<>(); + private final List dois = new ArrayList<>(); + private CopyMoreAction copyMoreAction; - private DialogService dialogService = spy(DialogService.class); - private ClipBoardManager clipBoardManager = mock(ClipBoardManager.class); - private PreferencesService preferencesService = mock(PreferencesService.class); - private StateManager stateManager = mock(StateManager.class); private BibEntry entry; - private List titles = new ArrayList<>(); - private List keys = new ArrayList<>(); - private List dois = new ArrayList<>(); @BeforeEach public void setUp() { @@ -61,7 +64,7 @@ public void setUp() { public void testExecuteOnFail() { when(stateManager.getActiveDatabase()).thenReturn(Optional.empty()); when(stateManager.getSelectedEntries()).thenReturn(FXCollections.emptyObservableList()); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); verify(clipBoardManager, times(0)).setContent(any(String.class)); @@ -77,7 +80,7 @@ public void testExecuteCopyTitleWithNoTitle() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithNoTitles); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); verify(clipBoardManager, times(0)).setContent(any(String.class)); @@ -93,7 +96,7 @@ public void testExecuteCopyTitleOnPartialSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(mixedEntries); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedTitles = String.join("\n", titles); @@ -109,7 +112,7 @@ public void testExecuteCopyTitleOnSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithTitles); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedTitles = String.join("\n", titles); @@ -127,7 +130,7 @@ public void testExecuteCopyKeyWithNoKey() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithNoKeys); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); verify(clipBoardManager, times(0)).setContent(any(String.class)); @@ -143,7 +146,7 @@ public void testExecuteCopyKeyOnPartialSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(mixedEntries); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedKeys = String.join("\n", keys); @@ -159,7 +162,7 @@ public void testExecuteCopyKeyOnSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithKeys); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedKeys = String.join("\n", keys); @@ -177,7 +180,7 @@ public void testExecuteCopyDoiWithNoDoi() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithNoDois); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); verify(clipBoardManager, times(0)).setContent(any(String.class)); @@ -193,7 +196,7 @@ public void testExecuteCopyDoiOnPartialSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(mixedEntries); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedDois = String.join("\n", dois); @@ -209,7 +212,7 @@ public void testExecuteCopyDoiOnSuccess() { when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); when(stateManager.getSelectedEntries()).thenReturn(entriesWithDois); - copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService); + copyMoreAction = new CopyMoreAction(StandardActions.COPY_DOI, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository); copyMoreAction.execute(); String copiedDois = String.join("\n", dois); diff --git a/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java b/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java index 03fb4dc6483..49bd0c0073b 100644 --- a/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java +++ b/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java @@ -14,6 +14,7 @@ import org.jabref.gui.util.CustomLocalDragboard; import org.jabref.gui.util.OptionalObjectProperty; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.preferences.PreferencesService; import org.jabref.preferences.SidePanePreferences; @@ -31,6 +32,7 @@ class SidePaneViewModelTest { PreferencesService preferencesService = mock(PreferencesService.class); + JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); StateManager stateManager = mock(StateManager.class); TaskExecutor taskExecutor = mock(TaskExecutor.class); DialogService dialogService = mock(DialogService.class); @@ -52,7 +54,7 @@ void setUp() { sidePanePreferences.getPreferredPositions().put(SidePaneType.WEB_SEARCH, 1); sidePanePreferences.getPreferredPositions().put(SidePaneType.OPEN_OFFICE, 2); - sidePaneViewModel = new SidePaneViewModel(preferencesService, stateManager, taskExecutor, dialogService, undoManager); + sidePaneViewModel = new SidePaneViewModel(preferencesService, abbreviationRepository, stateManager, taskExecutor, dialogService, undoManager); } @Test diff --git a/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java b/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java index 4ccc17d5295..f1f4c6eee3a 100644 --- a/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java +++ b/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java @@ -4,10 +4,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -40,6 +40,7 @@ public void setUp() { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), saveConfiguration, mock(XmpPreferences.class), mock(FieldPreferences.class), @@ -60,9 +61,8 @@ public void tearDown() { public void testPerformExportForSingleAuthor(@TempDir Path testFolder) throws Exception { Path path = testFolder.resolve("ThisIsARandomlyNamedFile"); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.AUTHOR, "Someone, Van Something"); - List entries = Arrays.asList(entry); + BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "Someone, Van Something"); + List entries = List.of(entry); exportFormat.export(databaseContext, path, entries); @@ -77,9 +77,8 @@ public void testPerformExportForSingleAuthor(@TempDir Path testFolder) throws Ex public void testPerformExportForMultipleAuthors(@TempDir Path testFolder) throws Exception { Path path = testFolder.resolve("ThisIsARandomlyNamedFile"); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.AUTHOR, "von Neumann, John and Smith, John and Black Brown, Peter"); - List entries = Arrays.asList(entry); + BibEntry entry = new BibEntry().withField(StandardField.AUTHOR, "von Neumann, John and Smith, John and Black Brown, Peter"); + List entries = List.of(entry); exportFormat.export(databaseContext, path, entries); @@ -94,9 +93,8 @@ public void testPerformExportForMultipleAuthors(@TempDir Path testFolder) throws public void testPerformExportForSingleEditor(@TempDir Path testFolder) throws Exception { Path path = testFolder.resolve("ThisIsARandomlyNamedFile"); File tmpFile = path.toFile(); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.EDITOR, "Someone, Van Something"); - List entries = Arrays.asList(entry); + BibEntry entry = new BibEntry().withField(StandardField.EDITOR, "Someone, Van Something"); + List entries = List.of(entry); exportFormat.export(databaseContext, tmpFile.toPath(), entries); @@ -113,7 +111,7 @@ public void testPerformExportForMultipleEditors(@TempDir Path testFolder) throws File tmpFile = path.toFile(); BibEntry entry = new BibEntry(); entry.setField(StandardField.EDITOR, "von Neumann, John and Smith, John and Black Brown, Peter"); - List entries = Arrays.asList(entry); + List entries = List.of(entry); exportFormat.export(databaseContext, tmpFile.toPath(), entries); diff --git a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java index 20e2118cdbd..d7186205bc4 100644 --- a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java @@ -11,6 +11,7 @@ import java.util.List; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -53,6 +54,7 @@ void setUp() throws URISyntaxException { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), saveConfiguration, mock(XmpPreferences.class), mock(FieldPreferences.class), diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index 299260af4a2..1e272d725e2 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -9,6 +9,7 @@ import java.util.List; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -42,6 +43,7 @@ public void setUp() { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), saveConfiguration, mock(XmpPreferences.class), mock(FieldPreferences.class), diff --git a/src/test/java/org/jabref/logic/exporter/ExporterTest.java b/src/test/java/org/jabref/logic/exporter/ExporterTest.java index a4db009de7d..29bb2f59a37 100644 --- a/src/test/java/org/jabref/logic/exporter/ExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/ExporterTest.java @@ -11,6 +11,7 @@ import java.util.stream.Stream; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -47,6 +48,7 @@ private static Stream exportFormats() { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class), + mock(JournalAbbreviationRepository.class), mock(SaveConfiguration.class), mock(XmpPreferences.class), mock(FieldPreferences.class, Answers.RETURNS_DEEP_STUBS), diff --git a/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java b/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java index 456f5b8feb6..9b0955ab97f 100644 --- a/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java +++ b/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java @@ -9,6 +9,7 @@ import java.util.List; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -42,6 +43,7 @@ public void setUp() { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), saveConfiguration, mock(XmpPreferences.class), mock(FieldPreferences.class), diff --git a/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java b/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java index e7a899428c2..85da5a7e394 100644 --- a/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java +++ b/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java @@ -15,6 +15,7 @@ import java.util.zip.ZipInputStream; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -53,6 +54,7 @@ void setUp() throws URISyntaxException { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), mock(SaveConfiguration.class), mock(XmpPreferences.class), mock(FieldPreferences.class), diff --git a/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java b/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java index f22ff325d8e..2fc4a6b335f 100644 --- a/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java @@ -9,6 +9,7 @@ import java.util.List; import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; @@ -42,6 +43,7 @@ static void setUp() { ExporterFactory exporterFactory = ExporterFactory.create( new ArrayList<>(), mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), + mock(JournalAbbreviationRepository.class), saveConfiguration, mock(XmpPreferences.class), mock(FieldPreferences.class), diff --git a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java index aaceee79574..5b910a2f2e8 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutEntryTest.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.StringReader; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; @@ -62,7 +63,7 @@ public void setUp() { public String layout(String layoutFile, BibEntry entry) throws IOException { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); - Layout layout = new LayoutHelper(sr, mock(LayoutFormatterPreferences.class)).getLayoutFromText(); + Layout layout = new LayoutHelper(sr, mock(LayoutFormatterPreferences.class), mock(JournalAbbreviationRepository.class)).getLayoutFromText(); return layout.doLayout(entry, null); } diff --git a/src/test/java/org/jabref/logic/layout/LayoutHelperTest.java b/src/test/java/org/jabref/logic/layout/LayoutHelperTest.java index d2203eddc1b..dec5ab5d781 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutHelperTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutHelperTest.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.io.StringReader; +import org.jabref.logic.journals.JournalAbbreviationRepository; + import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -11,19 +13,20 @@ class LayoutHelperTest { + private final LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class); + private final JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); + @Test public void backslashDoesNotTriggerException() { StringReader stringReader = new StringReader("\\"); - LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class); - LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences); + LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences, abbreviationRepository); assertThrows(IOException.class, layoutHelper::getLayoutFromText); } @Test public void unbalancedBeginEndIsParsed() throws Exception { StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi"); - LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class); - LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences); + LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences, abbreviationRepository); Layout layout = layoutHelper.getLayoutFromText(); assertNotNull(layout); } @@ -31,8 +34,7 @@ public void unbalancedBeginEndIsParsed() throws Exception { @Test public void minimalExampleWithDoiGetsParsed() throws Exception { StringReader stringReader = new StringReader("\\begin{doi}, DOI: \\doi\\end{doi}"); - LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class); - LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences); + LayoutHelper layoutHelper = new LayoutHelper(stringReader, layoutFormatterPreferences, abbreviationRepository); Layout layout = layoutHelper.getLayoutFromText(); assertNotNull(layout); } diff --git a/src/test/java/org/jabref/logic/layout/LayoutTest.java b/src/test/java/org/jabref/logic/layout/LayoutTest.java index a41c65fe801..ad1387a63d6 100644 --- a/src/test/java/org/jabref/logic/layout/LayoutTest.java +++ b/src/test/java/org/jabref/logic/layout/LayoutTest.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.List; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.format.NameFormatterPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; @@ -25,16 +26,19 @@ class LayoutTest { private LayoutFormatterPreferences layoutFormatterPreferences; + private JournalAbbreviationRepository abbreviationRepository; @BeforeEach void setUp() { layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); + abbreviationRepository = mock(JournalAbbreviationRepository.class); + } private String layout(String layout, List fileDirForDatabase, BibEntry entry) throws IOException { StringReader layoutStringReader = new StringReader(layout.replace("__NEWLINE__", "\n")); - return new LayoutHelper(layoutStringReader, fileDirForDatabase, layoutFormatterPreferences) + return new LayoutHelper(layoutStringReader, fileDirForDatabase, layoutFormatterPreferences, abbreviationRepository) .getLayoutFromText() .doLayout(entry, null); } diff --git a/src/test/java/org/jabref/logic/openoffice/style/OOBibStyleTest.java b/src/test/java/org/jabref/logic/openoffice/style/OOBibStyleTest.java index 102c90f081a..9935a9b50c3 100644 --- a/src/test/java/org/jabref/logic/openoffice/style/OOBibStyleTest.java +++ b/src/test/java/org/jabref/logic/openoffice/style/OOBibStyleTest.java @@ -13,6 +13,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.Layout; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.model.database.BibDatabase; @@ -26,7 +27,6 @@ import org.jabref.model.openoffice.style.CitationMarkerNumericEntry; import org.jabref.model.openoffice.style.NonUniqueCitationMarker; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Answers; @@ -37,16 +37,12 @@ import static org.mockito.Mockito.mock; class OOBibStyleTest { - private LayoutFormatterPreferences layoutFormatterPreferences; - - @BeforeEach - void setUp() { - layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); - } + private final LayoutFormatterPreferences layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);; + private final JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class); @Test void testAuthorYear() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, layoutFormatterPreferences, abbreviationRepository); assertTrue(style.isValid()); assertTrue(style.isInternalStyle()); assertFalse(style.isCitationKeyCiteMarkers()); @@ -61,7 +57,7 @@ void testAuthorYear() throws IOException { void testAuthorYearAsFile() throws URISyntaxException, IOException { Path defFile = Path.of(OOBibStyleTest.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()); - OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences, abbreviationRepository); assertTrue(style.isValid()); assertFalse(style.isInternalStyle()); assertFalse(style.isCitationKeyCiteMarkers()); @@ -74,8 +70,10 @@ void testAuthorYearAsFile() throws URISyntaxException, IOException { @Test void testNumerical() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertTrue(style.isValid()); assertFalse(style.isCitationKeyCiteMarkers()); assertFalse(style.isBoldCitations()); @@ -163,8 +161,10 @@ static String getCitationMarker2b(OOBibStyle style, @Test void testGetNumCitationMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertEquals("[1] ", runGetNumCitationMarker2a(style, List.of(1), -1, true)); assertEquals("[1]", runGetNumCitationMarker2a(style, List.of(1), -1, false)); @@ -181,8 +181,10 @@ void testGetNumCitationMarker() throws IOException { @Test void testGetNumCitationMarkerUndefined() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); // unresolved citations look like [??key] assertEquals("[" + OOBibStyle.UNDEFINED_CITATION_MARKER + "key" + "]", @@ -229,8 +231,10 @@ void testGetNumCitationMarkerUndefined() throws IOException { @Test void testGetCitProperty() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertEquals(", ", style.getStringCitProperty("AuthorSeparator")); // old @@ -248,7 +252,10 @@ void testGetCitProperty() throws IOException { @Test void testGetCitationMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); BibEntry entry = new BibEntry() .withField(StandardField.AUTHOR, "Gustav Bostr\\\"{o}m and Jaana W\\\"{a}yrynen and Marine Bod\\'{e}n and Konstantin Beznosov and Philippe Kruchten") .withField(StandardField.YEAR, "2006") @@ -287,7 +294,10 @@ void testGetCitationMarker() throws IOException { @Test void testLayout() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); BibEntry entry = new BibEntry() .withField(StandardField.AUTHOR, "Gustav Bostr\\\"{o}m and Jaana W\\\"{a}yrynen and Marine Bod\\'{e}n and Konstantin Beznosov and Philippe Kruchten") @@ -314,7 +324,10 @@ void testLayout() throws IOException { @Test void testInstitutionAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); BibDatabase database = new BibDatabase(); Layout l = style.getReferenceFormat(StandardEntryType.Article); @@ -332,8 +345,10 @@ void testInstitutionAuthor() throws IOException { @Test void testVonAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); BibDatabase database = new BibDatabase(); Layout l = style.getReferenceFormat(StandardEntryType.Article); @@ -351,8 +366,10 @@ void testVonAuthor() throws IOException { @Test void testInstitutionAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -375,8 +392,10 @@ void testInstitutionAuthorMarker() throws IOException { @Test void testVonAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -396,8 +415,10 @@ void testVonAuthorMarker() throws IOException { @Test void testNullAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle + (StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -415,8 +436,10 @@ void testNullAuthorMarker() throws IOException { @Test void testNullYearMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -434,8 +457,10 @@ void testNullYearMarker() throws IOException { @Test void testEmptyEntryMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -452,8 +477,10 @@ void testEmptyEntryMarker() throws IOException { @Test void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -494,8 +521,10 @@ void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { @Test void testGetCitationMarkerInTextUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -536,8 +565,10 @@ void testGetCitationMarkerInTextUniquefiers() throws IOException { @Test void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -577,8 +608,10 @@ void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOExc @Test void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -619,45 +652,61 @@ void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException @Test // TODO: equals only work when initialized from file, not from reader void testEquals() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style1 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); + OOBibStyle style2 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertEquals(style1, style2); } @Test // TODO: equals only work when initialized from file, not from reader void testNotEquals() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style1 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); + OOBibStyle style2 = new OOBibStyle( + StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertNotEquals(style1, style2); } @Test void testCompareToEqual() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style1 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); + OOBibStyle style2 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertEquals(0, style1.compareTo(style2)); } @Test void testCompareToNotEqual() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style1 = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); + OOBibStyle style2 = new OOBibStyle( + StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); assertTrue(style1.compareTo(style2) > 0); assertFalse(style2.compareTo(style1) > 0); } @Test void testEmptyStringPropertyAndOxfordComma() throws Exception { - OOBibStyle style = new OOBibStyle("test.jstyle", layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle("test.jstyle", layoutFormatterPreferences, abbreviationRepository); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); BibDatabase database = new BibDatabase(); @@ -677,14 +726,16 @@ void testEmptyStringPropertyAndOxfordComma() throws Exception { @Test void testIsValidWithDefaultSectionAtTheStart() throws Exception { - OOBibStyle style = new OOBibStyle("testWithDefaultAtFirstLIne.jstyle", layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle("testWithDefaultAtFirstLIne.jstyle", layoutFormatterPreferences, abbreviationRepository); assertTrue(style.isValid()); } @Test void testGetCitationMarkerJoinFirst() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, - layoutFormatterPreferences); + OOBibStyle style = new OOBibStyle( + StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + layoutFormatterPreferences, + abbreviationRepository); // Question: What should happen if some sources are // marked as isFirstAppearanceOfSource? diff --git a/src/test/java/org/jabref/logic/openoffice/style/StyleLoaderTest.java b/src/test/java/org/jabref/logic/openoffice/style/StyleLoaderTest.java index 954fb3aa616..38d8a359615 100644 --- a/src/test/java/org/jabref/logic/openoffice/style/StyleLoaderTest.java +++ b/src/test/java/org/jabref/logic/openoffice/style/StyleLoaderTest.java @@ -8,6 +8,7 @@ import javafx.collections.FXCollections; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.openoffice.OpenOfficePreferences; @@ -29,27 +30,34 @@ public class StyleLoaderTest { private OpenOfficePreferences preferences; private LayoutFormatterPreferences layoutPreferences; + private JournalAbbreviationRepository abbreviationRepository; @BeforeEach public void setUp() { preferences = mock(OpenOfficePreferences.class, Answers.RETURNS_DEEP_STUBS); layoutPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS); + abbreviationRepository = mock(JournalAbbreviationRepository.class); } @Test public void throwNPEWithNullPreferences() { - assertThrows(NullPointerException.class, () -> loader = new StyleLoader(null, layoutPreferences)); + assertThrows(NullPointerException.class, () -> loader = new StyleLoader(null, layoutPreferences, abbreviationRepository)); } @Test public void throwNPEWithNullLayoutPreferences() { - assertThrows(NullPointerException.class, () -> loader = new StyleLoader(mock(OpenOfficePreferences.class), null)); + assertThrows(NullPointerException.class, () -> loader = new StyleLoader(mock(OpenOfficePreferences.class), null, abbreviationRepository)); + } + + @Test + public void throwNPEWithNullAbbreviationRepository() { + assertThrows(NullPointerException.class, () -> loader = new StyleLoader(mock(OpenOfficePreferences.class), layoutPreferences, null)); } @Test public void testGetStylesWithEmptyExternal() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); assertEquals(2, loader.getStyles().size()); } @@ -57,7 +65,7 @@ public void testGetStylesWithEmptyExternal() { @Test public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); @@ -68,7 +76,7 @@ public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { @Test public void testAddInvalidStyleLeadsToNoMoreStyle() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); int beforeAdding = loader.getStyles().size(); loader.addStyleIfValid("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky"); assertEquals(beforeAdding, loader.getStyles().size()); @@ -79,7 +87,7 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(FXCollections.singletonObservableList(filename)); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); assertEquals(NUMBER_OF_INTERNAL_STYLES + 1, loader.getStyles().size()); } @@ -87,7 +95,7 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { public void testInitalizeWithIncorrectExternalFile() { preferences.setExternalStyles(Collections.singletonList("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky")); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); assertEquals(NUMBER_OF_INTERNAL_STYLES, loader.getStyles().size()); } @@ -97,7 +105,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(FXCollections.singletonObservableList(filename)); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); List toremove = new ArrayList<>(); int beforeRemoving = loader.getStyles().size(); for (OOBibStyle style : loader.getStyles()) { @@ -118,7 +126,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro .toFile().getPath(); when(preferences.getExternalStyles()).thenReturn(FXCollections.singletonObservableList(filename)); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { if (!style.isInternalStyle()) { @@ -136,7 +144,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro @Test public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); int beforeAdding = loader.getStyles().size(); String filename = Path.of(StyleLoader.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); @@ -147,7 +155,7 @@ public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException @Test public void testAddNullStyleThrowsNPE() { - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); assertThrows(NullPointerException.class, () -> loader.addStyleIfValid(null)); } @@ -155,7 +163,7 @@ public void testAddNullStyleThrowsNPE() { public void testGetDefaultUsedStyleWhenEmpty() { when(preferences.getCurrentStyle()).thenReturn(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH); preferences.clearCurrentStyle(); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, style.getPath()); @@ -165,7 +173,7 @@ public void testGetDefaultUsedStyleWhenEmpty() { @Test public void testGetStoredUsedStyle() { when(preferences.getCurrentStyle()).thenReturn(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, style.getPath()); @@ -175,7 +183,7 @@ public void testGetStoredUsedStyle() { @Test public void testGetDefaultUsedStyleWhenIncorrect() { when(preferences.getCurrentStyle()).thenReturn("ljlkjlkjnljnvdlsjniuhwelfhuewfhlkuewhfuwhelu"); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, style.getPath()); @@ -185,7 +193,7 @@ public void testGetDefaultUsedStyleWhenIncorrect() { public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, layoutPreferences); + loader = new StyleLoader(preferences, layoutPreferences, abbreviationRepository); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { if (style.isInternalStyle()) { From e15453df7d9b23ec482ba53733334b076050fcbc Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:38:53 +0200 Subject: [PATCH 05/11] Focused tests and removed superfluous constructor --- .../logic/exporter/ExporterFactory.java | 24 +++++-------------- .../logic/exporter/CsvExportFormatTest.java | 22 +++++++---------- .../logic/exporter/DocBook5ExporterTest.java | 24 +++++++------------ .../logic/exporter/DocbookExporterTest.java | 21 +++++++--------- .../jabref/logic/exporter/ExporterTest.java | 24 +++++++++---------- .../logic/exporter/HtmlExportFormatTest.java | 24 +++++++------------ .../OpenOfficeDocumentCreatorTest.java | 23 +----------------- .../logic/exporter/YamlExporterTest.java | 24 +++++++------------ 8 files changed, 59 insertions(+), 127 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index 4bc0b982dd3..b63412e2e3b 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -27,25 +27,13 @@ private ExporterFactory(List exporters) { public static ExporterFactory create(PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, JournalAbbreviationRepository abbreviationRepository) { - return ExporterFactory.create( - preferencesService.getCustomExportFormats(abbreviationRepository), - preferencesService.getLayoutFormatterPreferences(), - abbreviationRepository, - preferencesService.getExportConfiguration(), - preferencesService.getXmpPreferences(), - preferencesService.getFieldPreferences(), - preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(), - entryTypesManager); - } - public static ExporterFactory create(List customFormats, - LayoutFormatterPreferences layoutPreferences, - JournalAbbreviationRepository abbreviationRepository, - SaveConfiguration saveConfiguration, - XmpPreferences xmpPreferences, - FieldPreferences fieldPreferences, - BibDatabaseMode bibDatabaseMode, - BibEntryTypesManager entryTypesManager) { + List customFormats = preferencesService.getCustomExportFormats(abbreviationRepository); + LayoutFormatterPreferences layoutPreferences = preferencesService.getLayoutFormatterPreferences(); + SaveConfiguration saveConfiguration = preferencesService.getExportConfiguration(); + XmpPreferences xmpPreferences = preferencesService.getXmpPreferences(); + FieldPreferences fieldPreferences = preferencesService.getFieldPreferences(); + BibDatabaseMode bibDatabaseMode = preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(); List exporters = new ArrayList<>(); diff --git a/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java b/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java index f1f4c6eee3a..244be249bdb 100644 --- a/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java +++ b/src/test/java/org/jabref/logic/exporter/CsvExportFormatTest.java @@ -3,17 +3,13 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.SaveOrder; @@ -37,17 +33,15 @@ public void setUp() { SaveConfiguration saveConfiguration = mock(SaveConfiguration.class); when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), + exportFormat = new TemplateExporter( + "OpenOffice/LibreOffice CSV", + "oocsv", + "openoffice-csv", + "openoffice", + StandardFileType.CSV, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), mock(JournalAbbreviationRepository.class), - saveConfiguration, - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); - - exportFormat = exporterFactory.getExporterByName("oocsv").get(); + saveConfiguration); databaseContext = new BibDatabaseContext(); } diff --git a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java index d7186205bc4..311ea83962d 100644 --- a/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocBook5ExporterTest.java @@ -6,18 +6,14 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDate; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.metadata.SaveOrder; @@ -47,24 +43,22 @@ public class DocBook5ExporterTest { @BeforeEach void setUp() throws URISyntaxException { - xmlFile = Path.of(DocBook5ExporterTest.class.getResource("Docbook5ExportFormat.xml").toURI()); SaveConfiguration saveConfiguration = mock(SaveConfiguration.class); when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), + exporter = new TemplateExporter( + "DocBook 5.1", + "docbook5", + "docbook5", + null, + StandardFileType.XML, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), mock(JournalAbbreviationRepository.class), - saveConfiguration, - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); - - exporter = exporterFactory.getExporterByName("docbook5").get(); + saveConfiguration); LocalDate myDate = LocalDate.of(2018, 1, 1); + xmlFile = Path.of(DocBook5ExporterTest.class.getResource("Docbook5ExportFormat.xml").toURI()); databaseContext = new BibDatabaseContext(); charset = StandardCharsets.UTF_8; BibEntry entry = new BibEntry(StandardEntryType.Book); diff --git a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java index 1e272d725e2..ce7997364fe 100644 --- a/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/DocbookExporterTest.java @@ -4,18 +4,14 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.SaveOrder; @@ -40,16 +36,15 @@ public void setUp() { SaveConfiguration saveConfiguration = mock(SaveConfiguration.class); when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), + exportFormat = new TemplateExporter( + "DocBook 4", + "docbook4", + "docbook4", + null, + StandardFileType.XML, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), mock(JournalAbbreviationRepository.class), - saveConfiguration, - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); - exportFormat = exporterFactory.getExporterByName("docbook4").get(); + saveConfiguration); } @Test diff --git a/src/test/java/org/jabref/logic/exporter/ExporterTest.java b/src/test/java/org/jabref/logic/exporter/ExporterTest.java index 29bb2f59a37..a61a0012e71 100644 --- a/src/test/java/org/jabref/logic/exporter/ExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/ExporterTest.java @@ -10,14 +10,12 @@ import java.util.List; import java.util.stream.Stream; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; -import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.metadata.SaveOrder; +import org.jabref.preferences.PreferencesService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; @@ -27,7 +25,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ExporterTest { @@ -43,18 +43,16 @@ public void setUp() { } private static Stream exportFormats() { - Collection result = new ArrayList<>(); + PreferencesService preferencesService = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS); + when(preferencesService.getExportPreferences().getExportSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); + when(preferencesService.getCustomExportFormats(any())).thenReturn(new ArrayList<>()); ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), - mock(LayoutFormatterPreferences.class), - mock(JournalAbbreviationRepository.class), - mock(SaveConfiguration.class), - mock(XmpPreferences.class), - mock(FieldPreferences.class, Answers.RETURNS_DEEP_STUBS), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); + preferencesService, + mock(BibEntryTypesManager.class), + mock(JournalAbbreviationRepository.class)); + Collection result = new ArrayList<>(); for (Exporter format : exporterFactory.getExporters()) { result.add(new Object[]{format, format.getName()}); } diff --git a/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java b/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java index 9b0955ab97f..ea0415bfb70 100644 --- a/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java +++ b/src/test/java/org/jabref/logic/exporter/HtmlExportFormatTest.java @@ -4,18 +4,13 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.metadata.SaveOrder; @@ -40,17 +35,14 @@ public void setUp() { SaveConfiguration saveConfiguration = mock(SaveConfiguration.class); when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), + exportFormat = new TemplateExporter("HTML", + "html", + "html", + null, + StandardFileType.HTML, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), mock(JournalAbbreviationRepository.class), - saveConfiguration, - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); - - exportFormat = exporterFactory.getExporterByName("html").get(); + saveConfiguration); databaseContext = new BibDatabaseContext(); charset = StandardCharsets.UTF_8; @@ -58,7 +50,7 @@ public void setUp() { entry.setField(StandardField.TITLE, "my paper title"); entry.setField(StandardField.AUTHOR, "Stefan Kolb"); entry.setCitationKey("mykey"); - entries = Arrays.asList(entry); + entries = List.of(entry); } @AfterEach diff --git a/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java b/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java index 85da5a7e394..53c0d088a45 100644 --- a/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java +++ b/src/test/java/org/jabref/logic/exporter/OpenOfficeDocumentCreatorTest.java @@ -8,38 +8,27 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.jabref.logic.bibtex.FieldPreferences; -import org.jabref.logic.journals.JournalAbbreviationRepository; -import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.mockito.Answers; import org.xmlunit.builder.Input; import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.ElementSelectors; import org.xmlunit.matchers.CompareMatcher; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; public class OpenOfficeDocumentCreatorTest { - private static final String OPEN_OFFICE_EXPORTER_ID = "oocalc"; - public BibDatabaseContext databaseContext; public Charset charset; public List entries; @@ -51,17 +40,7 @@ public class OpenOfficeDocumentCreatorTest { void setUp() throws URISyntaxException { xmlFile = Path.of(OpenOfficeDocumentCreatorTest.class.getResource("OldOpenOfficeCalcExportFormatContentSingleEntry.xml").toURI()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), - mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), - mock(JournalAbbreviationRepository.class), - mock(SaveConfiguration.class), - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); - - exporter = exporterFactory.getExporterByName(OPEN_OFFICE_EXPORTER_ID).get(); + exporter = new OpenOfficeDocumentCreator(); databaseContext = new BibDatabaseContext(); charset = StandardCharsets.UTF_8; diff --git a/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java b/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java index 2fc4a6b335f..019cb68f80c 100644 --- a/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/YamlExporterTest.java @@ -1,21 +1,15 @@ package org.jabref.logic.exporter; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.layout.LayoutFormatterPreferences; -import org.jabref.logic.xmp.XmpPreferences; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.metadata.SaveOrder; @@ -31,7 +25,6 @@ public class YamlExporterTest { - private static Charset charset; private static Exporter yamlExporter; private static BibDatabaseContext databaseContext; @@ -40,19 +33,18 @@ static void setUp() { SaveConfiguration saveConfiguration = mock(SaveConfiguration.class); when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - ExporterFactory exporterFactory = ExporterFactory.create( - new ArrayList<>(), + yamlExporter = new TemplateExporter( + "CSL YAML", + "yaml", + "yaml", + null, + StandardFileType.YAML, mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS), mock(JournalAbbreviationRepository.class), saveConfiguration, - mock(XmpPreferences.class), - mock(FieldPreferences.class), - BibDatabaseMode.BIBTEX, - mock(BibEntryTypesManager.class)); + BlankLineBehaviour.DELETE_BLANKS); databaseContext = new BibDatabaseContext(); - charset = StandardCharsets.UTF_8; - yamlExporter = exporterFactory.getExporterByName("yaml").get(); } @Test From d2d5a81f1fe04a4ab378db15353105292c2c9ab2 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:46:57 +0200 Subject: [PATCH 06/11] Changed UnknownFormatImport to record --- src/main/java/org/jabref/cli/ArgumentProcessor.java | 4 ++-- .../org/jabref/gui/externalfiles/ImportHandler.java | 2 +- .../java/org/jabref/gui/importer/ImportAction.java | 6 +++--- .../jabref/logic/importer/ImportFormatReader.java | 13 ++----------- .../importer/ImportFormatReaderIntegrationTest.java | 4 ++-- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index bf9238be84b..244c746ec9f 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -167,8 +167,8 @@ private Optional importFile(Path file, String importFormat) { ImportFormatReader.UnknownFormatImport importResult = importFormatReader.importUnknownFormat(file, new DummyFileUpdateMonitor()); - System.out.println(Localization.lang("Format used") + ": " + importResult.format); - return Optional.of(importResult.parserResult); + System.out.println(Localization.lang("Format used") + ": " + importResult.format()); + return Optional.of(importResult.parserResult()); } } catch (ImportException ex) { System.err diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index b1741211be0..e8ec24a805a 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -313,7 +313,7 @@ private List tryImportFormats(String data) { preferencesService.getImportFormatPreferences(), fileUpdateMonitor); UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data); - return unknownFormatImport.parserResult.getDatabase().getEntries(); + return unknownFormatImport.parserResult().getDatabase().getEntries(); } catch (ImportException ex) { // ex is already localized dialogService.showErrorDialogAndWait(Localization.lang("Import error"), ex); return Collections.emptyList(); diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index d17142ac4d1..23e34bfc7ba 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -173,15 +173,15 @@ private ParserResult mergeImportResults(List path.getFileName().toString()).orElse("unknown"), + importResult.parserResult().getPath().map(path -> path.getFileName().toString()).orElse("unknown"), parserResult.getDatabase().getEntries()); } // TODO: collect errors into ParserResult, because they are currently ignored (see caller of this method) diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java index b395211809a..00656ccf780 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java @@ -125,8 +125,7 @@ public ParserResult importFromFile(String format, Path file) throws ImportExcept /** * All importers. - *

- *

+ * * Elements are sorted by name. *

* @@ -136,15 +135,7 @@ public SortedSet getImportFormats() { return new TreeSet<>(this.formats); } - public static class UnknownFormatImport { - - public final String format; - public final ParserResult parserResult; - - public UnknownFormatImport(String format, ParserResult parserResult) { - this.format = format; - this.parserResult = parserResult; - } + public record UnknownFormatImport(String format, ParserResult parserResult) { } /** diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java index 138f3896405..387e7b98175 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java @@ -38,7 +38,7 @@ void setUp() { void testImportUnknownFormat(String resource, String format, int count) throws Exception { Path file = Path.of(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); ImportFormatReader.UnknownFormatImport unknownFormat = reader.importUnknownFormat(file, new DummyFileUpdateMonitor()); - assertEquals(count, unknownFormat.parserResult.getDatabase().getEntryCount()); + assertEquals(count, unknownFormat.parserResult().getDatabase().getEntryCount()); } @ParameterizedTest @@ -53,7 +53,7 @@ void testImportFormatFromFile(String resource, String format, int count) throws void testImportUnknownFormatFromString(String resource, String format, int count) throws Exception { Path file = Path.of(ImportFormatReaderIntegrationTest.class.getResource(resource).toURI()); String data = Files.readString(file); - assertEquals(count, reader.importUnknownFormat(data).parserResult.getDatabase().getEntries().size()); + assertEquals(count, reader.importUnknownFormat(data).parserResult().getDatabase().getEntries().size()); } private static Stream importFormats() { From 2aad5c3b4b88cb6616db362725a02684ad35bdcd Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 5 Jun 2023 22:14:02 +0200 Subject: [PATCH 07/11] Fixed newInstance() deprecation --- .../customimporter/CustomImporterTabViewModel.java | 3 ++- .../logic/importer/fileformat/CustomImporter.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java index db9104ae101..cf449556f5d 100644 --- a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java @@ -15,6 +15,7 @@ import org.jabref.gui.importer.ImporterViewModel; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.fileformat.CustomImporter; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.StandardFileType; @@ -103,7 +104,7 @@ public void addImporter() { Localization.lang("Could not open %0", selectedFile.get().toString()) + "\n" + Localization.lang("Have you chosen the correct package path?"), exc); - } catch (ClassNotFoundException exc) { + } catch (ImportException exc) { LOGGER.error("Could not instantiate importer", exc); dialogService.showErrorDialogAndWait( Localization.lang("Could not instantiate %0 %1", "importer"), diff --git a/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java index 16c6f14434d..f928de20875 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/CustomImporter.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Objects; +import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.util.FileType; @@ -25,21 +26,21 @@ public class CustomImporter extends Importer { private final Importer importer; - public CustomImporter(String basePath, String className) throws ClassNotFoundException { + public CustomImporter(String basePath, String className) throws ImportException { this.basePath = Path.of(basePath); this.className = className; try { importer = load(this.basePath.toUri().toURL(), this.className); - } catch (IOException | InstantiationException | IllegalAccessException exception) { - throw new ClassNotFoundException("", exception); + } catch (IOException | ReflectiveOperationException exception) { + throw new ImportException(exception); } } private static Importer load(URL basePathURL, String className) - throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { + throws IOException, ReflectiveOperationException { try (URLClassLoader cl = new URLClassLoader(new URL[]{basePathURL})) { Class clazz = Class.forName(className, true, cl); - return (Importer) clazz.newInstance(); + return (Importer) clazz.getDeclaredConstructor().newInstance(); } } From 4507ce6a8894efceb166b7fe736b2c1a26adb8fb Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:41:40 +0200 Subject: [PATCH 08/11] Refactored LinkedFilesEditor --- .../jabref/gui/fieldeditors/FieldEditors.java | 2 +- .../gui/fieldeditors/LinkedFilesEditor.fxml | 3 +- .../gui/fieldeditors/LinkedFilesEditor.java | 47 ++++++++++++------- .../LinkedFilesEditorViewModel.java | 9 ++-- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index 083c7717c9a..90a2b1b2f93 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -70,7 +70,7 @@ public static FieldEditorFX getForField(final Field field, } else if (field == StandardField.GROUPS) { return new GroupEditor(field, suggestionProvider, fieldCheckers, preferences, isMultiLine); } else if (fieldProperties.contains(FieldProperty.FILE_EDITOR)) { - return new LinkedFilesEditor(field, dialogService, databaseContext, taskExecutor, suggestionProvider, fieldCheckers, preferences); + return new LinkedFilesEditor(field, databaseContext, suggestionProvider, fieldCheckers); } else if (fieldProperties.contains(FieldProperty.YES_NO)) { return new OptionEditor<>(new YesNoEditorViewModel(field, suggestionProvider, fieldCheckers)); } else if (fieldProperties.contains(FieldProperty.MONTH)) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.fxml b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.fxml index 5f61cfd109c..f73bdc72290 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.fxml +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.fxml @@ -23,8 +23,7 @@