From fbe029094af16bd09c8bbfb59f75717e942842ec Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 16 Jul 2016 15:01:15 +0200 Subject: [PATCH 01/17] Some Globals.prefs injection in logic and model --- src/main/java/net/sf/jabref/JabRefMain.java | 2 +- .../net/sf/jabref/cli/ArgumentProcessor.java | 2 +- .../net/sf/jabref/external/AutoSetLinks.java | 2 +- .../jabref/external/DownloadExternalFile.java | 3 ++- .../jabref/external/DroppedFileHandler.java | 3 ++- .../sf/jabref/external/MoveFileAction.java | 2 +- .../java/net/sf/jabref/gui/BasePanel.java | 2 +- .../java/net/sf/jabref/gui/StringDialog.java | 2 +- .../jabref/gui/TransferableBibtexEntry.java | 3 ++- .../sf/jabref/gui/actions/CleanupAction.java | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 6 ++--- .../sf/jabref/gui/exporter/ExportAction.java | 2 +- .../jabref/gui/mergeentries/MergeEntries.java | 2 +- .../gui/plaintextimport/TextInputDialog.java | 3 ++- .../gui/preftabs/PreferencesDialog.java | 2 +- .../jabref/gui/worker/SendAsEMailAction.java | 3 ++- .../importer/fetcher/ACMPortalFetcher.java | 4 ++-- .../importer/fetcher/CiteSeerXFetcher.java | 3 ++- .../jabref/importer/fetcher/DBLPFetcher.java | 9 ++++--- .../fetcher/GoogleScholarFetcher.java | 13 ++++++---- .../importer/fetcher/IEEEXploreFetcher.java | 3 ++- .../fetcher/ScienceDirectFetcher.java | 3 ++- .../importer/fileformat/BibtexParser.java | 2 +- .../logic/bibtex/FieldContentParser.java | 6 ++--- .../logic/bibtex/LatexFieldFormatter.java | 24 ++++++++++--------- .../jabref/logic/cleanup/CleanupWorker.java | 9 +++++-- .../logic/cleanup/RenamePdfCleanup.java | 7 ++++-- .../logic/exporter/BibtexDatabaseWriter.java | 5 ++-- .../jabref/logic/exporter/ExportFormats.java | 6 ++--- .../logic/exporter/FileSaveSession.java | 4 +++- .../net/sf/jabref/logic/net/URLDownload.java | 6 ----- .../net/sf/jabref/logic/util/io/FileUtil.java | 9 +++---- .../java/net/sf/jabref/logic/xmp/XMPUtil.java | 2 +- .../logic/bibtex/BibEntryWriterTest.java | 2 +- .../logic/bibtex/FieldContentParserTest.java | 2 +- .../bibtex/LatexFieldFormatterTests.java | 2 +- .../logic/cleanup/CleanupWorkerTest.java | 2 +- .../logic/cleanup/RenamePdfCleanupTest.java | 12 ++++++---- .../logic/exporter/ExportFormatTest.java | 2 +- .../logic/exporter/HtmlExportFormatTest.java | 2 +- .../sf/jabref/logic/net/URLDownloadTest.java | 3 ++- .../sf/jabref/logic/util/io/FileUtilTest.java | 8 ++++--- .../logic/util/io/UtilFindFileTest.java | 3 ++- .../net/sf/jabref/logic/xmp/XMPUtilTest.java | 2 +- 44 files changed, 113 insertions(+), 83 deletions(-) diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 48329e11b43..314dcc10eae 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -66,7 +66,7 @@ private static void start(String[] args) { /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); CustomEntryTypesManager.loadCustomEntryTypes(preferences); - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index cfc25c77d11..00c725d58dd 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -390,7 +390,7 @@ private void importPreferences() { try { Globals.prefs.importPreferences(cli.getPreferencesImport()); CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs); - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); } catch (JabRefException ex) { LOGGER.error("Cannot import preferences", ex); } diff --git a/src/main/java/net/sf/jabref/external/AutoSetLinks.java b/src/main/java/net/sf/jabref/external/AutoSetLinks.java index 7346c9e4861..41968bced88 100644 --- a/src/main/java/net/sf/jabref/external/AutoSetLinks.java +++ b/src/main/java/net/sf/jabref/external/AutoSetLinks.java @@ -104,7 +104,7 @@ public void run() { String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY); result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp); } else { - result = FileUtil.findAssociatedFiles(entries, extensions, dirs); + result = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs); } boolean foundAny = false; diff --git a/src/main/java/net/sf/jabref/external/DownloadExternalFile.java b/src/main/java/net/sf/jabref/external/DownloadExternalFile.java index 12cc76d7ee4..450fc458d37 100644 --- a/src/main/java/net/sf/jabref/external/DownloadExternalFile.java +++ b/src/main/java/net/sf/jabref/external/DownloadExternalFile.java @@ -270,7 +270,8 @@ private void downloadFinished() { // FIXME: will break download if no bibtexkey is present! private String getSuggestedFileName(String suffix) { String plannedName = FileUtil.createFileNameFromPattern(databaseContext.getDatabase(), - frame.getCurrentBasePanel().getSelectedEntries().get(0), Globals.journalAbbreviationLoader); + frame.getCurrentBasePanel().getSelectedEntries().get(0), Globals.journalAbbreviationLoader, + Globals.prefs); if (!suffix.isEmpty()) { plannedName += "." + suffix; diff --git a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java index 83c166f7caf..a48ce0c4de7 100644 --- a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java +++ b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java @@ -350,7 +350,8 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy renameCheckBox.setText(Localization.lang("Rename file to").concat(": ")); // Determine which name to suggest: - String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader); + String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader, + Globals.prefs); renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension())); diff --git a/src/main/java/net/sf/jabref/external/MoveFileAction.java b/src/main/java/net/sf/jabref/external/MoveFileAction.java index d39339c4b05..b4bc662daa2 100644 --- a/src/main/java/net/sf/jabref/external/MoveFileAction.java +++ b/src/main/java/net/sf/jabref/external/MoveFileAction.java @@ -112,7 +112,7 @@ public void actionPerformed(ActionEvent event) { // Determine which name to suggest: String suggName = FileUtil .createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(), - Globals.journalAbbreviationLoader) + Globals.journalAbbreviationLoader, Globals.prefs) .concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : ""); CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"), Localization.lang("Rename to '%0'", suggName), diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index bf221b40085..620fc43e76e 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -2425,7 +2425,7 @@ public Optional searchAndOpen() { String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY); result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp); } else { - result = FileUtil.findAssociatedFiles(entries, extensions, dirs); + result = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs); } if (result.containsKey(entry)) { final List res = result.get(entry); diff --git a/src/main/java/net/sf/jabref/gui/StringDialog.java b/src/main/java/net/sf/jabref/gui/StringDialog.java index a0c6f607463..8e2dab96fc2 100644 --- a/src/main/java/net/sf/jabref/gui/StringDialog.java +++ b/src/main/java/net/sf/jabref/gui/StringDialog.java @@ -266,7 +266,7 @@ public void setValueAt(Object value, int row, int col) { if (!value.equals(subject.getContent())) { try { - new LatexFieldFormatter().format((String) value, "__dummy"); + new LatexFieldFormatter(Globals.prefs).format((String) value, "__dummy"); } catch (IllegalArgumentException ex) { return; } diff --git a/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java b/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java index e156548f28a..2bfa4b9acae 100644 --- a/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java +++ b/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java @@ -24,6 +24,7 @@ import javax.swing.JOptionPane; +import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; import net.sf.jabref.logic.l10n.Localization; @@ -63,7 +64,7 @@ public Object getTransferData(DataFlavor flavor) } else if (flavor.equals(DataFlavor.stringFlavor)) { try { StringWriter sw = new StringWriter(); - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), false); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false); for (BibEntry entry : data) { bibtexEntryWriter.write(entry, sw, BibDatabaseMode.BIBTEX); } diff --git a/src/main/java/net/sf/jabref/gui/actions/CleanupAction.java b/src/main/java/net/sf/jabref/gui/actions/CleanupAction.java index a41b5b68d16..dca00432fa4 100644 --- a/src/main/java/net/sf/jabref/gui/actions/CleanupAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/CleanupAction.java @@ -161,7 +161,7 @@ private int showDialog(CleanupPresetPanel presetPanel) { private void doCleanup(CleanupPreset preset, BibEntry entry, NamedCompound ce) { // Create and run cleaner BibDatabaseContext bibDatabaseContext = panel.getBibDatabaseContext(); - CleanupWorker cleaner = new CleanupWorker(bibDatabaseContext, Globals.journalAbbreviationLoader); + CleanupWorker cleaner = new CleanupWorker(bibDatabaseContext, Globals.journalAbbreviationLoader, Globals.prefs); List changes = cleaner.cleanup(preset, entry); unsuccessfulRenames = cleaner.getUnsuccessfulRenames(); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 95ee322e314..4e171b98be7 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -592,7 +592,7 @@ public void updateSource() { public static String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException { StringWriter stringWriter = new StringWriter(200); - LatexFieldFormatter formatter = LatexFieldFormatter.buildIgnoreHashes(); + LatexFieldFormatter formatter = LatexFieldFormatter.buildIgnoreHashes(Globals.prefs); new BibEntryWriter(formatter, false).writeWithoutPrependedNewlines(entry, stringWriter, type); return stringWriter.getBuffer().toString(); @@ -813,7 +813,7 @@ private boolean storeSource() { String newValue = newEntry.getField(field); if (!Objects.equals(oldValue, newValue)) { // Test if the field is legally set. - new LatexFieldFormatter().format(newValue, field); + new LatexFieldFormatter(Globals.prefs).format(newValue, field); compound.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); entry.setField(field, newValue); @@ -1167,7 +1167,7 @@ public void actionPerformed(ActionEvent event) { // properly formatted. If that happens, the field // is not stored and the textarea turns red. if (toSet != null) { - new LatexFieldFormatter().format(toSet, fieldEditor.getFieldName()); + new LatexFieldFormatter(Globals.prefs).format(toSet, fieldEditor.getFieldName()); } String oldValue = entry.getField(fieldEditor.getFieldName()); diff --git a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java index 6df4e75a6ab..30324aee781 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java @@ -59,7 +59,7 @@ public InternalExportAction(JabRefFrame frame, boolean selectedOnly) { @Override public void actionPerformed(ActionEvent e) { - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); JFileChooser fc = ExportAction .createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); fc.showSaveDialog(frame); diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java index 7bdf6b01caa..73a426e8432 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java @@ -452,7 +452,7 @@ private void updateAll() { // Update the BibTeX source view StringWriter writer = new StringWriter(); try { - new BibEntryWriter(new LatexFieldFormatter(), false).write(mergedEntry, writer, databaseType); + new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(mergedEntry, writer, databaseType); } catch (IOException ex) { LOGGER.error("Error in entry", ex); } diff --git a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java index d324fdc2709..12c78b11842 100644 --- a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java @@ -537,7 +537,8 @@ private boolean parseWithFreeCiteAndAddEntries() { private void updateSourceView() { StringWriter sw = new StringWriter(200); try { - new BibEntryWriter(new LatexFieldFormatter(), false).write(entry, sw, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); + new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(entry, sw, + frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); sourcePreview.setText(sw.getBuffer().toString()); } catch (IOException ex) { LOGGER.error("Error in entry" + ": " + ex.getMessage(), ex); diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index c3b33ac699e..1dd512d4cfe 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -236,7 +236,7 @@ public PreferencesDialog(JabRefFrame parent) { private void updateAfterPreferenceChanges() { setValues(); - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); frame.removeCachedEntryEditors(); Globals.prefs.updateEntryEditorTabList(); } diff --git a/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java b/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java index 5f93c7ea2ee..33322e5e461 100644 --- a/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java +++ b/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +import net.sf.jabref.Globals; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.desktop.JabRefDesktop; @@ -79,7 +80,7 @@ public void run() { List bes = panel.getSelectedEntries(); // write the entries using sw, which is used later to form the email content - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), true); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); for (BibEntry entry : bes) { try { diff --git a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java index 6317ea3733c..4d019069515 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java @@ -143,7 +143,7 @@ public boolean processQueryGetPreview(String query, FetcherPreviewDialog preview try { URLDownload dl = new URLDownload(address); - String page = dl.downloadToString(); + String page = dl.downloadToString(Globals.prefs.getDefaultEncoding()); int hits = getNumberOfHits(page, RESULTS_FOUND_PATTERN, ACMPortalFetcher.HITS_PATTERN); @@ -351,7 +351,7 @@ private static Optional downloadEntryBibTeX(String id, boolean downloa // get abstract if (downloadAbstract) { URLDownload dl = new URLDownload(ACMPortalFetcher.START_URL + ACMPortalFetcher.ABSTRACT_URL + id); - String page = dl.downloadToString(); + String page = dl.downloadToString(Globals.prefs.getDefaultEncoding()); Matcher absM = ACMPortalFetcher.ABSTRACT_PATTERN.matcher(page); if (absM.find()) { diff --git a/src/main/java/net/sf/jabref/importer/fetcher/CiteSeerXFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/CiteSeerXFetcher.java index 0b6a3f0a2e3..29d9e8aa8f4 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/CiteSeerXFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/CiteSeerXFetcher.java @@ -25,6 +25,7 @@ import javax.swing.JPanel; +import net.sf.jabref.Globals; import net.sf.jabref.gui.help.HelpFile; import net.sf.jabref.importer.ImportInspector; import net.sf.jabref.importer.OutputPrinter; @@ -127,7 +128,7 @@ private List getCitations(String query) throws IOException { } private static String getCitationsFromUrl(String urlQuery, List ids) throws IOException { - String cont = new URLDownload(urlQuery).downloadToString(); + String cont = new URLDownload(urlQuery).downloadToString(Globals.prefs.getDefaultEncoding()); Matcher m = CiteSeerXFetcher.CITE_LINK_PATTERN.matcher(cont); while (m.find()) { ids.add(CiteSeerXFetcher.URL_START + m.group(1)); diff --git a/src/main/java/net/sf/jabref/importer/fetcher/DBLPFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/DBLPFetcher.java index 119e5d8a781..320b47b07e5 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/DBLPFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/DBLPFetcher.java @@ -24,6 +24,7 @@ import javax.swing.JPanel; +import net.sf.jabref.Globals; import net.sf.jabref.gui.help.HelpFile; import net.sf.jabref.importer.ImportInspector; import net.sf.jabref.importer.OutputPrinter; @@ -74,7 +75,7 @@ public boolean processQuery(String newQuery, ImportInspector inspector, String address = makeSearchURL(); URLDownload dl = new URLDownload(address); - String page = dl.downloadToString(); + String page = dl.downloadToString(Globals.prefs.getDefaultEncoding()); String[] lines = page.split("\n"); List bibtexUrlList = new ArrayList<>(); @@ -100,7 +101,8 @@ public boolean processQuery(String newQuery, ImportInspector inspector, break; } - final String bibtexHTMLPage = new URLDownload(urlStr).downloadToString(); + final String bibtexHTMLPage = new URLDownload(urlStr) + .downloadToString(Globals.prefs.getDefaultEncoding()); final String[] htmlLines = bibtexHTMLPage.split("\n"); @@ -114,7 +116,8 @@ public boolean processQuery(String newQuery, ImportInspector inspector, // we do not access dblp.uni-trier.de as they will complain bibtexUrl = bibtexUrl.replace("dblp.uni-trier.de", "www.dblp.org"); - final String bibtexPage = new URLDownload(bibtexUrl).downloadToString(); + final String bibtexPage = new URLDownload(bibtexUrl) + .downloadToString(Globals.prefs.getDefaultEncoding()); Collection bibtexEntries = BibtexParser.fromString(bibtexPage); diff --git a/src/main/java/net/sf/jabref/importer/fetcher/GoogleScholarFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/GoogleScholarFetcher.java index 6f22e69a30d..2a1a26934ae 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/GoogleScholarFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/GoogleScholarFetcher.java @@ -32,6 +32,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; +import net.sf.jabref.Globals; import net.sf.jabref.gui.FetcherPreviewDialog; import net.sf.jabref.gui.help.HelpFile; import net.sf.jabref.importer.ImportInspector; @@ -173,9 +174,10 @@ public void stopFetching() { private static void runConfig() throws IOException { try { - new URLDownload("http://scholar.google.com").downloadToString(); + new URLDownload("http://scholar.google.com").downloadToString(Globals.prefs.getDefaultEncoding()); //save("setting.html", ud.getStringContent()); - String settingsPage = new URLDownload(GoogleScholarFetcher.URL_SETTING).downloadToString(); + String settingsPage = new URLDownload(GoogleScholarFetcher.URL_SETTING) + .downloadToString(Globals.prefs.getDefaultEncoding()); // Get the form items and their values from the page: Map formItems = GoogleScholarFetcher.getFormElements(settingsPage); // Override the important ones: @@ -185,7 +187,7 @@ private static void runConfig() throws IOException { String request = formItems.entrySet().stream().map(Object::toString) .collect(Collectors.joining("&", GoogleScholarFetcher.URL_SETPREFS + "?", "&submit=")); // Download the URL to set preferences: - new URLDownload(request).downloadToString(); + new URLDownload(request).downloadToString(Globals.prefs.getDefaultEncoding()); } catch (UnsupportedEncodingException ex) { LOGGER.error("Unsupported encoding.", ex); @@ -216,7 +218,7 @@ private Map getCitations(String query) throws IOException { } private String getCitationsFromUrl(String urlQuery, Map ids) throws IOException { - String cont = new URLDownload(urlQuery).downloadToString(); + String cont = new URLDownload(urlQuery).downloadToString(Globals.prefs.getDefaultEncoding()); Matcher m = GoogleScholarFetcher.BIBTEX_LINK_PATTERN.matcher(cont); int lastRegionStart = 0; @@ -263,7 +265,8 @@ private String getCitationsFromUrl(String urlQuery, Map ids) thr private BibEntry downloadEntry(String link) throws IOException { try { - String s = new URLDownload(GoogleScholarFetcher.URL_START + link).downloadToString(); + String s = new URLDownload(GoogleScholarFetcher.URL_START + link) + .downloadToString(Globals.prefs.getDefaultEncoding()); BibtexParser bp = new BibtexParser(new StringReader(s)); ParserResult pr = bp.parse(); if ((pr != null) && (pr.getDatabase() != null)) { diff --git a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java index 7b5617d28d4..44495c2deaf 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java @@ -156,7 +156,8 @@ public boolean processQuery(String query, ImportInspector dialog, OutputPrinter } //fetch the raw Bibtex results from IEEEXplore - String bibtexPage = new URLDownload(createBibtexQueryURL(searchResultsJson)).downloadToString(); + String bibtexPage = new URLDownload(createBibtexQueryURL(searchResultsJson)) + .downloadToString(Globals.prefs.getDefaultEncoding()); //preprocess the result (eg. convert HTML escaped characters to latex and do other formatting not performed by BibtexParser) bibtexPage = preprocessBibtexResultsPage(bibtexPage); diff --git a/src/main/java/net/sf/jabref/importer/fetcher/ScienceDirectFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/ScienceDirectFetcher.java index 54478da2734..6fc7724a625 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/ScienceDirectFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/ScienceDirectFetcher.java @@ -26,6 +26,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; +import net.sf.jabref.Globals; import net.sf.jabref.gui.help.HelpFile; import net.sf.jabref.importer.ImportInspector; import net.sf.jabref.importer.OutputPrinter; @@ -135,7 +136,7 @@ private static List getCitations(String query) throws IOException { } private static String getCitationsFromUrl(String urlQuery, List ids) throws IOException { - String cont = new URLDownload(urlQuery).downloadToString(); + String cont = new URLDownload(urlQuery).downloadToString(Globals.prefs.getDefaultEncoding()); Matcher m = ScienceDirectFetcher.LINK_PATTERN.matcher(cont); if (m.find()) { while (m.find()) { diff --git a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java index 253bf298601..2ea8650458e 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java @@ -70,7 +70,7 @@ public class BibtexParser { private Map entryTypes; private boolean eof; private int line = 1; - private final FieldContentParser fieldContentParser = new FieldContentParser(); + private final FieldContentParser fieldContentParser = new FieldContentParser(Globals.prefs); private ParserResult parserResult; private static final Integer LOOKAHEAD = 64; private final Deque pureTextFromFile = new LinkedList<>(); diff --git a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java index e52c0be187b..cd3f6d25de3 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.regex.Pattern; -import net.sf.jabref.Globals; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.preferences.JabRefPreferences; @@ -34,13 +33,14 @@ public class FieldContentParser { // 's' matches a space, tab, new line, carriage return. private static final Pattern WHITESPACE = Pattern.compile("\\s+"); - public FieldContentParser() { + + public FieldContentParser(JabRefPreferences prefs) { multiLineFields = new HashSet<>(); // the following two are also coded in net.sf.jabref.logic.bibtex.LatexFieldFormatter.format(String, String) multiLineFields.add("abstract"); multiLineFields.add("review"); // the file field should not be formatted, therefore we treat it as a multi line field - List nonWrappableFields = Globals.prefs.getStringList(JabRefPreferences.NON_WRAPPABLE_FIELDS); + List nonWrappableFields = prefs.getStringList(JabRefPreferences.NON_WRAPPABLE_FIELDS); multiLineFields.addAll(nonWrappableFields); } diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java index 347bdcbffe9..f223a4af80a 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java @@ -45,28 +45,30 @@ public class LatexFieldFormatter { private final char valueDelimiterEndOfValue; private final List doNotResolveStringsFors; private final int lineLength; + private final JabRefPreferences prefs; private final FieldContentParser parser; - public LatexFieldFormatter() { - this(true); + public LatexFieldFormatter(JabRefPreferences prefs) { + this(true, prefs); } - private LatexFieldFormatter(boolean neverFailOnHashes) { + private LatexFieldFormatter(boolean neverFailOnHashes, JabRefPreferences prefs) { this.neverFailOnHashes = neverFailOnHashes; + this.prefs = prefs; - this.resolveStringsAllFields = Globals.prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS); - valueDelimiterStartOfValue = Globals.prefs.getValueDelimiters(0); - valueDelimiterEndOfValue = Globals.prefs.getValueDelimiters(1); - doNotResolveStringsFors = Globals.prefs.getStringList(JabRefPreferences.DO_NOT_RESOLVE_STRINGS_FOR); - lineLength = Globals.prefs.getInt(JabRefPreferences.LINE_LENGTH); + this.resolveStringsAllFields = prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS); + valueDelimiterStartOfValue = prefs.getValueDelimiters(0); + valueDelimiterEndOfValue = prefs.getValueDelimiters(1); + doNotResolveStringsFors = prefs.getStringList(JabRefPreferences.DO_NOT_RESOLVE_STRINGS_FOR); + lineLength = prefs.getInt(JabRefPreferences.LINE_LENGTH); - parser = new FieldContentParser(); + parser = new FieldContentParser(prefs); } - public static LatexFieldFormatter buildIgnoreHashes() { - return new LatexFieldFormatter(true); + public static LatexFieldFormatter buildIgnoreHashes(JabRefPreferences prefs) { + return new LatexFieldFormatter(true, prefs); } /** diff --git a/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java b/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java index 8c6c8edee18..697388170bb 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java @@ -20,6 +20,7 @@ import java.util.Objects; import net.sf.jabref.BibDatabaseContext; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; @@ -28,11 +29,15 @@ public class CleanupWorker { private final BibDatabaseContext databaseContext; private final JournalAbbreviationLoader repositoryLoader; + private final JabRefPreferences prefs; private int unsuccessfulRenames; - public CleanupWorker(BibDatabaseContext databaseContext, JournalAbbreviationLoader repositoryLoader) { + + public CleanupWorker(BibDatabaseContext databaseContext, JournalAbbreviationLoader repositoryLoader, + JabRefPreferences prefs) { this.databaseContext = databaseContext; this.repositoryLoader = repositoryLoader; + this.prefs = prefs; } public int getUnsuccessfulRenames() { @@ -73,7 +78,7 @@ private List determineCleanupActions(CleanupPreset preset) { } if (preset.isRenamePDF()) { RenamePdfCleanup cleaner = new RenamePdfCleanup(preset.isRenamePdfOnlyRelativePaths(), databaseContext, - repositoryLoader); + repositoryLoader, prefs); jobs.add(cleaner); unsuccessfulRenames += cleaner.getUnsuccessfulRenames(); } diff --git a/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java index 534824abb78..e619e938867 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java @@ -21,6 +21,7 @@ import java.util.Optional; import net.sf.jabref.BibDatabaseContext; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.TypedBibEntry; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.util.io.FileUtil; @@ -33,14 +34,16 @@ public class RenamePdfCleanup implements CleanupJob { private final BibDatabaseContext databaseContext; private final boolean onlyRelativePaths; private final JournalAbbreviationLoader repositoryLoader; + private final JabRefPreferences prefs; private int unsuccessfulRenames; public RenamePdfCleanup(boolean onlyRelativePaths, BibDatabaseContext databaseContext, - JournalAbbreviationLoader repositoryLoader) { + JournalAbbreviationLoader repositoryLoader, JabRefPreferences prefs) { this.databaseContext = Objects.requireNonNull(databaseContext); this.onlyRelativePaths = onlyRelativePaths; this.repositoryLoader = Objects.requireNonNull(repositoryLoader); + this.prefs = Objects.requireNonNull(prefs); } @Override @@ -59,7 +62,7 @@ public List cleanup(BibEntry entry) { } StringBuilder newFilename = new StringBuilder( - FileUtil.createFileNameFromPattern(databaseContext.getDatabase(), entry, repositoryLoader)); + FileUtil.createFileNameFromPattern(databaseContext.getDatabase(), entry, repositoryLoader, prefs)); //Add extension to newFilename newFilename.append('.').append(FileUtil.getFileExtension(realOldFilename).orElse("pdf")); diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index 1141323cf3b..7e014197794 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -109,7 +109,8 @@ protected void writeString(BibtexString bibtexString, boolean isFirstString, int getWriter().write("{}"); } else { try { - String formatted = new LatexFieldFormatter().format(bibtexString.getContent(), LatexFieldFormatter.BIBTEX_STRING); + String formatted = new LatexFieldFormatter(Globals.prefs).format(bibtexString.getContent(), + LatexFieldFormatter.BIBTEX_STRING); getWriter().write(formatted); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException( @@ -154,7 +155,7 @@ protected void writePrelogue(BibDatabaseContext bibDatabaseContext, Charset enco @Override protected void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile) throws SaveException { - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), true); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); try { bibtexEntryWriter.write(entry, getWriter(), mode, isReformatFile); } catch (IOException e) { diff --git a/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java index f5b1de8a3ea..948678dd264 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java @@ -20,7 +20,7 @@ import java.util.Map; import java.util.TreeMap; -import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.l10n.Localization; public class ExportFormats { @@ -31,7 +31,7 @@ public class ExportFormats { public static int entryNumber; - public static void initAllExports() { + public static void initAllExports(JabRefPreferences prefs) { ExportFormats.EXPORT_FORMATS.clear(); @@ -66,7 +66,7 @@ public static void initAllExports() { ExportFormats.putFormat(new ModsExportFormat()); // Now add custom export formats - Map customFormats = Globals.prefs.customExports.getCustomExportFormats(); + Map customFormats = prefs.customExports.getCustomExportFormats(); for (IExportFormat format : customFormats.values()) { ExportFormats.putFormat(format); } diff --git a/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java index c3a7d784607..1a44cb32d9d 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java +++ b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java @@ -56,11 +56,13 @@ public class FileSaveSession extends SaveSession { private final boolean useLockFile; private final Path temporaryFile; + public FileSaveSession(Charset encoding, boolean backup) throws SaveException { this(encoding, backup, createTemporaryFile()); } - public FileSaveSession(Charset encoding, boolean backup, Path temporaryFile) throws SaveException { + public FileSaveSession(Charset encoding, boolean backup, Path temporaryFile) + throws SaveException { super(encoding, backup, getWriterForFile(encoding, temporaryFile)); this.temporaryFile = temporaryFile; this.useLockFile = Globals.prefs.getBoolean(JabRefPreferences.USE_LOCK_FILES); diff --git a/src/main/java/net/sf/jabref/logic/net/URLDownload.java b/src/main/java/net/sf/jabref/logic/net/URLDownload.java index c6fbb6bc2b6..e942ebca67b 100644 --- a/src/main/java/net/sf/jabref/logic/net/URLDownload.java +++ b/src/main/java/net/sf/jabref/logic/net/URLDownload.java @@ -36,8 +36,6 @@ import java.util.HashMap; import java.util.Map; -import net.sf.jabref.Globals; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -143,14 +141,10 @@ private URLConnection openConnection() throws IOException { } /** - * Encoding will be determined from JabRefPreferences.DEFAULT_ENCODING * * @return the downloaded string * @throws IOException */ - public String downloadToString() throws IOException { - return downloadToString(Globals.prefs.getDefaultEncoding()); - } public String downloadToString(Charset encoding) throws IOException { diff --git a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java index 126d1d82a0f..51c274be0c9 100644 --- a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java +++ b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java @@ -317,7 +317,8 @@ private static File shortenFileName(File fileName, String directory) { } } - public static Map> findAssociatedFiles(Collection entries, Collection extensions, Collection directories) { + public static Map> findAssociatedFiles(Collection entries, + Collection extensions, Collection directories, JabRefPreferences prefs) { Map> result = new HashMap<>(); // First scan directories @@ -328,7 +329,7 @@ public static Map> findAssociatedFiles(Collection result.put(entry, new ArrayList<>()); } - boolean exactOnly = Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY); + boolean exactOnly = prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY); // Now look for keys nextFile: for (File file : filesWithExtension) { @@ -392,9 +393,9 @@ public static List getListOfLinkedFiles(List bes, List f * @return a suggested fileName */ public static String createFileNameFromPattern(BibDatabase database, BibEntry entry, - JournalAbbreviationLoader repositoryLoader) { + JournalAbbreviationLoader repositoryLoader, JabRefPreferences prefs) { String targetName = entry.getCiteKey() == null ? "default" : entry.getCiteKey(); - StringReader sr = new StringReader(Globals.prefs.get(JabRefPreferences.PREF_IMPORT_FILENAMEPATTERN)); + StringReader sr = new StringReader(prefs.get(JabRefPreferences.PREF_IMPORT_FILENAMEPATTERN)); Layout layout = null; try { layout = new LayoutHelper(sr, repositoryLoader).getLayoutFromText(); diff --git a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java index 23fed90a703..724d6c83363 100644 --- a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java +++ b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java @@ -1189,7 +1189,7 @@ public static void main(String[] args) throws IOException, TransformerException // Read from pdf and write as BibTex List l = XMPUtil.readXMP(new File(args[0])); - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), false); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false); for (BibEntry entry : l) { StringWriter sw = new StringWriter(); diff --git a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java index e8fcbc0ca7f..398ade15e58 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java @@ -39,7 +39,7 @@ public static void tearDown() { @Before public void setUpWriter() { - writer = new BibEntryWriter(new LatexFieldFormatter(), true); + writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); } @Test diff --git a/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java b/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java index 47a8fd30d36..64937e9bce9 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java @@ -20,7 +20,7 @@ public static void loadPreferences() { @Before public void setUp() throws Exception { - parser = new FieldContentParser(); + parser = new FieldContentParser(Globals.prefs); } @Test diff --git a/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java b/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java index 815e2c14afe..db50abccaf0 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java @@ -20,7 +20,7 @@ public static void setUpBeforeClass(){ @Before public void setUp() { - this.formatter = new LatexFieldFormatter(); + this.formatter = new LatexFieldFormatter(Globals.prefs); } @Test diff --git a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java index 4fef99dfbbe..91d81b055b5 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java @@ -59,7 +59,7 @@ public void setUp() throws IOException { MetaData metaData = new MetaData(); metaData.setDefaultFileDirectory(pdfFolder.getAbsolutePath()); BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(), metaData, bibFolder.newFile("test.bib")); - worker = new CleanupWorker(context, mock(JournalAbbreviationLoader.class)); + worker = new CleanupWorker(context, mock(JournalAbbreviationLoader.class), Globals.prefs); } diff --git a/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java b/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java index 3af23582600..8e49feb1010 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/RenamePdfCleanupTest.java @@ -54,7 +54,8 @@ public void cleanupRenamePdfRenamesFileEvenIfOnlyDifferenceIsCase() throws IOExc ParsedFileField fileField = new ParsedFileField("", tempFile.getAbsolutePath(), ""); entry.setField("file", FileField.getStringRepresentation(fileField)); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class)); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class), + Globals.prefs); cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot.tmp", ""); @@ -70,7 +71,8 @@ public void cleanupRenamePdfRenamesWithMultipleFiles() throws IOException { entry.setField("file", FileField.getStringRepresentation(Arrays.asList(new ParsedFileField("","",""), new ParsedFileField("", tempFile.getAbsolutePath(), ""), new ParsedFileField("","","")))); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class)); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class), + Globals.prefs); cleanup.cleanup(entry); assertEquals( @@ -87,7 +89,8 @@ public void cleanupRenamePdfRenamesFileStartingWithBibtexKey() throws IOExceptio entry.setField("file", FileField.getStringRepresentation(fileField)); entry.setField("title", "test title"); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class)); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class), + Globals.prefs); cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot - test title.tmp", ""); @@ -102,7 +105,8 @@ public void cleanupRenamePdfRenamesFileInSameFolder() throws IOException { entry.setField("file", FileField.getStringRepresentation(fileField)); entry.setField("title", "test title"); - RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class)); + RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, mock(JournalAbbreviationLoader.class), + Globals.prefs); cleanup.cleanup(entry); ParsedFileField newFileField = new ParsedFileField("", "Toot - test title.pdf", "PDF"); diff --git a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java index d180b377294..c0f5bfe61e5 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java @@ -78,7 +78,7 @@ public void testExportingNullEntriesThrowsNPE() throws Exception { public static Collection exportFormats() { Collection result = new ArrayList<>(); Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); for (IExportFormat format : ExportFormats.getExportFormats().values()) { result.add(new Object[] {format, format.getDisplayName()}); } diff --git a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java index 19fb08598f4..bccbdd86fe2 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java @@ -35,7 +35,7 @@ public class HtmlExportFormatTest { @Before public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(); + ExportFormats.initAllExports(Globals.prefs); exportFormat = ExportFormats.getExportFormat("html"); Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); diff --git a/src/test/java/net/sf/jabref/logic/net/URLDownloadTest.java b/src/test/java/net/sf/jabref/logic/net/URLDownloadTest.java index ffee836e282..1fbde9a3c61 100644 --- a/src/test/java/net/sf/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/net/sf/jabref/logic/net/URLDownloadTest.java @@ -27,7 +27,8 @@ public void testStringDownload() throws IOException { try { URLDownload dl = new URLDownload(new URL("http://www.google.com")); - Assert.assertTrue("google.com should contain google", dl.downloadToString().contains("Google")); + Assert.assertTrue("google.com should contain google", + dl.downloadToString(Globals.prefs.getDefaultEncoding()).contains("Google")); } finally { Globals.prefs = null; } diff --git a/src/test/java/net/sf/jabref/logic/util/io/FileUtilTest.java b/src/test/java/net/sf/jabref/logic/util/io/FileUtilTest.java index b778f48a1d7..c4af6d4784d 100644 --- a/src/test/java/net/sf/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/util/io/FileUtilTest.java @@ -40,7 +40,8 @@ public void testGetLinkedFileNameDefault() { entry.setCiteKey("1234"); entry.setField("title", "mytitle"); - assertEquals("1234 - mytitle", FileUtil.createFileNameFromPattern(null, entry, mock(JournalAbbreviationLoader.class))); + assertEquals("1234 - mytitle", + FileUtil.createFileNameFromPattern(null, entry, mock(JournalAbbreviationLoader.class), Globals.prefs)); } @Test @@ -52,7 +53,8 @@ public void testGetLinkedFileNameBibTeXKey() { entry.setCiteKey("1234"); entry.setField("title", "mytitle"); - assertEquals("1234", FileUtil.createFileNameFromPattern(null, entry, mock(JournalAbbreviationLoader.class))); + assertEquals("1234", + FileUtil.createFileNameFromPattern(null, entry, mock(JournalAbbreviationLoader.class), Globals.prefs)); } @Test @@ -128,5 +130,5 @@ public void uniquePathSubstrings() { assertEquals(uniqPath, result); } - + } diff --git a/src/test/java/net/sf/jabref/logic/util/io/UtilFindFileTest.java b/src/test/java/net/sf/jabref/logic/util/io/UtilFindFileTest.java index 56c38425ee2..b383ed53a5a 100644 --- a/src/test/java/net/sf/jabref/logic/util/io/UtilFindFileTest.java +++ b/src/test/java/net/sf/jabref/logic/util/io/UtilFindFileTest.java @@ -8,6 +8,7 @@ import java.util.Map; import net.sf.jabref.FileBasedTestCase; +import net.sf.jabref.Globals; import net.sf.jabref.model.entry.BibEntry; import org.junit.Assert; @@ -30,7 +31,7 @@ public void testFindAssociatedFiles() { Collection dirs = Arrays.asList(new File(root.getAbsoluteFile() + "/pdfs/"), new File(root.getAbsoluteFile() + "/graphicsDir/")); - Map> results = FileUtil.findAssociatedFiles(entries, extensions, dirs); + Map> results = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs); Assert.assertEquals(2, results.get(entry).size()); Assert.assertTrue( diff --git a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java index de3bd418474..aefa856097f 100644 --- a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java @@ -141,7 +141,7 @@ public static BibEntry bibtexString2BibtexEntry(String s) throws IOException { public static String bibtexEntry2BibtexString(BibEntry e) throws IOException { StringWriter sw = new StringWriter(); - new BibEntryWriter(new LatexFieldFormatter(), false).write(e, sw, BibDatabaseMode.BIBTEX); + new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(e, sw, BibDatabaseMode.BIBTEX); return sw.getBuffer().toString(); } From 3c4f11f845cf4b153af4393e7820dcb7545f2e3a Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 16 Jul 2016 17:12:39 +0200 Subject: [PATCH 02/17] Some more conversions and some fixes --- src/main/java/net/sf/jabref/JabRefMain.java | 2 +- .../java/net/sf/jabref/cli/ArgumentProcessor.java | 2 +- src/main/java/net/sf/jabref/gui/BasePanel.java | 4 ++-- .../net/sf/jabref/gui/ImportInspectionDialog.java | 4 ++-- .../net/sf/jabref/gui/entryeditor/EntryEditor.java | 3 ++- .../gui/labelpattern/SearchFixDuplicateLabels.java | 4 +++- .../net/sf/jabref/gui/preftabs/TablePrefsTab.java | 3 ++- .../jabref/importer/fileformat/FreeCiteImporter.java | 4 +++- .../sf/jabref/logic/bibtex/LatexFieldFormatter.java | 2 -- .../net/sf/jabref/logic/exporter/FileSaveSession.java | 4 +--- .../logic/journals/JournalAbbreviationLoader.java | 2 +- .../jabref/logic/labelpattern/LabelPatternUtil.java | 11 +++++------ .../sf/jabref/model/entry/InternalBibtexFields.java | 4 ++-- .../java/net/sf/jabref/pdfimport/PdfImporter.java | 7 ++++--- 14 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 314dcc10eae..794e5f3f8b8 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -61,7 +61,7 @@ private static void start(String[] args) { Globals.prefs.setLanguageDependentDefaultValues(); // Update which fields should be treated as numeric, based on preferences: - InternalBibtexFields.setNumericFieldsFromPrefs(); + InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs); /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 00c725d58dd..ff0a65db600 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -435,7 +435,7 @@ private void regenerateBibtexKeys(List loaded) { LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata")); for (BibEntry entry : database.getEntries()) { // try to make a new label - LabelPatternUtil.makeLabel(metaData, database, entry); + LabelPatternUtil.makeLabel(metaData, database, entry, Globals.prefs); } } else { LOGGER.info(Localization.lang("No meta data present in bibfile. Cannot regenerate BibTeX keys")); diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 620fc43e76e..18203f908e5 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -575,7 +575,7 @@ public void run() { // Finally, set the new keys: for (BibEntry entry : entries) { bes = entry; - LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes); + LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, Globals.prefs); ce.addEdit(new UndoableKeyChange(database, bes, (String) oldvals.get(bes), bes.getCiteKey())); } @@ -1987,7 +1987,7 @@ public void autoGenerateKeysBeforeSaving() { for (BibEntry bes : database.getEntries()) { String oldKey = bes.getCiteKey(); if ((oldKey == null) || oldKey.isEmpty()) { - LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes); + LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, Globals.prefs); ce.addEdit(new UndoableKeyChange(database, bes, null, bes.getCiteKey())); any = true; } diff --git a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java index 563b05d814e..61323de9134 100644 --- a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java +++ b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java @@ -461,7 +461,7 @@ private void generateKeySelectedEntry() { database.insertEntry(entry); // Generate a unique key: - LabelPatternUtil.makeLabel(localMetaData, database, entry); + LabelPatternUtil.makeLabel(localMetaData, database, entry, Globals.prefs); // Remove the entry from the database again, since we only added it in // order to // make sure the key was unique: @@ -502,7 +502,7 @@ private void generateKeys() { entry.setId(IdGenerator.next()); database.insertEntry(entry); - LabelPatternUtil.makeLabel(localMetaData, database, entry); + LabelPatternUtil.makeLabel(localMetaData, database, entry, Globals.prefs); // Add the generated key to our list: keys.add(entry.getCiteKey()); } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 4e171b98be7..bf7271cb8fe 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -1362,7 +1362,8 @@ public void actionPerformed(ActionEvent e) { } } - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry); + LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + Globals.prefs); // Store undo information: panel.getUndoManager().addEdit(new UndoableKeyChange(panel.getDatabase(), entry, (String) oldValue, entry.getCiteKey())); diff --git a/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java b/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java index 93031edd9a2..930b0e770ef 100644 --- a/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java +++ b/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java @@ -22,6 +22,7 @@ import javax.swing.JCheckBox; +import net.sf.jabref.Globals; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.undo.UndoableKeyChange; @@ -109,7 +110,8 @@ public void update() { NamedCompound ce = new NamedCompound(Localization.lang("Resolve duplicate BibTeX keys")); for (BibEntry entry : toGenerateFor) { String oldKey = entry.getCiteKey(); - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry); + LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + Globals.prefs); ce.addEdit(new UndoableKeyChange(panel.getDatabase(), entry, oldKey, entry.getCiteKey())); } ce.end(); diff --git a/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java b/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java index bf70ae85306..61b79f6d1c1 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java @@ -31,6 +31,7 @@ import javax.swing.JTable; import javax.swing.JTextField; +import net.sf.jabref.Globals; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.InternalBibtexFields; @@ -300,7 +301,7 @@ public void storeSettings() { } if (!Objects.equals(oldVal, newVal)) { prefs.put(JabRefPreferences.NUMERIC_FIELDS, newVal); - InternalBibtexFields.setNumericFieldsFromPrefs(); + InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs); } } diff --git a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java index ae766615b39..445d248f21f 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java @@ -213,7 +213,9 @@ public ParserResult importEntries(String text) { e.setType(type); // autogenerate label (BibTeX key) - LabelPatternUtil.makeLabel(JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext().getMetaData(), JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabase(), e); + LabelPatternUtil.makeLabel( + JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext().getMetaData(), + JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabase(), e, Globals.prefs); res.add(e); } diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java index f223a4af80a..9bb0a71d266 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java @@ -45,7 +45,6 @@ public class LatexFieldFormatter { private final char valueDelimiterEndOfValue; private final List doNotResolveStringsFors; private final int lineLength; - private final JabRefPreferences prefs; private final FieldContentParser parser; @@ -56,7 +55,6 @@ public LatexFieldFormatter(JabRefPreferences prefs) { private LatexFieldFormatter(boolean neverFailOnHashes, JabRefPreferences prefs) { this.neverFailOnHashes = neverFailOnHashes; - this.prefs = prefs; this.resolveStringsAllFields = prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS); valueDelimiterStartOfValue = prefs.getValueDelimiters(0); diff --git a/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java index 1a44cb32d9d..c3a7d784607 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java +++ b/src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java @@ -56,13 +56,11 @@ public class FileSaveSession extends SaveSession { private final boolean useLockFile; private final Path temporaryFile; - public FileSaveSession(Charset encoding, boolean backup) throws SaveException { this(encoding, backup, createTemporaryFile()); } - public FileSaveSession(Charset encoding, boolean backup, Path temporaryFile) - throws SaveException { + public FileSaveSession(Charset encoding, boolean backup, Path temporaryFile) throws SaveException { super(encoding, backup, getWriterForFile(encoding, temporaryFile)); this.temporaryFile = temporaryFile; this.useLockFile = Globals.prefs.getBoolean(JabRefPreferences.USE_LOCK_FILES); diff --git a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java index a42cd306422..1e303877258 100644 --- a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java @@ -74,7 +74,7 @@ public void update(JabRefPreferences jabRefPreferences) { if ((personalJournalList != null) && !personalJournalList.trim().isEmpty()) { try { journalAbbrev.addEntries( - readJournalListFromFile(new File(personalJournalList), Globals.prefs.getDefaultEncoding())); + readJournalListFromFile(new File(personalJournalList), jabRefPreferences.getDefaultEncoding())); } catch (FileNotFoundException e) { LOGGER.info("Personal journal list file '" + personalJournalList + "' not found.", e); } diff --git a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java b/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java index 555bb8c6f6a..c3644704188 100644 --- a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java +++ b/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java @@ -26,7 +26,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sf.jabref.Globals; import net.sf.jabref.MetaData; import net.sf.jabref.logic.formatter.casechanger.Word; import net.sf.jabref.logic.layout.format.RemoveLatexCommands; @@ -427,7 +426,7 @@ public static List split(String labelPattern) { * @param entry a BibEntry * @return modified BibEntry */ - public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entry) { + public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entry, JabRefPreferences prefs) { database = dBase; String key; StringBuilder stringBuilder = new StringBuilder(); @@ -474,9 +473,9 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr key = checkLegalKey(stringBuilder.toString()); // Remove Regular Expressions while generating Keys - String regex = Globals.prefs.get(JabRefPreferences.KEY_PATTERN_REGEX); + String regex = prefs.get(JabRefPreferences.KEY_PATTERN_REGEX); if ((regex != null) && !regex.trim().isEmpty()) { - String replacement = Globals.prefs.get(JabRefPreferences.KEY_PATTERN_REPLACEMENT); + String replacement = prefs.get(JabRefPreferences.KEY_PATTERN_REPLACEMENT); key = key.replaceAll(regex, replacement); } @@ -494,8 +493,8 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr occurrences--; // No change, so we can accept one dupe. } - boolean alwaysAddLetter = Globals.prefs.getBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER); - boolean firstLetterA = Globals.prefs.getBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A); + boolean alwaysAddLetter = prefs.getBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER); + boolean firstLetterA = prefs.getBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A); if (!alwaysAddLetter && (occurrences == 0)) { // No dupes found, so we can just go ahead. diff --git a/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java b/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java index c584b1aee72..a01198434e4 100644 --- a/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java +++ b/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java @@ -321,8 +321,8 @@ private InternalBibtexFields() { * sorting for all fields listed in the array. If an unknown field name is included, * add a field descriptor for the new field. */ - public static void setNumericFieldsFromPrefs() { - List numFields = Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS); + public static void setNumericFieldsFromPrefs(JabRefPreferences prefs) { + List numFields = prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS); if (numFields.isEmpty()) { return; } diff --git a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java index 818a4104576..a9fbb506f7f 100644 --- a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java @@ -58,8 +58,8 @@ public class PdfImporter { private final JabRefFrame frame; private final BasePanel panel; - private MainTable entryTable; - private int dropRow; + private final MainTable entryTable; + private final int dropRow; private static final Log LOGGER = LogFactory.getLog(PdfImporter.class); @@ -250,7 +250,8 @@ private void doContentImport(String fileName, List res) { // insert entry to database and link file panel.getDatabase().insertEntry(entry); panel.markBaseChanged(); - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry); + LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + Globals.prefs); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entry); panel.highlightEntry(entry); From e33ba3e4ba18e0ea65683cd465fb5f067d160aa9 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 16 Jul 2016 22:19:07 +0200 Subject: [PATCH 03/17] More injections --- src/main/java/net/sf/jabref/JabRefMain.java | 2 +- .../net/sf/jabref/cli/ArgumentProcessor.java | 2 +- .../jabref/external/DroppedFileHandler.java | 2 +- .../gui/actions/ManageKeywordsAction.java | 4 +- .../sf/jabref/gui/exporter/ExportAction.java | 2 +- .../gui/plaintextimport/TextInputDialog.java | 2 +- .../gui/preftabs/PreferencesDialog.java | 2 +- .../jabref/importer/EntryFromPDFCreator.java | 3 +- .../importer/fileformat/BibtexParser.java | 3 +- .../importer/fileformat/JSONEntryParser.java | 4 +- .../importer/fileformat/PdfXmpImporter.java | 5 +- .../importer/fileformat/RepecNepImporter.java | 5 +- .../jabref/logic/exporter/ExportFormats.java | 4 +- .../java/net/sf/jabref/logic/xmp/XMPUtil.java | 31 ++++----- .../net/sf/jabref/model/entry/BibEntry.java | 14 ++-- .../net/sf/jabref/pdfimport/PdfImporter.java | 2 +- .../specialfields/SpecialFieldsUtils.java | 4 +- .../logic/exporter/ExportFormatTest.java | 2 +- .../logic/exporter/HtmlExportFormatTest.java | 2 +- .../jabref/logic/groups/SearchGroupTest.java | 2 +- .../jabref/logic/search/SearchQueryTest.java | 4 +- .../net/sf/jabref/logic/xmp/XMPUtilTest.java | 64 ++++++++++--------- .../sf/jabref/model/entry/BibEntryTests.java | 55 +++++++++------- 23 files changed, 121 insertions(+), 99 deletions(-) diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 794e5f3f8b8..1e774909ee8 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -66,7 +66,7 @@ private static void start(String[] args) { /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); CustomEntryTypesManager.loadCustomEntryTypes(preferences); - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index ff0a65db600..015e3edde31 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -390,7 +390,7 @@ private void importPreferences() { try { Globals.prefs.importPreferences(cli.getPreferencesImport()); CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs); - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); } catch (JabRefException ex) { LOGGER.error("Cannot import preferences", ex); } diff --git a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java index a48ce0c4de7..351eba391c5 100644 --- a/src/main/java/net/sf/jabref/external/DroppedFileHandler.java +++ b/src/main/java/net/sf/jabref/external/DroppedFileHandler.java @@ -233,7 +233,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo List xmpEntriesInFile; try { - xmpEntriesInFile = XMPUtil.readXMP(fileName); + xmpEntriesInFile = XMPUtil.readXMP(fileName, Globals.prefs); } catch (IOException e) { LOGGER.warn("Problem reading XMP", e); return false; diff --git a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java index 5c1c7a57019..cea990ad08f 100644 --- a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java @@ -44,6 +44,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefGUI; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.autocompleter.AutoCompleteListener; @@ -321,7 +322,8 @@ private NamedCompound updateKeywords(List entries, Set keyword keywords.addAll(keywordsToAdd); // put keywords back - Optional change = entry.putKeywords(keywords); + Optional change = entry.putKeywords(keywords, + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); if (change.isPresent()) { ce.addEdit(new UndoableFieldChange(change.get())); } diff --git a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java index 30324aee781..62687fda83f 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java @@ -59,7 +59,7 @@ public InternalExportAction(JabRefFrame frame, boolean selectedOnly) { @Override public void actionPerformed(ActionEvent e) { - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); JFileChooser fc = ExportAction .createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); fc.showSaveDialog(frame); diff --git a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java index 12c78b11842..10cca6ab86b 100644 --- a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java @@ -476,7 +476,7 @@ private void insertTextForTag(boolean overrideField) { entry.setField(fieldName, old.get() + " and " + txt); } else if ("keywords".equals(fieldName)) { // Add keyword - entry.addKeyword(txt); + entry.addKeyword(txt, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } else { entry.setField(fieldName, old.get() + txt); } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index 1dd512d4cfe..1cf9096d17d 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -236,7 +236,7 @@ public PreferencesDialog(JabRefFrame parent) { private void updateAfterPreferenceChanges() { setValues(); - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); frame.removeCachedEntryEditors(); Globals.prefs.updateEntryEditorTabList(); } diff --git a/src/main/java/net/sf/jabref/importer/EntryFromPDFCreator.java b/src/main/java/net/sf/jabref/importer/EntryFromPDFCreator.java index 485cc674e92..49b2efd4add 100644 --- a/src/main/java/net/sf/jabref/importer/EntryFromPDFCreator.java +++ b/src/main/java/net/sf/jabref/importer/EntryFromPDFCreator.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Optional; +import net.sf.jabref.Globals; import net.sf.jabref.JabRefGUI; import net.sf.jabref.external.ExternalFileType; import net.sf.jabref.external.ExternalFileTypes; @@ -119,7 +120,7 @@ private void addEntryDataFromPDDocumentInformation(File pdfFile, BibEntry entry) */ private void addEntryDataFromXMP(File aFile, BibEntry entry) { try { - List entrys = XMPUtil.readXMP(aFile.getAbsoluteFile()); + List entrys = XMPUtil.readXMP(aFile.getAbsoluteFile(), Globals.prefs); addEntrysToEntry(entry, entrys); } catch (IOException e) { // no canceling here, just no data added. diff --git a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java index 2ea8650458e..fc594d601c1 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java @@ -30,6 +30,7 @@ import java.util.Optional; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.bibtex.FieldContentParser; @@ -562,7 +563,7 @@ private void parseField(BibEntry entry) throws IOException { entry.setField(key, entry.getFieldOptional(key).get() + " and " + content); } else if ("keywords".equals(key)) { //multiple keywords fields should be combined to one - entry.addKeyword(content); + entry.addKeyword(content, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } } else { entry.setField(key, content); diff --git a/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java b/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java index 8bba5ec0a58..0d7e276fc46 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java @@ -20,6 +20,8 @@ import java.util.LinkedHashSet; import java.util.List; +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.MonthUtil; @@ -111,7 +113,7 @@ public BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry) { keywordList.add(keywords.getString(i)); } } - entry.putKeywords(keywordList); + entry.putKeywords(keywordList, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } // Identifiers diff --git a/src/main/java/net/sf/jabref/importer/fileformat/PdfXmpImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/PdfXmpImporter.java index 9552dc4fbc8..a3937b48c89 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/PdfXmpImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/PdfXmpImporter.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Objects; +import net.sf.jabref.Globals; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.xmp.XMPUtil; @@ -54,7 +55,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { public ParserResult importDatabase(Path filePath, Charset defaultEncoding) { Objects.requireNonNull(filePath); try { - return new ParserResult(XMPUtil.readXMP(filePath)); + return new ParserResult(XMPUtil.readXMP(filePath, Globals.prefs)); } catch (IOException exception) { return ParserResult.fromErrorMessage(exception.getLocalizedMessage()); } @@ -75,7 +76,7 @@ protected boolean isRecognizedFormat(BufferedReader reader) throws IOException { @Override public boolean isRecognizedFormat(Path filePath, Charset defaultEncoding) throws IOException { Objects.requireNonNull(filePath); - return XMPUtil.hasMetadata(filePath); + return XMPUtil.hasMetadata(filePath, Globals.prefs); } @Override diff --git a/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java index d74ed3dfc01..facee5c8e22 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java @@ -32,6 +32,8 @@ import java.util.List; import java.util.Objects; +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.IdGenerator; @@ -350,7 +352,8 @@ private void parseAdditionalFields(BibEntry be, boolean multilineUrlFieldAllowed if ("Keywords".equals(keyword)) { String content = readMultipleLines(in); String[] keywords = content.split("[,;]"); - be.addKeywords(new LinkedHashSet<>(Arrays.asList(keywords))); + be.addKeywords(new LinkedHashSet<>(Arrays.asList(keywords)), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); // parse JEL field } else if ("JEL".equals(keyword)) { be.setField("jel", readMultipleLines(in)); diff --git a/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java index 948678dd264..94f2a582fa3 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormats.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.TreeMap; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.l10n.Localization; public class ExportFormats { @@ -31,7 +30,7 @@ public class ExportFormats { public static int entryNumber; - public static void initAllExports(JabRefPreferences prefs) { + public static void initAllExports(Map customFormats) { ExportFormats.EXPORT_FORMATS.clear(); @@ -66,7 +65,6 @@ public static void initAllExports(JabRefPreferences prefs) { ExportFormats.putFormat(new ModsExportFormat()); // Now add custom export formats - Map customFormats = prefs.customExports.getCustomExportFormats(); for (IExportFormat format : customFormats.values()) { ExportFormats.putFormat(format); } diff --git a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java index 724d6c83363..5e5ff75c83c 100644 --- a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java +++ b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java @@ -93,8 +93,8 @@ public class XMPUtil { * @return BibtexEntryies found in the PDF or an empty list * @throws IOException */ - public static List readXMP(String filename) throws IOException { - return XMPUtil.readXMP(new File(filename)); + public static List readXMP(String filename, JabRefPreferences prefs) throws IOException { + return XMPUtil.readXMP(new File(filename), prefs); } /** @@ -137,10 +137,10 @@ public static void writeXMP(String filename, BibEntry entry, * Throws an IOException if the file cannot be read, so the user * than remove a lock or cancel the operation. */ - public static List readXMP(File file) throws IOException { + public static List readXMP(File file, JabRefPreferences prefs) throws IOException { List result = Collections.emptyList(); try (FileInputStream inputStream = new FileInputStream(file)) { - result = XMPUtil.readXMP(inputStream); + result = XMPUtil.readXMP(inputStream, prefs); } return result; } @@ -178,7 +178,7 @@ public static PDDocument loadWithAutomaticDecryption(InputStream inputStream) th * * @return list of BibEntries retrieved from the stream. May be empty, but never null */ - public static List readXMP(InputStream inputStream) + public static List readXMP(InputStream inputStream, JabRefPreferences prefs) throws IOException { List result = new LinkedList<>(); @@ -206,7 +206,7 @@ public static List readXMP(InputStream inputStream) for (XMPSchema schema : schemas) { XMPSchemaDublinCore dc = (XMPSchemaDublinCore) schema; - Optional entry = XMPUtil.getBibtexEntryFromDublinCore(dc); + Optional entry = XMPUtil.getBibtexEntryFromDublinCore(dc, prefs); if (entry.isPresent()) { if (entry.get().getType() == null) { @@ -234,8 +234,8 @@ public static List readXMP(InputStream inputStream) return result; } - public static Collection readXMP(Path filePath) throws IOException { - return readXMP(filePath.toFile()); + public static Collection readXMP(Path filePath, JabRefPreferences prefs) throws IOException { + return readXMP(filePath.toFile(), prefs); } /** @@ -312,7 +312,8 @@ public static Optional getBibtexEntryFromDocumentInformation( * * @return The bibtex entry found in the document information. */ - public static Optional getBibtexEntryFromDublinCore(XMPSchemaDublinCore dcSchema) { + public static Optional getBibtexEntryFromDublinCore(XMPSchemaDublinCore dcSchema, + JabRefPreferences prefs) { BibEntry entry = new BibEntry(); @@ -416,7 +417,7 @@ public static Optional getBibtexEntryFromDublinCore(XMPSchemaDublinCor */ List subjects = dcSchema.getSubjects(); if (subjects != null) { - entry.addKeywords(subjects); + entry.addKeywords(subjects, prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); } /** @@ -1187,7 +1188,7 @@ public static void main(String[] args) throws IOException, TransformerException if (args[0].endsWith(".pdf")) { // Read from pdf and write as BibTex - List l = XMPUtil.readXMP(new File(args[0])); + List l = XMPUtil.readXMP(new File(args[0]), Globals.prefs); BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false); @@ -1274,9 +1275,9 @@ public static void main(String[] args) throws IOException, TransformerException /** * see XMPUtil.hasMetadata(InputStream) */ - public static boolean hasMetadata(Path path) { + public static boolean hasMetadata(Path path, JabRefPreferences prefs) { try (InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ)) { - return hasMetadata(inputStream); + return hasMetadata(inputStream, prefs); } catch (IOException e) { LOGGER.error("XMP reading failed", e); return false; @@ -1294,9 +1295,9 @@ public static boolean hasMetadata(Path path) { * The inputStream to read the PDF from. * @return whether a BibEntry was found in the given PDF. */ - public static boolean hasMetadata(InputStream inputStream) { + public static boolean hasMetadata(InputStream inputStream, JabRefPreferences prefs) { try { - List bibEntries = XMPUtil.readXMP(inputStream); + List bibEntries = XMPUtil.readXMP(inputStream, prefs); return !bibEntries.isEmpty(); } catch (EncryptedPdfsNotSupportedException ex) { LOGGER.info("Encryption not supported by XMPUtil"); diff --git a/src/main/java/net/sf/jabref/model/entry/BibEntry.java b/src/main/java/net/sf/jabref/model/entry/BibEntry.java index 9ac64bd5192..a25fb942570 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibEntry.java @@ -34,11 +34,9 @@ import java.util.Set; import java.util.TreeSet; -import net.sf.jabref.Globals; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.event.FieldChangedEvent; -import net.sf.jabref.preferences.JabRefPreferences; import com.google.common.base.Strings; import com.google.common.eventbus.EventBus; @@ -539,7 +537,7 @@ public void setChanged(boolean changed) { this.changed = changed; } - public Optional putKeywords(Collection keywords) { + public Optional putKeywords(Collection keywords, String separator) { Objects.requireNonNull(keywords); Optional oldValue = this.getFieldOptional(KEYWORDS_FIELD); @@ -553,7 +551,7 @@ public Optional putKeywords(Collection keywords) { } // Set new keyword field - String newValue = String.join(Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR), keywords); + String newValue = String.join(separator, keywords); return this.setField(KEYWORDS_FIELD, newValue); } @@ -562,7 +560,7 @@ public Optional putKeywords(Collection keywords) { * * @param keyword Keyword to add */ - public void addKeyword(String keyword) { + public void addKeyword(String keyword, String separator) { Objects.requireNonNull(keyword, "keyword must not be null"); if (keyword.isEmpty()) { @@ -571,7 +569,7 @@ public void addKeyword(String keyword) { Set keywords = this.getKeywords(); keywords.add(keyword); - this.putKeywords(keywords); + this.putKeywords(keywords, separator); } /** @@ -579,11 +577,11 @@ public void addKeyword(String keyword) { * * @param keywords Keywords to add */ - public void addKeywords(Collection keywords) { + public void addKeywords(Collection keywords, String separator) { Objects.requireNonNull(keywords); for (String keyword : keywords) { - this.addKeyword(keyword); + this.addKeyword(keyword, separator); } } diff --git a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java index a9fbb506f7f..53fbc520690 100644 --- a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java @@ -149,7 +149,7 @@ private List importPdfFiles(List fileNames) { for (String fileName : fileNames) { if (!neverShow && !doNotShowAgain) { importDialog = new ImportDialog(dropRow >= 0, fileName); - if (!XMPUtil.hasMetadata(Paths.get(fileName))) { + if (!XMPUtil.hasMetadata(Paths.get(fileName), Globals.prefs)) { importDialog.disableXMPChoice(); } importDialog.setLocationRelativeTo(frame); diff --git a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java index 731ecddcdda..d086cd3caac 100644 --- a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java +++ b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java @@ -21,6 +21,7 @@ import java.util.Set; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.undo.UndoableFieldChange; import net.sf.jabref.logic.util.UpdateField; @@ -121,7 +122,8 @@ private static void exportFieldToKeywords(SpecialField e, String newValue, BibEn } - Optional change = entry.putKeywords(keywordList); + Optional change = entry.putKeywords(keywordList, + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); if (ce != null){ change.ifPresent(changeValue -> ce.addEdit(new UndoableFieldChange(changeValue))); } diff --git a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java index c0f5bfe61e5..91b34867549 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java @@ -78,7 +78,7 @@ public void testExportingNullEntriesThrowsNPE() throws Exception { public static Collection exportFormats() { Collection result = new ArrayList<>(); Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); for (IExportFormat format : ExportFormats.getExportFormats().values()) { result.add(new Object[] {format, format.getDisplayName()}); } diff --git a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java index bccbdd86fe2..8cda903c0a3 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java @@ -35,7 +35,7 @@ public class HtmlExportFormatTest { @Before public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(Globals.prefs); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); exportFormat = ExportFormats.getExportFormat("html"); Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); diff --git a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java index 60d851edce7..c9648ac2bc2 100644 --- a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java @@ -27,7 +27,7 @@ public void testContains() { BibEntry entry = new BibEntry(); assertFalse(group.contains(entry)); - entry.addKeyword("review"); + entry.addKeyword("review", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); assertTrue(group.contains(entry)); } diff --git a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java index d338a81d078..00ff9288c34 100644 --- a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java +++ b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java @@ -1,5 +1,7 @@ package net.sf.jabref.logic.search; +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.model.entry.BibEntry; import org.junit.Test; @@ -33,7 +35,7 @@ public void testIsGrammarBasedSearch() { @Test public void testGrammarSearch() { BibEntry entry = new BibEntry(); - entry.addKeyword("one two"); + entry.addKeyword("one two", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); SearchQuery searchQuery = new SearchQuery("keywords=\"one two\"", false, false); assertTrue(searchQuery.isMatch(entry)); } diff --git a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java index aefa856097f..80933894cb3 100644 --- a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java @@ -267,7 +267,7 @@ public void testReadXMPSimple() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(XMPUtilTest.bibtexDescription(bibtex))); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -292,7 +292,7 @@ public void testReadXMPUTF8() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(XMPUtilTest.bibtexDescription(bibtex))); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -320,7 +320,7 @@ public void testPrivacyFilter() throws IOException, TransformerException { XMPUtil.writeXMP(pdfFile, e, null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry x = l.get(0); @@ -338,7 +338,7 @@ public void testPrivacyFilter() throws IOException, TransformerException { XMPUtil.writeXMP(pdfFile, e, null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry x = l.get(0); Set ts = x.getFieldNames(); @@ -366,7 +366,7 @@ public void testReadXMPSeq() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(XMPUtilTest.bibtexDescription(bibtex))); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -390,7 +390,7 @@ public void testReadXMPEntryType() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(XMPUtilTest.bibtexDescription(bibtex))); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -465,7 +465,7 @@ public void testReadWriteXMP() throws IOException, TransformerException { XMPUtil.writeXMP(pdfFile, e, null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry x = l.get(0); @@ -487,7 +487,7 @@ public void testNewlineHandling() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(XMPUtilTest.bibtexDescription(bibtex))); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -511,7 +511,7 @@ public void testAttributeRead() throws COSVisitorException, IOException { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(bibtex)); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -521,7 +521,7 @@ public void testAttributeRead() throws COSVisitorException, IOException { @Test public void testEmpty() throws Exception { - Assert.assertEquals(Collections.emptyList(), XMPUtil.readXMP(pdfFile)); + Assert.assertEquals(Collections.emptyList(), XMPUtil.readXMP(pdfFile, Globals.prefs)); } @@ -549,7 +549,7 @@ public void testSimpleUpdate() throws Exception { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(s)); // Nothing there yet, but should not crash - Assert.assertEquals(Collections.emptyList(), XMPUtil.readXMP(pdfFile)); + Assert.assertEquals(Collections.emptyList(), XMPUtil.readXMP(pdfFile, Globals.prefs)); s = " " + " Acrobat PDFMaker 7.0.7" @@ -569,13 +569,13 @@ public void testSimpleUpdate() throws Exception { // Title is Questionnaire.pdf so the DublinCore fallback should hit // in... - Assert.assertEquals(1, XMPUtil.readXMP(pdfFile).size()); + Assert.assertEquals(1, XMPUtil.readXMP(pdfFile, Globals.prefs).size()); { // Now write new packet and check if it was correctly written XMPUtil.writeXMP(pdfFile, t1BibtexEntry(), null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -651,7 +651,7 @@ public void testSimpleUpdate() throws Exception { XMPUtil.writeXMP(pdfFile, toSet, null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry e = l.get(0); @@ -742,7 +742,7 @@ public void testXMLEscape() throws Exception { XMPUtil.writeXMP(pdfFile, e, null); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry x = l.get(0); @@ -802,7 +802,7 @@ public void testXMPreadString() throws Exception { /* Test contents of string */ writeManually(pdfFile, xmp); - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(2, l.size()); @@ -837,7 +837,7 @@ public void testReadMultiple() throws Exception { writeManually(pdfFile, XMPUtilTest.bibtexXPacket(bibtex)); // Read from file - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(2, l.size()); @@ -868,7 +868,7 @@ public void testWriteMultiple() throws IOException, TransformerException { XMPUtil.writeXMP(pdfFile, l, null, false); - l = XMPUtil.readXMP(pdfFile); + l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(2, l.size()); @@ -891,7 +891,7 @@ public void testWriteMultiple() throws IOException, TransformerException { @Test public void testReadProtectedPDFHasMetaData() throws Exception { try (InputStream is = XMPUtilTest.class.getResourceAsStream("/pdfs/write-protected.pdf")) { - Assert.assertTrue(XMPUtil.hasMetadata(is)); + Assert.assertTrue(XMPUtil.hasMetadata(is, Globals.prefs)); } } @@ -901,7 +901,7 @@ public void testReadProtectedPDFHasMetaData() throws Exception { @Test public void testReadProtectedPDFHasCorrectMetaData() throws Exception { try (InputStream is = XMPUtilTest.class.getResourceAsStream("/pdfs/write-protected.pdf")) { - List readEntries = XMPUtil.readXMP(is); + List readEntries = XMPUtil.readXMP(is, Globals.prefs); BibEntry entry = new BibEntry(); entry.setType("misc"); @@ -971,7 +971,8 @@ public void testReadWriteDC() throws IOException, TransformerException { */ Assert.assertEquals(4, dcSchema.getRelationships().size()); - assertEqualsBibtexEntry(t3BibtexEntry(), XMPUtil.getBibtexEntryFromDublinCore(dcSchema).get()); + assertEqualsBibtexEntry(t3BibtexEntry(), + XMPUtil.getBibtexEntryFromDublinCore(dcSchema, Globals.prefs).get()); } @@ -1036,7 +1037,8 @@ public void testWriteSingleUpdatesDCAndInfo() throws IOException, TransformerExc */ Assert.assertEquals(4, dcSchema.getRelationships().size()); - assertEqualsBibtexEntry(t3BibtexEntry(), XMPUtil.getBibtexEntryFromDublinCore(dcSchema).get()); + assertEqualsBibtexEntry(t3BibtexEntry(), + XMPUtil.getBibtexEntryFromDublinCore(dcSchema, Globals.prefs).get()); } } @@ -1112,7 +1114,7 @@ public void testCommandLineSingleBib() throws IOException, TransformerException, writeManually(pdfFile, xmp); } - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(1, l.size()); assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0)); @@ -1181,7 +1183,7 @@ public void testCommandLineSinglePdf() throws IOException, TransformerException, /* Test contents of string */ writeManually(pdfFile, xmp); - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(1, l.size()); assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0)); @@ -1213,7 +1215,7 @@ public void testCommandLineByKey() throws IOException, TransformerException { } // PDF should be annotated: - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(1, l.size()); assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0)); } @@ -1229,7 +1231,7 @@ public void testCommandLineByKey() throws IOException, TransformerException { } // PDF should be annotated: - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(1, l.size()); assertEqualsBibtexEntry(t2BibtexEntry(), l.get(0)); } finally { @@ -1262,7 +1264,7 @@ public void testCommandLineSeveral() throws IOException, TransformerException { XMPUtil.main(new String[] {tempBib.getAbsolutePath(), pdfFile.getAbsolutePath()}); System.setOut(oldOut); } - List l = XMPUtil.readXMP(pdfFile); + List l = XMPUtil.readXMP(pdfFile, Globals.prefs); Assert.assertEquals(2, l.size()); @@ -1316,7 +1318,7 @@ public void testResolveStrings() throws IOException, TransformerException { XMPUtil.writeXMP(pdfFile, e, original.getDatabase()); - List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile()); + List l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), Globals.prefs); Assert.assertEquals(1, l.size()); BibEntry x = l.get(0); @@ -1327,7 +1329,7 @@ public void testResolveStrings() throws IOException, TransformerException { @Test(expected = EncryptedPdfsNotSupportedException.class) public void expectedEncryptionNotSupportedExceptionAtRead() throws IOException { try (InputStream is = XMPUtilTest.class.getResourceAsStream("/pdfs/encrypted.pdf")) { - XMPUtil.readXMP(is); + XMPUtil.readXMP(is, Globals.prefs); } } @@ -1361,7 +1363,7 @@ public void testResolveStrings2() throws IOException, TransformerException { result.getDatabase()); // Test whether we the main function can load the bibtex correctly - BibEntry b = XMPUtil.readXMP(pdfFile).get(0); + BibEntry b = XMPUtil.readXMP(pdfFile, Globals.prefs).get(0); Assert.assertNotNull(b); Assert.assertEquals(originalAuthors, AuthorList.parse(b.getFieldOptional("author").get())); @@ -1396,7 +1398,7 @@ public void testResolveStrings2() throws IOException, TransformerException { Assert.assertEquals("Arvind", dcSchema.getCreators().get(1)); Assert.assertEquals("Krste Asanov\\'\\i{}c", dcSchema.getCreators().get(2)); - b = XMPUtil.getBibtexEntryFromDublinCore(dcSchema).get(); + b = XMPUtil.getBibtexEntryFromDublinCore(dcSchema, Globals.prefs).get(); Assert.assertNotNull(b); Assert.assertEquals(originalAuthors, AuthorList.parse(b.getFieldOptional("author").get())); } diff --git a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java index 0d2c7671028..d92b0d018e2 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java @@ -212,16 +212,21 @@ public void setNullField() { @Test(expected = NullPointerException.class) public void addNullKeywordThrowsNPE() { - keywordEntry.addKeyword(null); + keywordEntry.addKeyword(null, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.fail(); } @Test(expected = NullPointerException.class) public void putNullKeywordListThrowsNPE() { - keywordEntry.putKeywords(null); + keywordEntry.putKeywords(null, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.fail(); } + @Test(expected = NullPointerException.class) + public void putNullKeywordSeparatorThrowsNPE() { + keywordEntry.putKeywords(Arrays.asList("A", "B"), null); + Assert.fail(); + } @Test public void testGetSeparatedKeywordsAreCorrect() { String[] expected = {"Foo", "Bar"}; @@ -230,48 +235,48 @@ public void testGetSeparatedKeywordsAreCorrect() { @Test public void testAddKeywordIsCorrect() { - keywordEntry.addKeyword("FooBar"); + keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); String[] expected = {"Foo", "Bar", "FooBar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordHasChanged() { - keywordEntry.addKeyword("FooBar"); + keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testAddKeywordTwiceYiedsOnlyOne() { - keywordEntry.addKeyword("FooBar"); - keywordEntry.addKeyword("FooBar"); + keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); String[] expected = {"Foo", "Bar", "FooBar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void addKeywordIsCaseSensitive() { - keywordEntry.addKeyword("FOO"); + keywordEntry.addKeyword("FOO", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); String[] expected = {"Foo", "Bar", "FOO"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordWithDifferentCapitalizationChanges() { - keywordEntry.addKeyword("FOO"); + keywordEntry.addKeyword("FOO", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testAddKeywordEmptyKeywordIsNotAdded() { - keywordEntry.addKeyword(""); + keywordEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); String[] expected = {"Foo", "Bar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordEmptyKeywordNotChanged() { - keywordEntry.addKeyword(""); + keywordEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertFalse(keywordEntry.hasChanged()); } @@ -282,81 +287,85 @@ public void texNewBibEntryHasNoKeywords() { @Test public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { - emptyEntry.addKeyword(""); + emptyEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(emptyEntry.getKeywords().isEmpty()); } @Test public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { - emptyEntry.addKeyword(""); + emptyEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertFalse(emptyEntry.hasChanged()); } @Test public void testAddKeywordsWorksAsExpected() { String[] expected = {"Foo", "Bar"}; - emptyEntry.addKeywords(keywordEntry.getKeywords()); + emptyEntry.addKeywords(keywordEntry.getKeywords(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertArrayEquals(expected, emptyEntry.getKeywords().toArray()); } @Test public void testPutKeywordsOverwritesOldKeywords() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang")); + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); String[] expected = {"Yin", "Yang"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testPutKeywordsHasChanged() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang")); + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { - keywordEntry.putKeywords(Collections.emptyList()); + keywordEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(keywordEntry.getKeywords().isEmpty()); } @Test public void testPutKeywordsPutEmpyListHasChanged() { - keywordEntry.putKeywords(Collections.emptyList()); + keywordEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testPutKeywordsPutEmpyListToEmptyBibentry() { - emptyEntry.putKeywords(Collections.emptyList()); + emptyEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertTrue(emptyEntry.getKeywords().isEmpty()); } @Test public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { - emptyEntry.putKeywords(Collections.emptyList()); + emptyEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertFalse(emptyEntry.hasChanged()); } @Test public void putKeywordsToEmptyReturnsNoChange() { - Optional change = emptyEntry.putKeywords(Collections.emptyList()); + Optional change = emptyEntry.putKeywords(Collections.emptyList(), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertEquals(Optional.empty(), change); } @Test public void clearKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Collections.emptyList()); + Optional change = keywordEntry.putKeywords(Collections.emptyList(), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertEquals(Optional.of(new FieldChange(keywordEntry, "keywords", "Foo, Bar", null)), change); } @Test public void changeKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest")); + Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest"), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertEquals(Optional.of(new FieldChange(keywordEntry, "keywords", "Foo, Bar", "Test, FooTest")), change); } @Test public void putKeywordsToSameReturnsNoChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar")); + Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar"), + Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); Assert.assertEquals(Optional.empty(), change); } From c94ed224d772215b92d907461edfc40f6b52dd57 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 17 Jul 2016 01:29:31 +0200 Subject: [PATCH 04/17] Even more injections --- .../java/net/sf/jabref/gui/BasePanel.java | 2 +- .../java/net/sf/jabref/gui/PreviewPanel.java | 3 +- .../gui/openoffice/OpenOfficePanel.java | 3 +- .../bibtex/comparator/FieldComparator.java | 26 ++++----- .../jabref/logic/exporter/ExportFormat.java | 8 +-- .../net/sf/jabref/logic/layout/Layout.java | 7 ++- .../sf/jabref/logic/layout/LayoutEntry.java | 19 +++++-- .../sf/jabref/logic/layout/LayoutHelper.java | 7 ++- .../jabref/logic/layout/format/FileLink.java | 12 +++- .../logic/layout/format/WrapFileLinks.java | 13 ++++- .../jabref/logic/openoffice/OOBibStyle.java | 12 +++- .../jabref/logic/openoffice/StyleLoader.java | 14 +++-- .../net/sf/jabref/logic/util/io/FileUtil.java | 2 +- .../jabref/logic/layout/LayoutEntryTest.java | 2 +- .../sf/jabref/logic/layout/LayoutTest.java | 2 +- .../logic/layout/format/FileLinkTest.java | 14 ++--- .../logic/openoffice/OOBibStyleTest.java | 56 +++++++++---------- .../logic/openoffice/StyleLoaderTest.java | 32 +++++------ 18 files changed, 136 insertions(+), 98 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 18203f908e5..8e0f54bfaff 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -990,7 +990,7 @@ private void copyKeyAndTitle() { "\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); Layout layout; try { - layout = new LayoutHelper(sr, Globals.journalAbbreviationLoader).getLayoutFromText(); + layout = new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText(); } catch (IOException e) { LOGGER.info("Could not get layout", e); return; diff --git a/src/main/java/net/sf/jabref/gui/PreviewPanel.java b/src/main/java/net/sf/jabref/gui/PreviewPanel.java index e0bcca47434..f516c01d47c 100644 --- a/src/main/java/net/sf/jabref/gui/PreviewPanel.java +++ b/src/main/java/net/sf/jabref/gui/PreviewPanel.java @@ -261,7 +261,8 @@ public void updateLayout(String layoutFormat) { private void updateLayout() { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); try { - layout = Optional.of(new LayoutHelper(sr, Globals.journalAbbreviationLoader).getLayoutFromText()); + layout = Optional + .of(new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText()); } catch (IOException e) { layout = Optional.empty(); LOGGER.debug("no layout could be set", e); diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index c1d084a5681..89154087040 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -126,7 +126,8 @@ private OpenOfficePanel() { update = new JButton(IconTheme.JabRefIcon.REFRESH.getSmallIcon()); update.setToolTipText(Localization.lang("Sync OpenOffice/LibreOffice bibliography")); preferences = new OpenOfficePreferences(Globals.prefs); - loader = new StyleLoader(preferences, Globals.journalAbbreviationLoader, Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, Globals.prefs, Globals.journalAbbreviationLoader, + Globals.prefs.getDefaultEncoding()); } public static OpenOfficePanel getInstance() { diff --git a/src/main/java/net/sf/jabref/logic/bibtex/comparator/FieldComparator.java b/src/main/java/net/sf/jabref/logic/bibtex/comparator/FieldComparator.java index 6ea66ddb816..e4d41f28f7f 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/comparator/FieldComparator.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/comparator/FieldComparator.java @@ -48,15 +48,6 @@ public class FieldComparator implements Comparator { private static final Collator COLLATOR = getCollator(); - private static Collator getCollator() { - try { - return new RuleBasedCollator( - ((RuleBasedCollator) Collator.getInstance()).getRules().replace("<'\u005f'", "<' '<'\u005f'")); - } catch (ParseException e) { - return Collator.getInstance(); - } - } - enum FieldType { NAME, TYPE, YEAR, MONTH, OTHER } @@ -89,6 +80,19 @@ public FieldComparator(String field, boolean reversed) { } } + public FieldComparator(SaveOrderConfig.SortCriterion sortCriterion) { + this(sortCriterion.field, sortCriterion.descending); + } + + private static Collator getCollator() { + try { + return new RuleBasedCollator( + ((RuleBasedCollator) Collator.getInstance()).getRules().replace("<'\u005f'", "<' '<'\u005f'")); + } catch (ParseException e) { + return Collator.getInstance(); + } + } + private FieldType determineFieldType() { if(BibEntry.TYPE_HEADER.equals(this.field[0])) { return FieldType.TYPE; @@ -103,10 +107,6 @@ private FieldType determineFieldType() { } } - public FieldComparator(SaveOrderConfig.SortCriterion sortCriterion) { - this(sortCriterion.field, sortCriterion.descending); - } - @Override public int compare(BibEntry e1, BibEntry e2) { String f1; diff --git a/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java b/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java index 4cb6ba4a357..9e44a4337c5 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java @@ -219,7 +219,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String // Print header try (Reader reader = getReader(lfFileName + ".begin.layout")) { - LayoutHelper layoutHelper = new LayoutHelper(reader, Globals.journalAbbreviationLoader); + LayoutHelper layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); beginLayout = layoutHelper.getLayoutFromText(); } catch (IOException ex) { // If an exception was cast, export filter doesn't have a begin @@ -245,7 +245,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String Layout defLayout; LayoutHelper layoutHelper; try (Reader reader = getReader(lfFileName + ".layout")) { - layoutHelper = new LayoutHelper(reader, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); defLayout = layoutHelper.getLayoutFromText(); } if (defLayout != null) { @@ -267,7 +267,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String } else { try (Reader reader = getReader(lfFileName + '.' + type + ".layout")) { // We try to get a type-specific layout for this entry. - layoutHelper = new LayoutHelper(reader, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); layout = layoutHelper.getLayoutFromText(); layouts.put(type, layout); if (layout != null) { @@ -291,7 +291,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String // changed section - begin (arudert) Layout endLayout = null; try (Reader reader = getReader(lfFileName + ".end.layout")) { - layoutHelper = new LayoutHelper(reader, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); endLayout = layoutHelper.getLayoutFromText(); } catch (IOException ex) { // If an exception was thrown, export filter doesn't have an end diff --git a/src/main/java/net/sf/jabref/logic/layout/Layout.java b/src/main/java/net/sf/jabref/logic/layout/Layout.java index 7a497a5e043..94a1c305df8 100644 --- a/src/main/java/net/sf/jabref/logic/layout/Layout.java +++ b/src/main/java/net/sf/jabref/logic/layout/Layout.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import net.sf.jabref.BibDatabaseContext; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; @@ -41,7 +42,7 @@ public class Layout { private static final Log LOGGER = LogFactory.getLog(Layout.class); - public Layout(List parsedEntries, JournalAbbreviationLoader repositoryLoader) { + public Layout(List parsedEntries, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { List tmpEntries = new ArrayList<>(parsedEntries.size()); List blockEntries = null; @@ -67,7 +68,7 @@ public Layout(List parsedEntries, JournalAbbreviationLoader repositor blockEntries.add(parsedEntry); le = new LayoutEntry(blockEntries, parsedEntry.i == LayoutHelper.IS_FIELD_END ? LayoutHelper.IS_FIELD_START : LayoutHelper.IS_GROUP_START, - repositoryLoader); + prefs, repositoryLoader); tmpEntries.add(le); blockEntries = null; } else { @@ -82,7 +83,7 @@ public Layout(List parsedEntries, JournalAbbreviationLoader repositor } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, repositoryLoader)); + tmpEntries.add(new LayoutEntry(parsedEntry, prefs, repositoryLoader)); } else { blockEntries.add(parsedEntry); } diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index e16b1d99f86..c130211b403 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -27,6 +27,7 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; @@ -118,8 +119,12 @@ class LayoutEntry { private final JournalAbbreviationLoader repositoryLoader; - public LayoutEntry(StringInt si, JournalAbbreviationLoader repositoryLoader) { + private final JabRefPreferences prefs; + + + public LayoutEntry(StringInt si, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { this.repositoryLoader = repositoryLoader; + this.prefs = prefs; type = si.i; switch (type) { case LayoutHelper.IS_LAYOUT_TEXT: @@ -138,8 +143,10 @@ public LayoutEntry(StringInt si, JournalAbbreviationLoader repositoryLoader) { } } - public LayoutEntry(List parsedEntries, int layoutType, JournalAbbreviationLoader repositoryLoader) { + public LayoutEntry(List parsedEntries, int layoutType, JabRefPreferences prefs, + JournalAbbreviationLoader repositoryLoader) { this.repositoryLoader = repositoryLoader; + this.prefs = prefs; List tmpEntries = new ArrayList<>(); String blockStart = parsedEntries.get(0).s; String blockEnd = parsedEntries.get(parsedEntries.size() - 1).s; @@ -164,7 +171,7 @@ public LayoutEntry(List parsedEntries, int layoutType, JournalAbbrevi 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, repositoryLoader); + LayoutEntry le = new LayoutEntry(blockEntries, groupType, prefs, repositoryLoader); tmpEntries.add(le); blockEntries = null; } else { @@ -180,7 +187,7 @@ public LayoutEntry(List parsedEntries, int layoutType, JournalAbbrevi } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, repositoryLoader)); + tmpEntries.add(new LayoutEntry(parsedEntry, prefs, repositoryLoader)); } else { blockEntries.add(parsedEntry); } @@ -544,7 +551,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "Default": return new Default(); case "FileLink": - return new FileLink(); + return new FileLink(prefs); case "Number": return new Number(); case "RisAuthors": @@ -558,7 +565,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "WrapContent": return new WrapContent(); case "WrapFileLinks": - return new WrapFileLinks(); + return new WrapFileLinks(prefs); default: return new NotFoundFormatter(name); } diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java b/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java index 59785ea4f64..e18712bb628 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; /** @@ -51,12 +52,14 @@ public class LayoutHelper { private final PushbackReader in; private final List parsedEntries = new ArrayList<>(); private final JournalAbbreviationLoader repositoryLoader; + private final JabRefPreferences prefs; private boolean endOfFile; - public LayoutHelper(Reader in, JournalAbbreviationLoader repositoryLoader) { + public LayoutHelper(Reader in, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { this.in = new PushbackReader(Objects.requireNonNull(in)); this.repositoryLoader = Objects.requireNonNull(repositoryLoader); + this.prefs = Objects.requireNonNull(prefs); } public Layout getLayoutFromText() throws IOException { @@ -70,7 +73,7 @@ public Layout getLayoutFromText() throws IOException { } } - return new Layout(parsedEntries, repositoryLoader); + return new Layout(parsedEntries, prefs, repositoryLoader); } public static String getCurrentGroup() { diff --git a/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java b/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java index 9108a85e009..6e57c72445e 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java @@ -22,6 +22,7 @@ import java.util.Optional; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.layout.ParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.entry.FileField; @@ -39,8 +40,13 @@ public class FileLink implements ParamLayoutFormatter { private static final Log LOGGER = LogFactory.getLog(FileLink.class); private String fileType; + private final JabRefPreferences prefs; + public FileLink(JabRefPreferences prefs) { + this.prefs = prefs; + } + @Override public String format(String field) { if (field == null) { @@ -75,10 +81,10 @@ public String format(String field) { // but that is not available from a formatter. Therefore, as an // ugly hack, the export routine has set a global variable before // starting the export, which contains the database's file directory: - if (Globals.prefs.fileDirForDatabase == null) { - dirs = Collections.singletonList(Globals.prefs.get(Globals.FILE_FIELD + Globals.DIR_SUFFIX)); + if (prefs.fileDirForDatabase == null) { + dirs = Collections.singletonList(prefs.get(Globals.FILE_FIELD + Globals.DIR_SUFFIX)); } else { - dirs = Globals.prefs.fileDirForDatabase; + dirs = prefs.fileDirForDatabase; } Optional f = FileUtil.expandFilename(link, dirs); diff --git a/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java b/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java index 426c2ecd091..bdbf9651443 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java @@ -25,6 +25,7 @@ import java.util.Optional; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.layout.AbstractParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.entry.FileField; @@ -116,6 +117,7 @@ public class WrapFileLinks extends AbstractParamLayoutFormatter { // Define which escape sequences give what results: private static final Map ESCAPE_SEQ = new HashMap<>(); + private final JabRefPreferences prefs; static { WrapFileLinks.ESCAPE_SEQ.put('i', WrapFileLinks.ITERATION_COUNT); @@ -126,6 +128,11 @@ public class WrapFileLinks extends AbstractParamLayoutFormatter { WrapFileLinks.ESCAPE_SEQ.put('d', WrapFileLinks.FILE_DESCRIPTION); } + + public WrapFileLinks(JabRefPreferences prefs) { + this.prefs = prefs; + } + @Override public void setArgument(String arg) { String[] parts = AbstractParamLayoutFormatter.parseArgument(arg); @@ -170,10 +177,10 @@ public String format(String field) { // but that is not available from a formatter. Therefore, as an // ugly hack, the export routine has set a global variable before // starting the export, which contains the database's file directory: - if (Globals.prefs.fileDirForDatabase == null) { - dirs = Collections.singletonList(Globals.prefs.get(Globals.FILE_FIELD + Globals.DIR_SUFFIX)); + if (prefs.fileDirForDatabase == null) { + dirs = Collections.singletonList(prefs.get(Globals.FILE_FIELD + Globals.DIR_SUFFIX)); } else { - dirs = Globals.prefs.fileDirForDatabase; + dirs = prefs.fileDirForDatabase; } Optional f = FileUtil.expandFilename(flEntry.getLink(), dirs); diff --git a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java index 7488671a7f1..09869e06125 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java @@ -37,6 +37,7 @@ import java.util.regex.Pattern; import net.sf.jabref.JabRefMain; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatter; @@ -147,13 +148,16 @@ enum BibStyleMode { private static final String AUTHOR_SEPARATOR = "AuthorSeparator"; private final JournalAbbreviationLoader repositoryLoader; + private final JabRefPreferences prefs; private static final Pattern QUOTED = Pattern.compile("\".*\""); private static final Log LOGGER = LogFactory.getLog(OOBibStyle.class); - public OOBibStyle(File styleFile, JournalAbbreviationLoader repositoryLoader, Charset encoding) throws IOException { + public OOBibStyle(File styleFile, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader, + Charset encoding) throws IOException { this.repositoryLoader = Objects.requireNonNull(repositoryLoader); + this.prefs = Objects.requireNonNull(prefs); this.styleFile = Objects.requireNonNull(styleFile); this.encoding = Objects.requireNonNull(encoding); setDefaultProperties(); @@ -162,9 +166,10 @@ public OOBibStyle(File styleFile, JournalAbbreviationLoader repositoryLoader, Ch path = styleFile.getPath(); } - public OOBibStyle(String resourcePath, JournalAbbreviationLoader repositoryLoader) + public OOBibStyle(String resourcePath, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) throws IOException { this.repositoryLoader = Objects.requireNonNull(repositoryLoader); + this.prefs = Objects.requireNonNull(prefs); this.encoding = StandardCharsets.UTF_8; setDefaultProperties(); initialize(JabRefMain.class.getResource(resourcePath).openStream()); @@ -378,7 +383,8 @@ private void handleStructureLine(String line) { boolean setDefault = line.substring(0, index).equals(OOBibStyle.DEFAULT_MARK); String type = line.substring(0, index); try { - Layout layout = new LayoutHelper(new StringReader(formatString), this.repositoryLoader).getLayoutFromText(); + Layout layout = new LayoutHelper(new StringReader(formatString), this.prefs, this.repositoryLoader) + .getLayoutFromText(); if (setDefault) { defaultBibLayout = layout; } else { diff --git a/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java b/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java index af1a616d643..66fbd0c4e14 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import org.apache.commons.logging.Log; @@ -43,6 +44,7 @@ public class StyleLoader { private final JournalAbbreviationLoader journalAbbreviationLoader; private final OpenOfficePreferences preferences; private final Charset encoding; + private final JabRefPreferences jabrefPreferences; // Lists of the internal // and external styles @@ -50,9 +52,11 @@ public class StyleLoader { private final List externalStyles = new ArrayList<>(); - public StyleLoader(OpenOfficePreferences preferences, JournalAbbreviationLoader journalAbbreviationLoader, Charset encoding) { + public StyleLoader(OpenOfficePreferences preferences, JabRefPreferences jabrefPreferences, + JournalAbbreviationLoader journalAbbreviationLoader, Charset encoding) { this.journalAbbreviationLoader = Objects.requireNonNull(journalAbbreviationLoader); this.preferences = Objects.requireNonNull(preferences); + this.jabrefPreferences = Objects.requireNonNull(jabrefPreferences); this.encoding = Objects.requireNonNull(encoding); loadInternalStyles(); loadExternalStyles(); @@ -72,7 +76,8 @@ public List getStyles() { public boolean addStyleIfValid(String filename) { Objects.requireNonNull(filename); try { - OOBibStyle newStyle = new OOBibStyle(new File(filename), journalAbbreviationLoader, encoding); + OOBibStyle newStyle = new OOBibStyle(new File(filename), jabrefPreferences, journalAbbreviationLoader, + encoding); if (externalStyles.contains(newStyle)) { LOGGER.info("External style file " + filename + " already existing."); } else if (newStyle.isValid()) { @@ -98,7 +103,8 @@ private void loadExternalStyles() { List lists = preferences.getExternalStyles(); for (String filename : lists) { try { - OOBibStyle style = new OOBibStyle(new File(filename), journalAbbreviationLoader, encoding); + OOBibStyle style = new OOBibStyle(new File(filename), jabrefPreferences, journalAbbreviationLoader, + encoding); if (style.isValid()) { //Problem! externalStyles.add(style); } else { @@ -117,7 +123,7 @@ private void loadInternalStyles() { internalStyles.clear(); for (String filename : internalStyleFiles) { try { - internalStyles.add(new OOBibStyle(filename, journalAbbreviationLoader)); + internalStyles.add(new OOBibStyle(filename, jabrefPreferences, journalAbbreviationLoader)); } catch (IOException e) { LOGGER.info("Problem reading internal style file " + filename, e); } diff --git a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java index 51c274be0c9..3bbc88c267d 100644 --- a/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java +++ b/src/main/java/net/sf/jabref/logic/util/io/FileUtil.java @@ -398,7 +398,7 @@ public static String createFileNameFromPattern(BibDatabase database, BibEntry en StringReader sr = new StringReader(prefs.get(JabRefPreferences.PREF_IMPORT_FILENAMEPATTERN)); Layout layout = null; try { - layout = new LayoutHelper(sr, repositoryLoader).getLayoutFromText(); + layout = new LayoutHelper(sr, prefs, repositoryLoader).getLayoutFromText(); } catch (IOException e) { LOGGER.info("Wrong format " + e.getMessage(), e); } diff --git a/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java b/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java index bbf289d027b..467bbf64ecd 100644 --- a/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java +++ b/src/test/java/net/sf/jabref/logic/layout/LayoutEntryTest.java @@ -86,7 +86,7 @@ public void setUp() { public String layout(String layoutFile, BibEntry entry, Optional highlightPattern) throws IOException { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); - Layout layout = new LayoutHelper(sr, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); + Layout layout = new LayoutHelper(sr, Globals.prefs, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); return layout.doLayout(entry, null, highlightPattern); } diff --git a/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java b/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java index a25aa679735..e045a7eff4d 100644 --- a/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java +++ b/src/test/java/net/sf/jabref/logic/layout/LayoutTest.java @@ -53,7 +53,7 @@ public String layout(String layoutFile, String entry) throws IOException { BibEntry be = LayoutTest.bibtexString2BibtexEntry(entry); StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); - Layout layout = new LayoutHelper(sr, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); + Layout layout = new LayoutHelper(sr, Globals.prefs, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); return layout.doLayout(be, null); } diff --git a/src/test/java/net/sf/jabref/logic/layout/format/FileLinkTest.java b/src/test/java/net/sf/jabref/logic/layout/format/FileLinkTest.java index 3c78f9c424c..df66e221d17 100644 --- a/src/test/java/net/sf/jabref/logic/layout/format/FileLinkTest.java +++ b/src/test/java/net/sf/jabref/logic/layout/format/FileLinkTest.java @@ -21,40 +21,40 @@ public void setUp() throws Exception { @Test public void testEmpty() { - assertEquals("", new FileLink().format("")); + assertEquals("", new FileLink(Globals.prefs).format("")); } @Test public void testNull() { - assertEquals("", new FileLink().format(null)); + assertEquals("", new FileLink(Globals.prefs).format(null)); } @Test public void testOnlyFilename() { - assertEquals("test.pdf", new FileLink().format("test.pdf")); + assertEquals("test.pdf", new FileLink(Globals.prefs).format("test.pdf")); } @Test public void testCompleteRecord() { - assertEquals("test.pdf", new FileLink().format("paper:test.pdf:PDF")); + assertEquals("test.pdf", new FileLink(Globals.prefs).format("paper:test.pdf:PDF")); } @Test public void testMultipleFiles() { - ParamLayoutFormatter a = new FileLink(); + ParamLayoutFormatter a = new FileLink(Globals.prefs); assertEquals("test.pdf", a.format("paper:test.pdf:PDF;presentation:pres.ppt:PPT")); } @Test public void testMultipleFilesPick() { - ParamLayoutFormatter a = new FileLink(); + ParamLayoutFormatter a = new FileLink(Globals.prefs); a.setArgument("ppt"); assertEquals("pres.ppt", a.format("paper:test.pdf:PDF;presentation:pres.ppt:PPT")); } @Test public void testMultipleFilesPickNonExistant() { - ParamLayoutFormatter a = new FileLink(); + ParamLayoutFormatter a = new FileLink(Globals.prefs); a.setArgument("doc"); assertEquals("", a.format("paper:test.pdf:PDF;presentation:pres.ppt:PPT")); } diff --git a/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java b/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java index 65fa1cf5b06..5e39f3981ea 100644 --- a/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java +++ b/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java @@ -49,7 +49,7 @@ public void tearDown() { @Test public void testAuthorYear() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertTrue(style.isValid()); assertTrue(style.isFromResource()); @@ -67,7 +67,7 @@ public void testAuthorYearAsFile() throws URISyntaxException, IOException { File defFile = Paths.get(JabRefMain.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile(); - OOBibStyle style = new OOBibStyle(defFile, mock(JournalAbbreviationLoader.class), + OOBibStyle style = new OOBibStyle(defFile, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); assertTrue(style.isValid()); assertFalse(style.isFromResource()); @@ -82,7 +82,7 @@ public void testAuthorYearAsFile() throws URISyntaxException, IOException { @Test public void testNumerical() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertTrue(style.isValid()); assertFalse(style.isBibtexKeyCiteMarkers()); @@ -96,7 +96,7 @@ public void testNumerical() throws IOException { @Test public void testGetNumCitationMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertEquals("[1] ", style.getNumCitationMarker(Arrays.asList(1), -1, true)); assertEquals("[1]", style.getNumCitationMarker(Arrays.asList(1), -1, false)); @@ -113,7 +113,7 @@ public void testGetNumCitationMarker() throws IOException { @Test public void testGetNumCitationMarkerUndefined() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertEquals("[" + OOBibStyle.UNDEFINED_CITATION_MARKER + "; 2-4] ", style.getNumCitationMarker(Arrays.asList(4, 2, 3, 0), 1, true)); @@ -131,7 +131,7 @@ public void testGetNumCitationMarkerUndefined() throws IOException { @Test public void testGetCitProperty() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertEquals(", ", style.getStringCitProperty("AuthorSeparator")); assertEquals(3, style.getIntCitProperty("MaxAuthors")); @@ -146,7 +146,7 @@ public void testGetCitProperty() throws IOException { public void testGetCitationMarker() throws IOException { Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib"); ParserResult result = BibtexParser.parse(ImportFormat.getReader(testBibtexFile, StandardCharsets.UTF_8)); - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); BibDatabase db = result.getDatabase(); @@ -167,7 +167,7 @@ public void testGetCitationMarker() throws IOException { public void testLayout() throws IOException { Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib"); ParserResult result = BibtexParser.parse(ImportFormat.getReader(testBibtexFile, StandardCharsets.UTF_8)); - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); BibDatabase db = result.getDatabase(); @@ -187,7 +187,7 @@ public void testLayout() throws IOException { @Test public void testInstitutionAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); BibDatabase database = new BibDatabase(); @@ -206,7 +206,7 @@ public void testInstitutionAuthor() throws IOException { @Test public void testVonAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); BibDatabase database = new BibDatabase(); @@ -225,7 +225,7 @@ public void testVonAuthor() throws IOException { @Test public void testInstitutionAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -245,7 +245,7 @@ public void testInstitutionAuthorMarker() throws IOException { @Test public void testVonAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -265,7 +265,7 @@ public void testVonAuthorMarker() throws IOException { @Test public void testNullAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -283,7 +283,7 @@ public void testNullAuthorMarker() throws IOException { @Test public void testNullYearMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -301,7 +301,7 @@ public void testNullYearMarker() throws IOException { @Test public void testEmptyEntryMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -318,7 +318,7 @@ public void testEmptyEntryMarker() throws IOException { @Test public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -354,7 +354,7 @@ public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { @Test public void testGetCitationMarkerInTextUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -390,7 +390,7 @@ public void testGetCitationMarkerInTextUniquefiers() throws IOException { @Test public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -425,7 +425,7 @@ public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throw @Test public void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); @@ -461,9 +461,9 @@ public void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOExc @Test // TODO: equals only work when initialized from file, not from reader public void testEquals() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertEquals(style1, style2); } @@ -471,27 +471,27 @@ public void testEquals() throws IOException { @Test // TODO: equals only work when initialized from file, not from reader public void testNotEquals() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertNotEquals(style1, style2); } @Test public void testCompareToEqual() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertEquals(0, style1.compareTo(style2)); } @Test public void testCompareToNotEqual() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, mock(JournalAbbreviationLoader.class)); assertTrue(style1.compareTo(style2) > 0); assertFalse(style2.compareTo(style1) > 0); @@ -501,7 +501,7 @@ public void testCompareToNotEqual() throws IOException { @Ignore public void testEmptyStringPropertyAndOxfordComma() throws URISyntaxException, IOException { String fileName = Paths.get(OOBibStyleTest.class.getResource("test.jstyle").toURI()).toString(); - OOBibStyle style = new OOBibStyle(fileName, mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(fileName, Globals.prefs, mock(JournalAbbreviationLoader.class)); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); BibDatabase database = new BibDatabase(); diff --git a/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java b/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java index d86bd968523..7aa75441839 100644 --- a/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java +++ b/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java @@ -48,21 +48,21 @@ public void tearDown() throws Exception { @Test(expected = NullPointerException.class) public void throwNPEWithNullPreferences() { - loader = new StyleLoader(null, + loader = new StyleLoader(null, Globals.prefs, mock(JournalAbbreviationLoader.class), mock(Charset.class)); fail(); } @Test(expected = NullPointerException.class) public void throwNPEWithNullRepository() { - loader = new StyleLoader(mock(OpenOfficePreferences.class), + loader = new StyleLoader(mock(OpenOfficePreferences.class), Globals.prefs, null, mock(Charset.class)); fail(); } @Test(expected = NullPointerException.class) public void throwNPEWithNullCharset() { - loader = new StyleLoader(mock(OpenOfficePreferences.class), + loader = new StyleLoader(mock(OpenOfficePreferences.class), Globals.prefs, mock(JournalAbbreviationLoader.class), null); fail(); } @@ -70,7 +70,7 @@ public void throwNPEWithNullCharset() { @Test public void testGetStylesWithEmptyExternal() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); assertEquals(2, loader.getStyles().size()); @@ -79,7 +79,7 @@ public void testGetStylesWithEmptyExternal() { @Test public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); String filename = Paths.get(JabRefMain.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) @@ -92,7 +92,7 @@ public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { public void testAddInvalidStyleLeadsToNoMoreStyle() { preferences.setExternalStyles(Collections.emptyList()); Globals.prefs.putStringList(JabRefPreferences.OO_EXTERNAL_STYLE_FILES, Collections.emptyList()); - loader = new StyleLoader(preferences, + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); int beforeAdding = loader.getStyles().size(); loader.addStyleIfValid("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky"); @@ -104,7 +104,7 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { String filename = Paths.get(JabRefMain.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); preferences.setExternalStyles(Collections.singletonList(filename)); - loader = new StyleLoader(preferences, + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); assertEquals(numberOfInternalStyles + 1, loader.getStyles().size()); } @@ -113,7 +113,7 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { public void testInitalizeWithIncorrectExternalFile() { preferences.setExternalStyles(Collections.singletonList("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky")); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); assertEquals(numberOfInternalStyles, loader.getStyles().size()); } @@ -124,7 +124,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept .toFile().getPath(); preferences.setExternalStyles(Collections.singletonList(filename)); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); int beforeRemoving = loader.getStyles().size(); @@ -146,7 +146,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro .toFile().getPath(); preferences.setExternalStyles(Collections.singletonList(filename)); - loader = new StyleLoader(preferences, + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { @@ -164,7 +164,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro @Test public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); int beforeAdding = loader.getStyles().size(); String filename = Paths.get(JabRefMain.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) @@ -176,7 +176,7 @@ public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException @Test(expected = NullPointerException.class) public void testAddNullStyleThrowsNPE() { - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); loader.addStyleIfValid(null); fail(); @@ -186,7 +186,7 @@ public void testAddNullStyleThrowsNPE() { @Test public void testGetDefaultUsedStyleWhenEmpty() { Globals.prefs.remove(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); @@ -197,7 +197,7 @@ public void testGetDefaultUsedStyleWhenEmpty() { @Test public void testGetStoredUsedStyle() { preferences.setCurrentStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); @@ -208,7 +208,7 @@ public void testGetStoredUsedStyle() { @Test public void testGtDefaultUsedStyleWhenIncorrect() { preferences.setCurrentStyle("ljlkjlkjnljnvdlsjniuhwelfhuewfhlkuewhfuwhelu"); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); @@ -220,7 +220,7 @@ public void testGtDefaultUsedStyleWhenIncorrect() { public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, mock(JournalAbbreviationLoader.class), + loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { From a7ef1e8743f6da67a6a882642befb065f04cdab1 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 17 Jul 2016 02:01:13 +0200 Subject: [PATCH 05/17] Yes, even more injections --- src/main/java/net/sf/jabref/JabRefMain.java | 2 +- src/main/java/net/sf/jabref/MetaData.java | 2 +- .../net/sf/jabref/cli/ArgumentProcessor.java | 2 +- .../java/net/sf/jabref/gui/JabRefFrame.java | 2 +- .../sf/jabref/gui/exporter/ExportAction.java | 2 +- .../exporter/ExportCustomizationDialog.java | 56 +++++++++---------- .../gui/labelpattern/LabelPatternPanel.java | 2 +- .../gui/preftabs/PreferencesDialog.java | 2 +- .../logic/exporter/CustomExportList.java | 25 ++++----- .../logic/exporter/SavePreferences.java | 5 +- .../labelpattern/DatabaseLabelPattern.java | 11 +++- .../importer/fileformat/BibtexParserTest.java | 2 +- .../exporter/BibtexDatabaseWriterTest.java | 6 +- .../logic/exporter/ExportFormatTest.java | 2 +- .../logic/exporter/HtmlExportFormatTest.java | 2 +- 15 files changed, 64 insertions(+), 59 deletions(-) diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 1e774909ee8..51aa9a22c79 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -66,7 +66,7 @@ private static void start(String[] args) { /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); CustomEntryTypesManager.loadCustomEntryTypes(preferences); - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index de4646a4511..a9fd1cdf47f 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -238,7 +238,7 @@ public AbstractLabelPattern getLabelPattern() { return labelPattern; } - labelPattern = new DatabaseLabelPattern(); + labelPattern = new DatabaseLabelPattern(Globals.prefs); // read the data from the metadata and store it into the labelPattern for (String key : this) { diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 015e3edde31..4f61e9976a1 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -390,7 +390,7 @@ private void importPreferences() { try { Globals.prefs.importPreferences(cli.getPreferencesImport()); CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs); - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); } catch (JabRefException ex) { LOGGER.error("Cannot import preferences", ex); } diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index c3c7a04ed29..43eb7976d41 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -776,7 +776,7 @@ private void tearDownJabRef(List filenames) { } fileHistory.storeHistory(); - prefs.customExports.store(); + prefs.customExports.store(Globals.prefs); prefs.customImports.store(); CustomEntryTypesManager.saveCustomEntryTypes(prefs); diff --git a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java index 62687fda83f..bef252b3c06 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportAction.java @@ -59,7 +59,7 @@ public InternalExportAction(JabRefFrame frame, boolean selectedOnly) { @Override public void actionPerformed(ActionEvent e) { - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); JFileChooser fc = ExportAction .createExportFileChooser(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY)); fc.showSaveDialog(frame); diff --git a/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java b/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java index d2c8bae31b6..6d9e228ebb8 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java +++ b/src/main/java/net/sf/jabref/gui/exporter/ExportCustomizationDialog.java @@ -91,43 +91,43 @@ public ExportCustomizationDialog(final JabRefFrame frame) { if (ecd.okPressed()) { List newFormat = Arrays.asList(ecd.name(), ecd.layoutFile(), ecd.extension()); Globals.prefs.customExports.addFormat(newFormat); - Globals.prefs.customExports.store(); + Globals.prefs.customExports.store(Globals.prefs); } }); JButton modify = new JButton(Localization.lang("Modify")); modify.addActionListener(e -> { - int row = table.getSelectedRow(); - if (row == -1) { - return; - } - List old = Globals.prefs.customExports.getSortedList().get(row); - CustomExportDialog ecd = new CustomExportDialog(frame, old.get(0), old.get(1), old.get(2)); - ecd.setVisible(true); // ecd.show(); -> deprecated since 1.5 - if (ecd.okPressed()) { - old.set(0, ecd.name()); - old.set(1, ecd.layoutFile()); - old.set(2, ecd.extension()); - table.revalidate(); - table.repaint(); - Globals.prefs.customExports.store(); - } + int row = table.getSelectedRow(); + if (row == -1) { + return; + } + List old = Globals.prefs.customExports.getSortedList().get(row); + CustomExportDialog ecd = new CustomExportDialog(frame, old.get(0), old.get(1), old.get(2)); + ecd.setVisible(true); // ecd.show(); -> deprecated since 1.5 + if (ecd.okPressed()) { + old.set(0, ecd.name()); + old.set(1, ecd.layoutFile()); + old.set(2, ecd.extension()); + table.revalidate(); + table.repaint(); + Globals.prefs.customExports.store(Globals.prefs); + } }); JButton remove = new JButton(Localization.lang("Remove")); remove.addActionListener(e -> { - int[] rows = table.getSelectedRows(); - if (rows.length == 0) { - return; - } - List> entries = new ArrayList<>(); - for (int i = 0; i < rows.length; i++) { - entries.add(Globals.prefs.customExports.getSortedList().get(rows[i])); - } - for (List list : entries) { - Globals.prefs.customExports.remove(list); - } - Globals.prefs.customExports.store(); + int[] rows = table.getSelectedRows(); + if (rows.length == 0) { + return; + } + List> entries = new ArrayList<>(); + for (int i = 0; i < rows.length; i++) { + entries.add(Globals.prefs.customExports.getSortedList().get(rows[i])); + } + for (List list : entries) { + Globals.prefs.customExports.remove(list); + } + Globals.prefs.customExports.store(Globals.prefs); }); Action closeAction = new AbstractAction() { diff --git a/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java b/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java index 2e72afc14af..f1a96fe418b 100644 --- a/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java +++ b/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java @@ -245,7 +245,7 @@ protected GlobalLabelPattern getLabelPatternAsGlobalLabelPattern() { } public DatabaseLabelPattern getLabelPatternAsDatabaseLabelPattern() { - DatabaseLabelPattern res = new DatabaseLabelPattern(); + DatabaseLabelPattern res = new DatabaseLabelPattern(Globals.prefs); fillPatternUsingPanelData(res); return res; } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index 1cf9096d17d..5d167a3b9a1 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -236,7 +236,7 @@ public PreferencesDialog(JabRefFrame parent) { private void updateAfterPreferenceChanges() { setValues(); - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); frame.removeCachedEntryEditors(); Globals.prefs.updateEntryEditorTabList(); } diff --git a/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java b/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java index 7b3ab7786a7..855c41fad37 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java +++ b/src/main/java/net/sf/jabref/logic/exporter/CustomExportList.java @@ -21,7 +21,6 @@ import java.util.Optional; import java.util.TreeMap; -import net.sf.jabref.Globals; import net.sf.jabref.preferences.JabRefPreferences; import ca.odell.glazedlists.BasicEventList; @@ -52,9 +51,9 @@ public CustomExportList(Comparator> comp) { sorted = new SortedList<>(list, comp); } - public Map getCustomExportFormats() { + public Map getCustomExportFormats(JabRefPreferences prefs) { formats.clear(); - readPrefs(); + readPrefs(prefs); return formats; } @@ -66,18 +65,18 @@ public EventList> getSortedList() { return sorted; } - private void readPrefs() { + private void readPrefs(JabRefPreferences prefs) { formats.clear(); list.clear(); int i = 0; List s; - while (!((s = Globals.prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { + while (!((s = prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { Optional format = createFormat(s); if (format.isPresent()) { formats.put(format.get().getConsoleName(), format.get()); list.add(s); } else { - String customExportFormat = Globals.prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); + String customExportFormat = prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); LOGGER.error("Error initializing custom export format from string " + customExportFormat); } i++; @@ -113,22 +112,22 @@ public void remove(List toRemove) { }); } - public void store() { + public void store(JabRefPreferences prefs) { if (list.isEmpty()) { - purge(0); + purge(0, prefs); } else { for (int i = 0; i < list.size(); i++) { - Globals.prefs.putStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i, list.get(i)); + prefs.putStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i, list.get(i)); } - purge(list.size()); + purge(list.size(), prefs); } } - private void purge(int from) { + private void purge(int from, JabRefPreferences prefs) { int i = from; - while (!Globals.prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i).isEmpty()) { - Globals.prefs.remove(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); + while (!prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i).isEmpty()) { + prefs.remove(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); i++; } } diff --git a/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java index d482609035a..23ffe25e3dd 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java +++ b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java @@ -2,7 +2,6 @@ import java.nio.charset.Charset; -import net.sf.jabref.Globals; import net.sf.jabref.logic.config.SaveOrderConfig; import net.sf.jabref.preferences.JabRefPreferences; @@ -32,10 +31,10 @@ public SavePreferences(Boolean saveInOriginalOrder, SaveOrderConfig saveOrder, C } public static SavePreferences loadForExportFromPreferences(JabRefPreferences preferences) { - Boolean saveInOriginalOrder = Globals.prefs.getBoolean(JabRefPreferences.EXPORT_IN_ORIGINAL_ORDER); + Boolean saveInOriginalOrder = preferences.getBoolean(JabRefPreferences.EXPORT_IN_ORIGINAL_ORDER); SaveOrderConfig saveOrder = null; if (!saveInOriginalOrder) { - if (Globals.prefs.getBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER)) { + if (preferences.getBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER)) { saveOrder = SaveOrderConfig.loadExportSaveOrderFromPreferences(preferences); } else { saveOrder = SaveOrderConfig.loadTableSaveOrderFromPreferences(preferences); diff --git a/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java b/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java index 2e10becff78..c341a6fabd4 100644 --- a/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java +++ b/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java @@ -17,13 +17,20 @@ import java.util.List; -import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; public class DatabaseLabelPattern extends AbstractLabelPattern { + private final JabRefPreferences prefs; + + + public DatabaseLabelPattern(JabRefPreferences prefs) { + this.prefs = prefs; + } + @Override public List getLastLevelLabelPattern(String key) { - return Globals.prefs.getKeyPattern().getValue(key); + return prefs.getKeyPattern().getValue(key); } } diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index c5d77dc8f8a..69d15d63255 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -1393,7 +1393,7 @@ public void integrationTestCustomKeyPattern() throws IOException { AbstractLabelPattern labelPattern = result.getMetaData().getLabelPattern(); - AbstractLabelPattern expectedPattern = new DatabaseLabelPattern(); + AbstractLabelPattern expectedPattern = new DatabaseLabelPattern(Globals.prefs); expectedPattern.setDefaultValue("test"); expectedPattern.addLabelPattern("article", "articleTest"); diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index aa597b1d4a4..fb980313f4f 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -155,7 +155,7 @@ public void writeEpilogueAndEncoding() throws Exception { @Test public void writeMetadata() throws Exception { - DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(); + DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(Globals.prefs); labelPattern.setDefaultValue("test"); metaData.setLabelPattern(labelPattern); @@ -168,7 +168,7 @@ public void writeMetadata() throws Exception { @Test public void writeMetadataAndEncoding() throws Exception { SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII); - DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(); + DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(Globals.prefs); labelPattern.setDefaultValue("test"); metaData.setLabelPattern(labelPattern); @@ -420,7 +420,7 @@ public void writeSaveOrderConfig() throws Exception { @Test public void writeCustomKeyPattern() throws Exception { - AbstractLabelPattern pattern = new DatabaseLabelPattern(); + AbstractLabelPattern pattern = new DatabaseLabelPattern(Globals.prefs); pattern.setDefaultValue("test"); pattern.addLabelPattern("article", "articleTest"); metaData.setLabelPattern(pattern); diff --git a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java index 91b34867549..cd3800762c7 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/ExportFormatTest.java @@ -78,7 +78,7 @@ public void testExportingNullEntriesThrowsNPE() throws Exception { public static Collection exportFormats() { Collection result = new ArrayList<>(); Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); for (IExportFormat format : ExportFormats.getExportFormats().values()) { result.add(new Object[] {format, format.getDisplayName()}); } diff --git a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java index 8cda903c0a3..2ff764799ce 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/HtmlExportFormatTest.java @@ -35,7 +35,7 @@ public class HtmlExportFormatTest { @Before public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); - ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats()); + ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); exportFormat = ExportFormats.getExportFormat("html"); Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); From 77b3c6f985a2f45bc2f48036eb8d393765e5871b Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 17 Jul 2016 02:13:45 +0200 Subject: [PATCH 06/17] Indeed, even more injections --- src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java | 7 +++---- .../net/sf/jabref/logic/layout/format/NameFormatter.java | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index c130211b403..08c0d520baf 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -26,7 +26,6 @@ import java.util.regex.Pattern; import net.sf.jabref.BibDatabaseContext; -import net.sf.jabref.Globals; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; @@ -582,15 +581,15 @@ private List getOptionalLayout(String formatterName) { List results = new ArrayList<>(formatterStrings.size()); - Map userNameFormatter = NameFormatter.getNameFormatters(); + Map userNameFormatter = NameFormatter.getNameFormatters(prefs); for (List strings : formatterStrings) { String className = strings.get(0).trim(); // Check if this is a name formatter defined by this export filter: - if (Globals.prefs.customExportNameFormatters != null) { - String contents = Globals.prefs.customExportNameFormatters.get(className); + if (prefs.customExportNameFormatters != null) { + String contents = prefs.customExportNameFormatters.get(className); if (contents != null) { NameFormatter nf = new NameFormatter(); nf.setParameter(contents); diff --git a/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java index 5f781287662..b1bfd534ab3 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Map; -import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.bst.BibtexNameFormatter; import net.sf.jabref.logic.layout.LayoutFormatter; import net.sf.jabref.model.entry.AuthorList; @@ -184,12 +184,12 @@ public void setParameter(String parameter) { this.parameter = parameter; } - public static Map getNameFormatters() { + public static Map getNameFormatters(JabRefPreferences prefs) { Map result = new HashMap<>(); - List names = Globals.prefs.getStringList(NameFormatter.NAME_FORMATER_KEY); - List formats = Globals.prefs.getStringList(NameFormatter.NAME_FORMATTER_VALUE); + List names = prefs.getStringList(NameFormatter.NAME_FORMATER_KEY); + List formats = prefs.getStringList(NameFormatter.NAME_FORMATTER_VALUE); for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { From cc3a821c520a71d917b5958103f718dfceacd9d2 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 17 Jul 2016 15:05:33 +0200 Subject: [PATCH 07/17] Probably the last injections for now --- .../net/sf/jabref/benchmarks/Benchmarks.java | 11 ++- src/main/java/net/sf/jabref/JabRefMain.java | 2 +- .../net/sf/jabref/cli/ArgumentProcessor.java | 5 +- .../net/sf/jabref/collab/ChangeScanner.java | 2 +- .../java/net/sf/jabref/gui/BasePanel.java | 6 +- .../gui/entryeditor/FieldExtraComponents.java | 3 +- .../jabref/gui/exporter/AutoSaveManager.java | 2 +- .../gui/exporter/SaveDatabaseAction.java | 2 +- .../sf/jabref/gui/groups/AutoGroupDialog.java | 5 +- .../net/sf/jabref/gui/groups/GroupDialog.java | 12 +-- .../jabref/gui/journals/AbbreviateAction.java | 2 +- .../gui/journals/ManageJournalsPanel.java | 2 +- .../gui/journals/UnabbreviateAction.java | 2 +- .../sf/jabref/gui/preftabs/TablePrefsTab.java | 2 +- .../jabref/importer/AppendDatabaseAction.java | 2 +- .../importer/fetcher/ACMPortalFetcher.java | 3 +- .../importer/fetcher/IEEEXploreFetcher.java | 6 +- .../autocompleter/AutoCompleterFactory.java | 8 +- .../autocompleter/ContentAutoCompleters.java | 6 +- .../autocompleter/JournalAutoCompleter.java | 9 ++- .../logic/exporter/BibtexDatabaseWriter.java | 9 ++- .../sf/jabref/logic/formatter/Formatters.java | 2 +- .../bibtexfields/HtmlToLatexFormatter.java | 10 ++- .../sf/jabref/logic/groups/ExplicitGroup.java | 12 +-- .../sf/jabref/logic/groups/KeywordGroup.java | 19 ++--- .../sf/jabref/logic/groups/SearchGroup.java | 14 ++-- .../journals/JournalAbbreviationLoader.java | 5 +- .../sf/jabref/logic/layout/LayoutEntry.java | 4 +- .../layout/format/JournalAbbreviator.java | 8 +- .../model/entry/InternalBibtexFields.java | 22 +++--- .../jabref/preferences/JabRefPreferences.java | 2 +- .../jabref/sql/importer/DatabaseImporter.java | 7 +- .../ConvertLegacyExplicitGroupsTest.java | 4 +- .../importer/fileformat/BibtexParserTest.java | 6 +- .../AutoCompleterFactoryTest.java | 7 +- .../logic/cleanup/CleanupWorkerTest.java | 3 +- .../exporter/BibtexDatabaseWriterTest.java | 7 +- .../jabref/logic/formatter/FormatterTest.java | 2 +- .../HtmlToLatexFormatterTest.java | 2 +- .../logic/groups/ExplicitGroupTest.java | 4 +- .../logic/groups/GroupTreeNodeTest.java | 76 +++++++++++-------- .../jabref/logic/groups/KeywordGroupTest.java | 26 ++++--- .../jabref/logic/groups/SearchGroupTest.java | 6 +- .../logic/journals/AbbreviationsTest.java | 10 +-- .../jabref/sql/DatabaseImportExportTests.java | 3 +- 45 files changed, 213 insertions(+), 149 deletions(-) diff --git a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java index e1a03ce0423..e022055a267 100644 --- a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java @@ -60,7 +60,8 @@ public void init() throws Exception { entry.setField("rnd", "2" + randomizer.nextInt()); database.insertEntry(entry); } - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, + Globals.prefs); StringSaveSession saveSession = databaseWriter.savePartOfDatabase( new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences()); @@ -80,7 +81,8 @@ public ParserResult parse() throws IOException { @Benchmark public String write() throws Exception { - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, + Globals.prefs); StringSaveSession saveSession = databaseWriter.savePartOfDatabase( new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences()); @@ -115,14 +117,15 @@ public String latexToHTMLConversion() { @Benchmark public String htmlToLatexConversion() { - HtmlToLatexFormatter f = new HtmlToLatexFormatter(); + HtmlToLatexFormatter f = new HtmlToLatexFormatter( + Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); return f.format(htmlConversionString); } @Benchmark public boolean keywordGroupContains() throws ParseException { KeywordGroup group = new KeywordGroup("testGroup", "keyword", "testkeyword", false, false, - GroupHierarchyType.INDEPENDENT); + GroupHierarchyType.INDEPENDENT, Globals.prefs); return group.containsAll(database.getEntries()); } diff --git a/src/main/java/net/sf/jabref/JabRefMain.java b/src/main/java/net/sf/jabref/JabRefMain.java index 51aa9a22c79..4470fc7aed1 100644 --- a/src/main/java/net/sf/jabref/JabRefMain.java +++ b/src/main/java/net/sf/jabref/JabRefMain.java @@ -61,7 +61,7 @@ private static void start(String[] args) { Globals.prefs.setLanguageDependentDefaultValues(); // Update which fields should be treated as numeric, based on preferences: - InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs); + InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 4f61e9976a1..9d1fe06ee9a 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -288,7 +288,7 @@ private boolean generateAux(List loaded, String[] data) { try { System.out.println(Localization.lang("Saving") + ": " + subName); SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); Defaults defaults = new Defaults(BibDatabaseMode .fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); SaveSession session = databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults), @@ -332,7 +332,8 @@ private void exportFile(List loaded, String[] data) { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs); Defaults defaults = new Defaults(BibDatabaseMode.fromPreference( Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, + Globals.prefs); SaveSession session = databaseWriter.saveDatabase( new BibDatabaseContext(pr.getDatabase(), pr.getMetaData(), defaults), prefs); diff --git a/src/main/java/net/sf/jabref/collab/ChangeScanner.java b/src/main/java/net/sf/jabref/collab/ChangeScanner.java index ab9987a9a42..f15942b6551 100644 --- a/src/main/java/net/sf/jabref/collab/ChangeScanner.java +++ b/src/main/java/net/sf/jabref/collab/ChangeScanner.java @@ -167,7 +167,7 @@ private void storeTempDatabase() { Defaults defaults = new Defaults(BibDatabaseMode .fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(inTemp, mdInTemp, defaults), prefs); ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle())); } catch (SaveException ex) { diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 8e0f54bfaff..a73d38262e7 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1105,7 +1105,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(enc) .withSaveType(saveType); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(), prefs); } else { @@ -1572,7 +1572,7 @@ public void setupMainPanel() { // Set up AutoCompleters for this panel: if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { autoCompleters = new ContentAutoCompleters(getDatabase(), bibDatabaseContext.getMetaData(), - autoCompletePreferences, Globals.journalAbbreviationLoader); + autoCompletePreferences, Globals.journalAbbreviationLoader, Globals.prefs); // ensure that the autocompleters are in sync with entries this.getDatabase().registerListener(new AutoCompleteListener()); } else { @@ -1598,7 +1598,7 @@ public void updateSearchManager() { private void instantiateSearchAutoCompleter() { AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(autoCompletePreferences, - Globals.journalAbbreviationLoader); + Globals.journalAbbreviationLoader, Globals.prefs); searchAutoCompleter = autoCompleterFactory.getPersonAutoCompleter(); for (BibEntry entry : database.getEntries()) { searchAutoCompleter.addBibtexEntry(entry); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java b/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java index 9581d91a74f..cdcf17a4e57 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java @@ -93,7 +93,8 @@ public static Optional getJournalExtraComponent(JabRefFrame frame, B button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT); button.addActionListener(actionEvent -> { String text = editor.getText(); - JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader.getRepository(); + JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader + .getRepository(Globals.prefs); if (abbreviationRepository.isKnownName(text)) { String s = abbreviationRepository.getNextAbbreviation(text).orElse(text); diff --git a/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java index e1e06b55b0e..0ca3d1111e5 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java +++ b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java @@ -102,7 +102,7 @@ private static boolean autoSave(BasePanel panel) { .withMakeBackup(false) .withEncoding(panel.getBibDatabaseContext().getMetaData().getEncoding()); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); SaveSession ss = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); ss.commit(backupFile.toPath()); } catch (SaveException e) { diff --git a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index a36a6593518..29fdc4f7a2a 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -173,7 +173,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs); diff --git a/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java b/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java index 335f1470d10..8f658a05a17 100644 --- a/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java +++ b/src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java @@ -94,7 +94,8 @@ public void actionPerformed(ActionEvent e) { try { GroupTreeNode autoGroupsRoot = GroupTreeNode.fromGroup( - new ExplicitGroup(Localization.lang("Automatically created groups"), GroupHierarchyType.INCLUDING)); + new ExplicitGroup(Localization.lang("Automatically created groups"), + GroupHierarchyType.INCLUDING, Globals.prefs)); Set hs; String fieldText = field.getText(); if (keywords.isSelected()) { @@ -120,7 +121,7 @@ public void actionPerformed(ActionEvent e) { for (String keyword : hs) { KeywordGroup group = new KeywordGroup(keyword, fieldText, keyword, false, false, - GroupHierarchyType.INDEPENDENT); + GroupHierarchyType.INDEPENDENT, Globals.prefs); autoGroupsRoot.addChild(GroupTreeNode.fromGroup(group)); } diff --git a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java index a5aa095174d..2acb30890e4 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java @@ -279,21 +279,21 @@ public void actionPerformed(ActionEvent e) { isOkPressed = true; try { if (explicitRadioButton.isSelected()) { - resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext()); + resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext(), Globals.prefs); } else if (keywordsRadioButton.isSelected()) { // regex is correct, otherwise OK would have been disabled // therefore I don't catch anything here resultingGroup = new KeywordGroup(nameField.getText().trim(), keywordGroupSearchField.getText().trim(), keywordGroupSearchTerm.getText().trim(), keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp .isSelected(), - getContext()); + getContext(), Globals.prefs); } else if (searchRadioButton.isSelected()) { try { // regex is correct, otherwise OK would have been // disabled // therefore I don't catch anything here resultingGroup = new SearchGroup(nameField.getText().trim(), searchGroupSearchExpression.getText().trim(), - isCaseSensitive(), isRegex(), getContext()); + isCaseSensitive(), isRegex(), getContext(), Globals.prefs); } catch (Exception e1) { // should never happen } @@ -317,7 +317,7 @@ public void actionPerformed(ActionEvent e) { searchGroupCaseSensitive.addItemListener(itemListener); // configure for current type - if (editedGroup != null && editedGroup.getClass() == KeywordGroup.class) { + if ((editedGroup != null) && (editedGroup.getClass() == KeywordGroup.class)) { KeywordGroup group = (KeywordGroup) editedGroup; nameField.setText(group.getName()); keywordGroupSearchField.setText(group.getSearchField()); @@ -326,7 +326,7 @@ public void actionPerformed(ActionEvent e) { keywordGroupRegExp.setSelected(group.isRegExp()); keywordsRadioButton.setSelected(true); setContext(editedGroup.getHierarchicalContext()); - } else if (editedGroup != null && editedGroup.getClass() == SearchGroup.class) { + } else if ((editedGroup != null) && (editedGroup.getClass() == SearchGroup.class)) { SearchGroup group = (SearchGroup) editedGroup; nameField.setText(group.getName()); searchGroupSearchExpression.setText(group.getSearchExpression()); @@ -334,7 +334,7 @@ public void actionPerformed(ActionEvent e) { searchGroupRegExp.setSelected(group.isRegExp()); searchRadioButton.setSelected(true); setContext(editedGroup.getHierarchicalContext()); - } else if (editedGroup != null && editedGroup.getClass() == ExplicitGroup.class) { + } else if ((editedGroup != null) && (editedGroup.getClass() == ExplicitGroup.class)) { nameField.setText(editedGroup.getName()); explicitRadioButton.setSelected(true); setContext(editedGroup.getHierarchicalContext()); diff --git a/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java b/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java index ffebc4c9776..f06c182af81 100644 --- a/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java +++ b/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java @@ -52,7 +52,7 @@ public void run() { } UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator( - Globals.journalAbbreviationLoader.getRepository(), iso); + Globals.journalAbbreviationLoader.getRepository(Globals.prefs), iso); NamedCompound ce = new NamedCompound(Localization.lang("Abbreviate journal names")); int count = 0; diff --git a/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java b/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java index 3cd0c8e4124..f50afa9a5e9 100644 --- a/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java +++ b/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java @@ -185,7 +185,7 @@ public ManageJournalsPanel(final JabRefFrame frame) { viewBuiltin.addActionListener(e -> { JTable table = new JTable(JournalAbbreviationsUtil - .getTableModel(Globals.journalAbbreviationLoader.getRepository().getAbbreviations())); + .getTableModel(Globals.journalAbbreviationLoader.getRepository(Globals.prefs).getAbbreviations())); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); diff --git a/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java b/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java index 8d12b4b983b..73a11e3aaa9 100644 --- a/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java +++ b/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java @@ -50,7 +50,7 @@ public void run() { } UndoableUnabbreviator undoableAbbreviator = new UndoableUnabbreviator( - Globals.journalAbbreviationLoader.getRepository()); + Globals.journalAbbreviationLoader.getRepository(Globals.prefs)); NamedCompound ce = new NamedCompound(Localization.lang("Unabbreviate journal names")); int count = 0; diff --git a/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java b/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java index 61b79f6d1c1..70ee52724a3 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/TablePrefsTab.java @@ -301,7 +301,7 @@ public void storeSettings() { } if (!Objects.equals(oldVal, newVal)) { prefs.put(JabRefPreferences.NUMERIC_FIELDS, newVal); - InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs); + InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); } } diff --git a/src/main/java/net/sf/jabref/importer/AppendDatabaseAction.java b/src/main/java/net/sf/jabref/importer/AppendDatabaseAction.java index 8f83a6618a6..61b8c67cd42 100644 --- a/src/main/java/net/sf/jabref/importer/AppendDatabaseAction.java +++ b/src/main/java/net/sf/jabref/importer/AppendDatabaseAction.java @@ -168,7 +168,7 @@ private static void mergeFromBibtex(JabRefFrame frame, BasePanel panel, ParserRe // create a dummy group ExplicitGroup group = null; try { - group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT); + group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs); } catch (ParseException e) { LOGGER.error(e); } diff --git a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java index 4d019069515..2048a1271ba 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java @@ -62,7 +62,8 @@ public class ACMPortalFetcher implements PreviewEntryFetcher { private static final Log LOGGER = LogFactory.getLog(ACMPortalFetcher.class); - private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(); + private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter( + Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter(); private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter(); private String terms; diff --git a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java index 44495c2deaf..d6d2372be57 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java @@ -81,7 +81,8 @@ public class IEEEXploreFetcher implements EntryFetcher { private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter(); private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter(); - private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(); + private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter( + Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); private final JCheckBox absCheckBox = new JCheckBox(Localization.lang("Include abstracts"), false); private boolean shouldContinue; @@ -444,7 +445,8 @@ private BibEntry cleanup(BibEntry entry) { fullName = fullName.trim(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) { - fullName = abbreviationLoader.getRepository().getMedlineAbbreviation(fullName).orElse(fullName); + fullName = abbreviationLoader.getRepository(Globals.prefs).getMedlineAbbreviation(fullName) + .orElse(fullName); } } if ("inproceedings".equals(type)) { diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java index 9e9f4f7d2c4..31c744e1e96 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.entry.FieldProperties; import net.sf.jabref.model.entry.InternalBibtexFields; @@ -31,10 +32,13 @@ public class AutoCompleterFactory { private final AutoCompletePreferences preferences; private final JournalAbbreviationLoader abbreviationLoader; + private final JabRefPreferences jabRefPreferences; - public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { + public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader, + JabRefPreferences jabRefPreferences) { this.preferences = Objects.requireNonNull(preferences); this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); + this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); } public AutoCompleter getFor(String fieldName) { @@ -45,7 +49,7 @@ public AutoCompleter getFor(String fieldName) { } else if ("crossref".equals(fieldName)) { return new BibtexKeyAutoCompleter(preferences); } else if ("journal".equals(fieldName) || "publisher".equals(fieldName)) { - return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader); + return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader, jabRefPreferences); } else { return new DefaultAutoCompleter(fieldName, preferences); } diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java b/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java index 2951af38ae9..b71f0bbf725 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java @@ -4,6 +4,7 @@ import java.util.Map; import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.database.BibDatabase; @@ -14,10 +15,11 @@ public ContentAutoCompleters() { } public ContentAutoCompleters(BibDatabase database, MetaData metaData, AutoCompletePreferences preferences, - JournalAbbreviationLoader abbreviationLoader) { + JournalAbbreviationLoader abbreviationLoader, JabRefPreferences jabRefPreferences) { Objects.requireNonNull(preferences); - AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); + AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader, + jabRefPreferences); List completeFields = preferences.getCompleteNames(); for (String field : completeFields) { AutoCompleter autoCompleter = autoCompleterFactory.getFor(field); diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java b/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java index 51cc5afb1fd..ca5e878116f 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java @@ -20,16 +20,21 @@ import java.util.List; import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.Abbreviation; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; public class JournalAutoCompleter extends EntireFieldAutoCompleter { private final JournalAbbreviationLoader abbreviationLoader; + private final JabRefPreferences jabRefPreferences; - JournalAutoCompleter(String fieldName, AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { + + JournalAutoCompleter(String fieldName, AutoCompletePreferences preferences, + JournalAbbreviationLoader abbreviationLoader, JabRefPreferences jabRefPreferences) { super(fieldName, preferences); this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); + this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); } @Override @@ -37,7 +42,7 @@ public List complete(String toComplete) { List completions = super.complete(toComplete); // Also return journal names in the journal abbreviation list - for (Abbreviation abbreviation : abbreviationLoader.getRepository().getAbbreviations()) { + for (Abbreviation abbreviation : abbreviationLoader.getRepository(jabRefPreferences).getAbbreviations()) { if (abbreviation.getName().startsWith(toComplete)) { completions.add(abbreviation.getName()); } diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index 7e014197794..9396dfe01db 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -22,6 +22,7 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; @@ -37,8 +38,10 @@ public class BibtexDatabaseWriter extends BibDatabaseWrit private static final String COMMENT_PREFIX = "@Comment"; private static final String PREAMBLE_PREFIX = "@Preamble"; - public BibtexDatabaseWriter(SaveSessionFactory saveSessionFactory) { + private final JabRefPreferences jabRefPreferences; + public BibtexDatabaseWriter(SaveSessionFactory saveSessionFactory, JabRefPreferences jabRefPreferences) { super(saveSessionFactory); + this.jabRefPreferences = jabRefPreferences; } @Override @@ -109,7 +112,7 @@ protected void writeString(BibtexString bibtexString, boolean isFirstString, int getWriter().write("{}"); } else { try { - String formatted = new LatexFieldFormatter(Globals.prefs).format(bibtexString.getContent(), + String formatted = new LatexFieldFormatter(jabRefPreferences).format(bibtexString.getContent(), LatexFieldFormatter.BIBTEX_STRING); getWriter().write(formatted); } catch (IllegalArgumentException ex) { @@ -155,7 +158,7 @@ protected void writePrelogue(BibDatabaseContext bibDatabaseContext, Charset enco @Override protected void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile) throws SaveException { - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(jabRefPreferences), true); try { bibtexEntryWriter.write(entry, getWriter(), mode, isReformatFile); } catch (IOException e) { diff --git a/src/main/java/net/sf/jabref/logic/formatter/Formatters.java b/src/main/java/net/sf/jabref/logic/formatter/Formatters.java index c4d70477409..68c93a25d56 100644 --- a/src/main/java/net/sf/jabref/logic/formatter/Formatters.java +++ b/src/main/java/net/sf/jabref/logic/formatter/Formatters.java @@ -45,7 +45,7 @@ public class Formatters { public static final List CONVERTERS = Arrays.asList( - new HtmlToLatexFormatter(), + new HtmlToLatexFormatter(false), // TODO: Get the correct value from USE_CONVERT_TO_EQUATION new HtmlToUnicodeFormatter(), new LatexToUnicodeFormatter(), new UnicodeToLatexFormatter() diff --git a/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java b/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java index 875c4745de9..ebf06cc28c1 100644 --- a/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java +++ b/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java @@ -20,12 +20,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sf.jabref.Globals; import net.sf.jabref.logic.formatter.Formatter; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.layout.LayoutFormatter; import net.sf.jabref.logic.util.strings.HTMLUnicodeConversionMaps; -import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,6 +39,12 @@ public class HtmlToLatexFormatter implements LayoutFormatter, Formatter { private static final Pattern ESCAPED_PATTERN3 = Pattern.compile("&#([x]*)([0]*)(\\p{XDigit}+);"); private static final Pattern ESCAPED_PATTERN4 = Pattern.compile("&(\\w+);"); + private final boolean convertToEquation; + + + public HtmlToLatexFormatter(boolean convertToEquation) { + this.convertToEquation = convertToEquation; + } @Override public String format(String text) { @@ -54,7 +58,7 @@ public String format(String text) { // Deal with the form kand k // If the result is in text or equation form can be controlled // From the "Advanced settings" tab - if (Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)) { + if (convertToEquation) { result = result.replaceAll("<[ ]?sup>([^<]+)", "\\$\\^\\{$1\\}\\$"); result = result.replaceAll("<[ ]?sub>([^<]+)", "\\$_\\{$1\\}\\$"); } else { diff --git a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java index fc3a801b076..6c796ead849 100644 --- a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java @@ -21,6 +21,7 @@ import java.util.Set; import java.util.TreeSet; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; @@ -42,11 +43,12 @@ public class ExplicitGroup extends KeywordGroup { private static final Log LOGGER = LogFactory.getLog(ExplicitGroup.class); - public ExplicitGroup(String name, GroupHierarchyType context) throws ParseException { - super(name, "groups", name, true, false, context); + public ExplicitGroup(String name, GroupHierarchyType context, JabRefPreferences jabRefPreferences) + throws ParseException { + super(name, "groups", name, true, false, context, jabRefPreferences); } - public static ExplicitGroup fromString(String s) throws ParseException { + public static ExplicitGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { if (!s.startsWith(ExplicitGroup.ID)) { throw new IllegalArgumentException("ExplicitGroup cannot be created from \"" + s + "\"."); } @@ -55,7 +57,7 @@ public static ExplicitGroup fromString(String s) throws ParseException { String name = tok.nextToken(); int context = Integer.parseInt(tok.nextToken()); - ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumber(context)); + ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumber(context), jabRefPreferences); newGroup.addLegacyEntryKeys(tok); return newGroup; } @@ -80,7 +82,7 @@ public void addLegacyEntryKey(String key) { @Override public AbstractGroup deepCopy() { try { - ExplicitGroup copy = new ExplicitGroup(getName(), getContext()); + ExplicitGroup copy = new ExplicitGroup(getName(), getContext(), jabRefPreferences); copy.legacyEntryKeys.addAll(legacyEntryKeys); return copy; } catch (ParseException exception) { diff --git a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java index 257df6c1114..679f51c29ca 100644 --- a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java @@ -22,7 +22,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import net.sf.jabref.Globals; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; @@ -47,7 +46,8 @@ public class KeywordGroup extends AbstractGroup { private final boolean caseSensitive; private final boolean regExp; private Pattern pattern; - private List searchWords; + private final List searchWords; + protected final JabRefPreferences jabRefPreferences; private static final Log LOGGER = LogFactory.getLog(KeywordGroup.class); @@ -57,7 +57,7 @@ public class KeywordGroup extends AbstractGroup { */ public KeywordGroup(String name, String searchField, String searchExpression, boolean caseSensitive, boolean regExp, - GroupHierarchyType context) throws ParseException { + GroupHierarchyType context, JabRefPreferences jabRefPreferences) throws ParseException { super(name, context); this.searchField = searchField; this.searchExpression = searchExpression; @@ -66,6 +66,7 @@ public KeywordGroup(String name, String searchField, if (this.regExp) { compilePattern(); } + this.jabRefPreferences = jabRefPreferences; this.searchWords = EntryUtil.getStringAsWords(searchExpression); } @@ -84,7 +85,7 @@ private void compilePattern() throws ParseException { * @param s The String representation obtained from * KeywordGroup.toString() */ - public static AbstractGroup fromString(String s) throws ParseException { + public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { if (!s.startsWith(KeywordGroup.ID)) { throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\"."); } @@ -100,7 +101,7 @@ public static AbstractGroup fromString(String s) throws ParseException { return new KeywordGroup(StringUtil.unquote(name, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(field, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(expression, AbstractGroup.QUOTE_CHAR), caseSensitive, regExp, - GroupHierarchyType.getByNumber(context)); + GroupHierarchyType.getByNumber(context), jabRefPreferences); } /** @@ -140,7 +141,7 @@ public Optional add(List entriesToAdd) { if (!contains(entry)) { String oldContent = entry .getField(searchField); - String pre = Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR); + String pre = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR); String newContent = (oldContent == null ? "" : oldContent + pre) + searchExpression; @@ -279,7 +280,7 @@ private void removeMatches(BibEntry entry) { int i; int j; int k; - final String separator = Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR); + final String separator = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR); while ((i = haystack.indexOf(needle)) >= 0) { sbOrig.replace(i, i + needle.length(), ""); sbLower.replace(i, i + needle.length(), ""); @@ -308,7 +309,7 @@ private void removeMatches(BibEntry entry) { public AbstractGroup deepCopy() { try { return new KeywordGroup(getName(), searchField, searchExpression, - caseSensitive, regExp, getContext()); + caseSensitive, regExp, getContext(), jabRefPreferences); } catch (ParseException exception) { // this should never happen, because the constructor obviously succeeded in creating _this_ instance! LOGGER.error("Internal error in KeywordGroup.deepCopy(). " @@ -370,7 +371,7 @@ public static String getDescriptionForPreview(String field, String expr, boolean public String getShortDescription() { StringBuilder sb = new StringBuilder(); sb.append(""); - if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { + if (jabRefPreferences.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { sb.append("").append(StringUtil.quoteForHTML(getName())).append(""); } else { sb.append(StringUtil.quoteForHTML(getName())); diff --git a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java index 8c5d30034bc..4c8cbe141d4 100644 --- a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Optional; -import net.sf.jabref.Globals; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.search.SearchQuery; import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; @@ -42,14 +41,17 @@ public class SearchGroup extends AbstractGroup { private static final Log LOGGER = LogFactory.getLog(SearchGroup.class); + private final JabRefPreferences jabRefPreferences; /** * Creates a SearchGroup with the specified properties. */ - public SearchGroup(String name, String searchExpression, boolean caseSensitive, boolean regExp, GroupHierarchyType context) { + public SearchGroup(String name, String searchExpression, boolean caseSensitive, boolean regExp, + GroupHierarchyType context, JabRefPreferences jabRefPreferences) { super(name, context); this.query = new SearchQuery(searchExpression, caseSensitive, regExp); + this.jabRefPreferences = jabRefPreferences; } /** @@ -58,7 +60,7 @@ public SearchGroup(String name, String searchExpression, boolean caseSensitive, * @param s The String representation obtained from * SearchGroup.toString(), or null if incompatible */ - public static AbstractGroup fromString(String s) { + public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) { if (!s.startsWith(SearchGroup.ID)) { throw new IllegalArgumentException("SearchGroup cannot be created from \"" + s + "\"."); } @@ -74,7 +76,7 @@ public static AbstractGroup fromString(String s) { // fields; these are ignored now, all fields are always searched return new SearchGroup(StringUtil.unquote(name, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(expression, AbstractGroup.QUOTE_CHAR), caseSensitive, regExp, - GroupHierarchyType.getByNumber(context)); + GroupHierarchyType.getByNumber(context), jabRefPreferences); } @Override @@ -141,7 +143,7 @@ public boolean contains(BibEntry entry) { public AbstractGroup deepCopy() { try { return new SearchGroup(getName(), getSearchExpression(), isCaseSensitive(), - isRegExp(), getHierarchicalContext()); + isRegExp(), getHierarchicalContext(), jabRefPreferences); } catch (Throwable t) { // this should never happen, because the constructor obviously // succeeded in creating _this_ instance! @@ -173,7 +175,7 @@ public String getDescription() { public String getShortDescription() { StringBuilder sb = new StringBuilder(); sb.append(""); - if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { + if (jabRefPreferences.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { sb.append("").append(StringUtil.quoteForHTML(getName())).append(""); } else { sb.append(StringUtil.quoteForHTML(getName())); diff --git a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java index 1e303877258..8fcc80198ab 100644 --- a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.Globals; import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; @@ -94,9 +93,9 @@ public static List getBuiltInAbbreviations() { return readJournalListFromResource(JOURNALS_FILE_BUILTIN); } - public JournalAbbreviationRepository getRepository() { + public JournalAbbreviationRepository getRepository(JabRefPreferences jabRefPreferences) { if (journalAbbrev == null) { - update(Globals.prefs); + update(jabRefPreferences); } return journalAbbrev; } diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index 08c0d520baf..759e17d3784 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -440,7 +440,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { switch (name) { case "HTMLToLatexFormatter": // For backward compatibility case "HtmlToLatex": - return new HtmlToLatexFormatter(); + return new HtmlToLatexFormatter(prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); case "UnicodeToLatexFormatter": // For backward compatibility case "UnicodeToLatex": return new UnicodeToLatexFormatter(); @@ -513,7 +513,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "Iso690NamesAuthors": return new Iso690NamesAuthors(); case "JournalAbbreviator": - return new JournalAbbreviator(repositoryLoader); + return new JournalAbbreviator(repositoryLoader, prefs); case "LastPage": return new LastPage(); case "FormatChars": // For backward compatibility diff --git a/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java b/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java index 59a7a25ede5..d21ce1b51d3 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java @@ -29,6 +29,7 @@ import java.util.Objects; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.LayoutFormatter; @@ -50,14 +51,15 @@ public class JournalAbbreviator implements LayoutFormatter { private final JournalAbbreviationLoader repostioryLoader; + private final JabRefPreferences jabRefPreferences; - - public JournalAbbreviator(JournalAbbreviationLoader repostioryLoader) { + public JournalAbbreviator(JournalAbbreviationLoader repostioryLoader, JabRefPreferences jabRefPreferences) { this.repostioryLoader = Objects.requireNonNull(repostioryLoader); + this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); } @Override public String format(String fieldText) { - return repostioryLoader.getRepository().getIsoAbbreviation(fieldText).orElse(fieldText); + return repostioryLoader.getRepository(jabRefPreferences).getIsoAbbreviation(fieldText).orElse(fieldText); } } diff --git a/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java b/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java index a01198434e4..ccb09d167c5 100644 --- a/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java +++ b/src/main/java/net/sf/jabref/model/entry/InternalBibtexFields.java @@ -43,7 +43,6 @@ import java.util.Set; import net.sf.jabref.Globals; -import net.sf.jabref.preferences.JabRefPreferences; import net.sf.jabref.specialfields.SpecialFieldsUtils; public class InternalBibtexFields { @@ -78,9 +77,11 @@ public class InternalBibtexFields { public static final List BIBLATEX_PAGINATION_FIELDS = Arrays.asList("pagination", "bookpagination"); // singleton instance - private static final InternalBibtexFields RUNTIME = new InternalBibtexFields(); + private static final InternalBibtexFields RUNTIME = new InternalBibtexFields( + Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)); - private InternalBibtexFields() { + + private InternalBibtexFields(boolean serializeSpecialFields) { fieldSet = new HashMap<>(); BibtexSingleField dummy; @@ -131,42 +132,42 @@ private InternalBibtexFields() { // custom fields not displayed at editor, but as columns in the UI dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_RANKING, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); } add(dummy); dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_PRIORITY, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); } add(dummy); dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_RELEVANCE, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); } add(dummy); dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_QUALITY, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); } add(dummy); dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_READ, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); } add(dummy); dummy = new BibtexSingleField(SpecialFieldsUtils.FIELDNAME_PRINTED, false); - if (!Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS)) { + if (!serializeSpecialFields) { dummy.setPrivate(); dummy.setWriteable(false); dummy.setDisplayable(false); @@ -321,8 +322,7 @@ private InternalBibtexFields() { * sorting for all fields listed in the array. If an unknown field name is included, * add a field descriptor for the new field. */ - public static void setNumericFieldsFromPrefs(JabRefPreferences prefs) { - List numFields = prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS); + public static void setNumericFields(List numFields) { if (numFields.isEmpty()) { return; } diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 33868186da6..c6e62bdb915 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -365,7 +365,7 @@ public class JabRefPreferences { activeFormatterCleanups.add(new FieldFormatterCleanup("title", new ProtectTermsFormatter())); activeFormatterCleanups.add(new FieldFormatterCleanup("title", new UnitsToLatexFormatter())); activeFormatterCleanups.add(new FieldFormatterCleanup("title", new LatexCleanupFormatter())); - activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter())); + activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter(false))); // TODO: Get the actual value USE_CONVERT_TO_EQUATION FieldFormatterCleanups formatterCleanups = new FieldFormatterCleanups(true, activeFormatterCleanups); CLEANUP_DEFAULT_PRESET = new CleanupPreset(EnumSet.complementOf(deactivedJobs), formatterCleanups); } diff --git a/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java b/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java index 34a5ac3382a..b01ab845d1d 100644 --- a/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java +++ b/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java @@ -31,6 +31,7 @@ import java.util.StringJoiner; import java.util.stream.Collectors; +import net.sf.jabref.Globals; import net.sf.jabref.MetaData; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.groups.AbstractGroup; @@ -228,7 +229,7 @@ private void importGroupsTree(MetaData metaData, Map entries, break; case ExplicitGroup.ID: group = new ExplicitGroup(rsGroups.getString("label"), - GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context"))); + GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context")), Globals.prefs); break; case KeywordGroup.ID: LOGGER.debug("Keyw: " + rsGroups.getBoolean("case_sensitive")); @@ -236,14 +237,14 @@ private void importGroupsTree(MetaData metaData, Map entries, StringUtil.unquote(rsGroups.getString("search_field"), '\\'), StringUtil.unquote(rsGroups.getString("search_expression"), '\\'), rsGroups.getBoolean("case_sensitive"), rsGroups.getBoolean("reg_exp"), - GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context"))); + GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context")), Globals.prefs); break; case SearchGroup.ID: LOGGER.debug("Search: " + rsGroups.getBoolean("case_sensitive")); group = new SearchGroup(rsGroups.getString("label"), StringUtil.unquote(rsGroups.getString("search_expression"), '\\'), rsGroups.getBoolean("case_sensitive"), rsGroups.getBoolean("reg_exp"), - GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context"))); + GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context")), Globals.prefs); break; default: break; diff --git a/src/test/java/net/sf/jabref/importer/ConvertLegacyExplicitGroupsTest.java b/src/test/java/net/sf/jabref/importer/ConvertLegacyExplicitGroupsTest.java index f5cd24a89c8..500b77e4b07 100644 --- a/src/test/java/net/sf/jabref/importer/ConvertLegacyExplicitGroupsTest.java +++ b/src/test/java/net/sf/jabref/importer/ConvertLegacyExplicitGroupsTest.java @@ -34,7 +34,7 @@ public void setUp() throws Exception { entry = new BibEntry(); entry.setCiteKey("Entry1"); - group = new ExplicitGroup("TestGroup", GroupHierarchyType.INCLUDING); + group = new ExplicitGroup("TestGroup", GroupHierarchyType.INCLUDING, Globals.prefs); group.addLegacyEntryKey("Entry1"); } @@ -59,7 +59,7 @@ public void performActionClearsLegacyKeys() throws Exception { @Test public void performActionWritesGroupMembershipInEntryForComplexGroupTree() throws Exception { GroupTreeNode root = GroupTreeNode.fromGroup(new AllEntriesGroup()); - root.addSubgroup(new ExplicitGroup("TestGroup2", GroupHierarchyType.INCLUDING)); + root.addSubgroup(new ExplicitGroup("TestGroup2", GroupHierarchyType.INCLUDING, Globals.prefs)); root.addSubgroup(group); ParserResult parserResult = generateParserResult(entry, root); diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index 69d15d63255..b6beedd24fb 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -1430,10 +1430,12 @@ public void integrationTestGroupTree() throws IOException, ParseException { assertEquals(new AllEntriesGroup(), root.getGroup()); assertEquals(3, root.getNumberOfChildren()); assertEquals( - new KeywordGroup("Fréchet", "keywords", "FrechetSpace", false, true, GroupHierarchyType.INDEPENDENT), + new KeywordGroup("Fréchet", "keywords", "FrechetSpace", false, true, GroupHierarchyType.INDEPENDENT, + Globals.prefs), root.getChildren().get(0).getGroup()); assertEquals( - new KeywordGroup("Invariant theory", "keywords", "GIT", false, false, GroupHierarchyType.INDEPENDENT), + new KeywordGroup("Invariant theory", "keywords", "GIT", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs), root.getChildren().get(1).getGroup()); assertEquals(Arrays.asList("Key1", "Key2"), ((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys()); } diff --git a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java index 5c2d8eddd12..5c60108e0a4 100644 --- a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java +++ b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java @@ -1,5 +1,7 @@ package net.sf.jabref.logic.autocompleter; +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import org.junit.Assert; @@ -17,12 +19,13 @@ public class AutoCompleterFactoryTest { public void setUp() throws Exception { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); abbreviationLoader = mock(JournalAbbreviationLoader.class); - autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); + Globals.prefs = JabRefPreferences.getInstance(); + autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader, Globals.prefs); } @Test(expected = NullPointerException.class) public void initFactoryWithNullPreferenceThrowsException() { - new AutoCompleterFactory(null, abbreviationLoader); + new AutoCompleterFactory(null, abbreviationLoader, Globals.prefs); } @Test diff --git a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java index 91d81b055b5..c59ab7b2224 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java @@ -261,7 +261,8 @@ public void cleanupRenamePdfRenamesRelativeFile() throws IOException { @Test public void cleanupHtmlToLatexConvertsEpsilonToLatex() { CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(true, - Collections.singletonList(new FieldFormatterCleanup("title", new HtmlToLatexFormatter())))); + Collections.singletonList(new FieldFormatterCleanup("title", new HtmlToLatexFormatter( + Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)))))); BibEntry entry = new BibEntry(); entry.setField("title", "Ε"); diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index fb980313f4f..120e54af36f 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -52,7 +52,7 @@ public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); // Write to a string instead of to a file - databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); + databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, Globals.prefs); database = new BibDatabase(); metaData = new MetaData(); @@ -182,7 +182,7 @@ public void writeMetadataAndEncoding() throws Exception { @Test public void writeGroups() throws Exception { GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup()); - groupRoot.addSubgroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING)); + groupRoot.addSubgroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, Globals.prefs)); metaData.setGroups(groupRoot); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences()); @@ -201,7 +201,8 @@ public void writeGroupsAndEncoding() throws Exception { SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII); GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup()); - groupRoot.addChild(GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING))); + groupRoot.addChild( + GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, Globals.prefs))); metaData.setGroups(groupRoot); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences); diff --git a/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java b/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java index 442e9421f08..ed755a49690 100644 --- a/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java +++ b/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java @@ -105,7 +105,7 @@ public static Collection instancesToTest() { return Arrays.asList( new Object[]{new CapitalizeFormatter()}, new Object[]{new ClearFormatter()}, - new Object[]{new HtmlToLatexFormatter()}, + new Object[]{new HtmlToLatexFormatter(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION))}, new Object[]{new HtmlToUnicodeFormatter()}, new Object[]{new IdentityFormatter()}, new Object[]{new LatexCleanupFormatter()}, diff --git a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java index beede42e473..fef63b4c4da 100644 --- a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java +++ b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java @@ -23,7 +23,7 @@ public static void setUpBeforeClass() throws Exception { @Before public void setUp() { - formatter = new HtmlToLatexFormatter(); + formatter = new HtmlToLatexFormatter(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); } @Test diff --git a/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java index 35f33e51da4..0d85b07ea18 100644 --- a/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/ExplicitGroupTest.java @@ -21,13 +21,13 @@ public void setUp() { @Test public void testToStringSimple() throws ParseException { - ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT); + ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); assertEquals("ExplicitGroup:myExplicitGroup;0;", group.toString()); } @Test public void toStringDoesNotWriteAssignedEntries() throws ParseException { - ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INCLUDING); + ExplicitGroup group = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INCLUDING, Globals.prefs); group.add(makeBibtexEntry()); assertEquals("ExplicitGroup:myExplicitGroup;2;", group.toString()); } diff --git a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java index 3b48d686940..87a8f81b160 100644 --- a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java @@ -21,7 +21,7 @@ public class GroupTreeNodeTest { - private List entries = new ArrayList<>(); + private final List entries = new ArrayList<>(); private BibEntry entry; @Before @@ -44,9 +44,11 @@ public void setUp() throws Exception { * B ExplicitNode, Refining (<-- this) */ private GroupTreeNode getNodeInSimpleTree(GroupTreeNode root) throws ParseException { - root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING)); - GroupTreeNode parent = root.addSubgroup(new ExplicitGroup("ExplicitParent", GroupHierarchyType.INDEPENDENT)); - GroupTreeNode node = parent.addSubgroup(new ExplicitGroup("ExplicitNode", GroupHierarchyType.REFINING)); + root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, Globals.prefs)); + GroupTreeNode parent = root + .addSubgroup(new ExplicitGroup("ExplicitParent", GroupHierarchyType.INDEPENDENT, Globals.prefs)); + GroupTreeNode node = parent + .addSubgroup(new ExplicitGroup("ExplicitNode", GroupHierarchyType.REFINING, Globals.prefs)); return node; } @@ -73,8 +75,9 @@ private GroupTreeNode getNodeInSimpleTree() throws ParseException { */ private GroupTreeNode getNodeInComplexTree(GroupTreeNode root) throws ParseException { root.addSubgroup(getSearchGroup("SearchA")); - root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING)); - GroupTreeNode grandParent = root.addSubgroup(new ExplicitGroup("ExplicitGrandParent", GroupHierarchyType.INDEPENDENT)); + root.addSubgroup(new ExplicitGroup("ExplicitA", GroupHierarchyType.INCLUDING, Globals.prefs)); + GroupTreeNode grandParent = root + .addSubgroup(new ExplicitGroup("ExplicitGrandParent", GroupHierarchyType.INDEPENDENT, Globals.prefs)); root.addSubgroup(getKeywordGroup("KeywordA")); grandParent.addSubgroup(getExplict("ExplicitB")); @@ -92,15 +95,16 @@ private GroupTreeNode getNodeInComplexTree(GroupTreeNode root) throws ParseExcep } private AbstractGroup getKeywordGroup(String name) throws ParseException { - return new KeywordGroup(name, "searchField", "searchExpression", true, false, GroupHierarchyType.INDEPENDENT); + return new KeywordGroup(name, "searchField", "searchExpression", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); } private AbstractGroup getSearchGroup(String name) { - return new SearchGroup(name, "searchExpression", true, false, GroupHierarchyType.INCLUDING); + return new SearchGroup(name, "searchExpression", true, false, GroupHierarchyType.INCLUDING, Globals.prefs); } private AbstractGroup getExplict(String name) throws ParseException { - return new ExplicitGroup(name, GroupHierarchyType.REFINING); + return new ExplicitGroup(name, GroupHierarchyType.REFINING, Globals.prefs); } /* @@ -171,14 +175,16 @@ public void getTreeAsStringInComplexTree() throws Exception { @Test public void getSearchRuleForIndependentGroupReturnsGroupAsMatcher() throws ParseException { - GroupTreeNode node = GroupTreeNode.fromGroup(new ExplicitGroup("node", GroupHierarchyType.INDEPENDENT)); + GroupTreeNode node = GroupTreeNode + .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INDEPENDENT, Globals.prefs)); assertEquals(node.getGroup(), node.getSearchRule()); } @Test public void getSearchRuleForRefiningGroupReturnsParentAndGroupAsMatcher() throws ParseException { - GroupTreeNode parent = GroupTreeNode.fromGroup(new ExplicitGroup("parent", GroupHierarchyType.INDEPENDENT)); - GroupTreeNode node = parent.addSubgroup(new ExplicitGroup("node", GroupHierarchyType.REFINING)); + GroupTreeNode parent = GroupTreeNode + .fromGroup(new ExplicitGroup("parent", GroupHierarchyType.INDEPENDENT, Globals.prefs)); + GroupTreeNode node = parent.addSubgroup(new ExplicitGroup("node", GroupHierarchyType.REFINING, Globals.prefs)); AndMatcher matcher = new AndMatcher(); matcher.addRule(node.getGroup()); @@ -188,8 +194,10 @@ public void getSearchRuleForRefiningGroupReturnsParentAndGroupAsMatcher() throws @Test public void getSearchRuleForIncludingGroupReturnsGroupOrSubgroupAsMatcher() throws ParseException { - GroupTreeNode node = GroupTreeNode.fromGroup(new ExplicitGroup("node", GroupHierarchyType.INCLUDING)); - GroupTreeNode child = node.addSubgroup(new ExplicitGroup("child", GroupHierarchyType.INDEPENDENT)); + GroupTreeNode node = GroupTreeNode + .fromGroup(new ExplicitGroup("node", GroupHierarchyType.INCLUDING, Globals.prefs)); + GroupTreeNode child = node + .addSubgroup(new ExplicitGroup("child", GroupHierarchyType.INDEPENDENT, Globals.prefs)); OrMatcher matcher = new OrMatcher(); matcher.addRule(node.getGroup()); @@ -206,7 +214,8 @@ public void numberOfHitsReturnsZeroForEmptyList() throws Exception { public void numberOfHitsMatchesOneEntry() throws Exception { GroupTreeNode parent = getNodeInSimpleTree(); GroupTreeNode node = parent.addSubgroup( - new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT)); + new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs)); assertEquals(1, node.numberOfHits(entries)); } @@ -214,7 +223,8 @@ public void numberOfHitsMatchesOneEntry() throws Exception { public void numberOfHitsMatchesMultipleEntries() throws Exception { GroupTreeNode parent = getNodeInSimpleTree(); GroupTreeNode node = parent.addSubgroup( - new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT)); + new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs)); assertEquals(2, node.numberOfHits(entries)); } @@ -222,9 +232,10 @@ public void numberOfHitsMatchesMultipleEntries() throws Exception { public void numberOfHitsWorksForRefiningGroups() throws Exception { GroupTreeNode grandParent = getNodeInSimpleTree(); GroupTreeNode parent = grandParent.addSubgroup( - new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT)); + new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs)); GroupTreeNode node = parent.addSubgroup( - new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.REFINING)); + new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.REFINING, Globals.prefs)); assertEquals(1, node.numberOfHits(entries)); } @@ -232,16 +243,18 @@ public void numberOfHitsWorksForRefiningGroups() throws Exception { public void numberOfHitsWorksForHierarchyOfIndependentGroups() throws Exception { GroupTreeNode grandParent = getNodeInSimpleTree(); GroupTreeNode parent = grandParent.addSubgroup( - new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT)); + new KeywordGroup("node", "author", "author2", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs)); GroupTreeNode node = parent.addSubgroup( - new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT)); + new KeywordGroup("node", "author", "author1", true, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs)); assertEquals(2, node.numberOfHits(entries)); } @Test public void setGroupChangesUnderlyingGroup() throws Exception { GroupTreeNode node = getNodeInSimpleTree(); - AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); node.setGroup(newGroup, true, entries); @@ -250,10 +263,10 @@ public void setGroupChangesUnderlyingGroup() throws Exception { @Test public void setGroupAddsPreviousAssignmentsExplicitToExplicit() throws Exception { - AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); node.setGroup(newGroup, true, entries); @@ -262,10 +275,10 @@ public void setGroupAddsPreviousAssignmentsExplicitToExplicit() throws Exception @Test public void setGroupWithFalseDoesNotAddsPreviousAssignments() throws Exception { - AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); node.setGroup(newGroup, false, entries); @@ -274,10 +287,10 @@ public void setGroupWithFalseDoesNotAddsPreviousAssignments() throws Exception { @Test public void setGroupAddsOnlyPreviousAssignments() throws Exception { - AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); assertFalse(oldGroup.isMatch(entry)); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); node.setGroup(newGroup, true, entries); @@ -286,10 +299,11 @@ public void setGroupAddsOnlyPreviousAssignments() throws Exception { @Test public void setGroupExplicitToSearchDoesNotKeepPreviousAssignments() throws Exception { - AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new SearchGroup("NewGroup", "test", false, false, GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new SearchGroup("NewGroup", "test", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); node.setGroup(newGroup, true, entries); @@ -298,10 +312,10 @@ public void setGroupExplicitToSearchDoesNotKeepPreviousAssignments() throws Exce @Test public void setGroupExplicitToExplicitIsRenameAndSoRemovesPreviousAssignment() throws Exception { - AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT); + AbstractGroup newGroup = new ExplicitGroup("NewGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); node.setGroup(newGroup, true, entries); diff --git a/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java index 38166bfa7c0..8037c66cc4b 100644 --- a/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/KeywordGroupTest.java @@ -1,5 +1,6 @@ package net.sf.jabref.logic.groups; +import net.sf.jabref.Globals; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.model.entry.BibEntry; @@ -13,20 +14,21 @@ public class KeywordGroupTest { @Test public void testToString() throws ParseException { KeywordGroup group = new KeywordGroup("myExplicitGroup", "author","asdf", true, true, - GroupHierarchyType.INDEPENDENT); + GroupHierarchyType.INDEPENDENT, Globals.prefs); assertEquals("KeywordGroup:myExplicitGroup;0;author;asdf;1;1;", group.toString()); } @Test public void testToString2() throws ParseException { KeywordGroup group = new KeywordGroup("myExplicitGroup", "author","asdf", false, true, - GroupHierarchyType.REFINING); + GroupHierarchyType.REFINING, Globals.prefs); assertEquals("KeywordGroup:myExplicitGroup;1;author;asdf;0;1;", group.toString()); } @Test public void containsSimpleWord() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "test"); assertTrue(group.isMatch(entry)); @@ -34,7 +36,8 @@ public void containsSimpleWord() throws Exception { @Test public void containsSimpleWordInSentence() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing test word"); assertTrue(group.isMatch(entry)); @@ -42,7 +45,8 @@ public void containsSimpleWordInSentence() throws Exception { @Test public void containsSimpleWordCommaSeparated() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "Some,list,containing,test,word"); assertTrue(group.isMatch(entry)); @@ -50,7 +54,8 @@ public void containsSimpleWordCommaSeparated() throws Exception { @Test public void containsSimpleWordSemicolonSeparated() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "test", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "Some;list;containing;test;word"); assertTrue(group.isMatch(entry)); @@ -58,7 +63,8 @@ public void containsSimpleWordSemicolonSeparated() throws Exception { @Test public void containsComplexWord() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "\\H2O"); assertTrue(group.isMatch(entry)); @@ -66,7 +72,8 @@ public void containsComplexWord() throws Exception { @Test public void containsComplexWordInSentence() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "\\H2O", false, false, GroupHierarchyType.INDEPENDENT, + Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing \\H2O word"); assertTrue(group.isMatch(entry)); @@ -74,7 +81,8 @@ public void containsComplexWordInSentence() throws Exception { @Test public void containsWordWithWhitespaceInSentence() throws Exception { - KeywordGroup group = new KeywordGroup("name", "keywords", "test word", false, false, GroupHierarchyType.INDEPENDENT); + KeywordGroup group = new KeywordGroup("name", "keywords", "test word", false, false, + GroupHierarchyType.INDEPENDENT, Globals.prefs); BibEntry entry = new BibEntry().withField("keywords", "Some sentence containing test word"); assertTrue(group.isMatch(entry)); diff --git a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java index c9648ac2bc2..5203b51778b 100644 --- a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java @@ -21,7 +21,7 @@ public static void setUp() { @Test public void testContains() { SearchGroup group = new SearchGroup("myExplicitGroup", "review", - true, true, GroupHierarchyType.INDEPENDENT); + true, true, GroupHierarchyType.INDEPENDENT, Globals.prefs); assertEquals("SearchGroup:myExplicitGroup;0;review;1;1;", group.toString()); BibEntry entry = new BibEntry(); @@ -34,14 +34,14 @@ public void testContains() { @Test public void testToStringSimple() { SearchGroup group = new SearchGroup("myExplicitGroup", "author=harrer", - true, true, GroupHierarchyType.INDEPENDENT); + true, true, GroupHierarchyType.INDEPENDENT, Globals.prefs); assertEquals("SearchGroup:myExplicitGroup;0;author=harrer;1;1;", group.toString()); } @Test public void testToStringComplex() { SearchGroup group = new SearchGroup("myExplicitGroup", "author=\"harrer\"", true, false, - GroupHierarchyType.INCLUDING); + GroupHierarchyType.INCLUDING, Globals.prefs); assertEquals("SearchGroup:myExplicitGroup;2;author=\"harrer\";1;0;", group.toString()); } diff --git a/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java b/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java index b65d9187236..c356b81ccf8 100644 --- a/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java +++ b/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java @@ -29,7 +29,7 @@ public void getNextAbbreviationAbbreviatesIEEEJournalTitle() { when(prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)).thenReturn(true); assertEquals("#IEEE_J_PROC#", - abbreviations.getRepository().getNextAbbreviation("Proceedings of the IEEE").get()); + abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proceedings of the IEEE").get()); } @Test @@ -37,24 +37,24 @@ public void getNextAbbreviationExpandsIEEEAbbreviation() { when(prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)).thenReturn(true); assertEquals("Proceedings of the IEEE", - abbreviations.getRepository().getNextAbbreviation("#IEEE_J_PROC#").get()); + abbreviations.getRepository(Globals.prefs).getNextAbbreviation("#IEEE_J_PROC#").get()); } @Test public void getNextAbbreviationAbbreviatesJournalTitle() { assertEquals("Proc. IEEE", - abbreviations.getRepository().getNextAbbreviation("Proceedings of the IEEE").get()); + abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proceedings of the IEEE").get()); } @Test public void getNextAbbreviationRemovesPoint() { - assertEquals("Proc IEEE", abbreviations.getRepository().getNextAbbreviation("Proc. IEEE").get()); + assertEquals("Proc IEEE", abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proc. IEEE").get()); } @Test public void getNextAbbreviationExpandsAbbreviation() { assertEquals("Proceedings of the IEEE", - abbreviations.getRepository().getNextAbbreviation("Proc IEEE").get()); + abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proc IEEE").get()); } } diff --git a/src/test/java/net/sf/jabref/sql/DatabaseImportExportTests.java b/src/test/java/net/sf/jabref/sql/DatabaseImportExportTests.java index cd451c2c52b..b014caf2c42 100644 --- a/src/test/java/net/sf/jabref/sql/DatabaseImportExportTests.java +++ b/src/test/java/net/sf/jabref/sql/DatabaseImportExportTests.java @@ -179,7 +179,8 @@ private BibDatabaseContext createContextWithSingleEntrySingleGroup() throws Pars BibDatabaseContext databaseContext = createContextWithSingleEntry(); GroupTreeNode root = GroupTreeNode.fromGroup(new AllEntriesGroup()); - KeywordGroup group = new KeywordGroup("test", "asdf", "fdas", false, true, GroupHierarchyType.INCLUDING); + KeywordGroup group = new KeywordGroup("test", "asdf", "fdas", false, true, GroupHierarchyType.INCLUDING, + Globals.prefs); root.addSubgroup(group); databaseContext.getMetaData().setGroups(root); return databaseContext; From 8fdd8b80dfc70103bba849da218edadeb9533ce0 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 17 Jul 2016 15:24:15 +0200 Subject: [PATCH 08/17] Removed unrequired dependency and fixed issue --- src/main/java/net/sf/jabref/MetaData.java | 2 +- .../java/net/sf/jabref/logic/groups/AbstractGroup.java | 9 +++++---- .../java/net/sf/jabref/logic/groups/GroupTreeNode.java | 6 ++++-- .../java/net/sf/jabref/logic/groups/GroupsParser.java | 6 ++++-- .../java/net/sf/jabref/logic/openoffice/OOBibStyle.java | 3 +-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index a9fd1cdf47f..1a6369da8e5 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -178,7 +178,7 @@ public void putData(String key, List orderedData) { */ private void putGroups(List orderedData) throws ParseException { try { - groupsRoot = GroupTreeNode.parse(orderedData); + groupsRoot = GroupTreeNode.parse(orderedData, Globals.prefs); } catch (ParseException e) { throw new ParseException(Localization.lang( "Group tree could not be parsed. If you save the BibTeX database, all groups will be lost."), e); diff --git a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java index 10f1ea3c35d..fa67145e0e2 100644 --- a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Optional; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.search.SearchMatcher; import net.sf.jabref.model.database.BibDatabase; @@ -62,18 +63,18 @@ public abstract class AbstractGroup implements SearchMatcher { * @throws ParseException If an error occurred and a group could not be created, * e.g. due to a malformed regular expression. */ - public static AbstractGroup fromString(String s) throws ParseException { + public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) throws ParseException { if (s.startsWith(KeywordGroup.ID)) { - return KeywordGroup.fromString(s); + return KeywordGroup.fromString(s, jabRefPreferences); } if (s.startsWith(AllEntriesGroup.ID)) { return AllEntriesGroup.fromString(s); } if (s.startsWith(SearchGroup.ID)) { - return SearchGroup.fromString(s); + return SearchGroup.fromString(s, jabRefPreferences); } if (s.startsWith(ExplicitGroup.ID)) { - return ExplicitGroup.fromString(s); + return ExplicitGroup.fromString(s, jabRefPreferences); } return null; // unknown group } diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java index c0cbba8d536..7a5e60c3ea5 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java @@ -21,6 +21,7 @@ import java.util.Optional; import java.util.stream.Collectors; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.search.SearchMatcher; import net.sf.jabref.logic.search.matchers.MatcherSet; @@ -248,8 +249,9 @@ public GroupTreeNode copyNode() { return GroupTreeNode.fromGroup(group); } - public static GroupTreeNode parse(List orderedData) throws ParseException { - return GroupsParser.importGroups(orderedData); + public static GroupTreeNode parse(List orderedData, JabRefPreferences jabRefPreferences) + throws ParseException { + return GroupsParser.importGroups(orderedData, jabRefPreferences); } /** diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java index 82aae0af35a..c54c347f5ac 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java @@ -19,6 +19,7 @@ import java.util.List; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.l10n.Localization; @@ -27,7 +28,8 @@ */ class GroupsParser { - public static GroupTreeNode importGroups(List orderedData) throws ParseException { + public static GroupTreeNode importGroups(List orderedData, JabRefPreferences jabRefPreferences) + throws ParseException { GroupTreeNode cursor = null; GroupTreeNode root = null; for (String string : orderedData) { @@ -42,7 +44,7 @@ public static GroupTreeNode importGroups(List orderedData) throws ParseE throw new ParseException(Localization.lang("Expected \"%0\" to contain whitespace", string)); } int level = Integer.parseInt(string.substring(0, spaceIndex)); - AbstractGroup group = AbstractGroup.fromString(string.substring(spaceIndex + 1)); + AbstractGroup group = AbstractGroup.fromString(string.substring(spaceIndex + 1), jabRefPreferences); GroupTreeNode newNode = GroupTreeNode.fromGroup(group); if (cursor == null) { // create new root diff --git a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java index 09869e06125..0a6ca84726e 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java @@ -36,7 +36,6 @@ import java.util.TreeSet; import java.util.regex.Pattern; -import net.sf.jabref.JabRefMain; import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; @@ -172,7 +171,7 @@ public OOBibStyle(String resourcePath, JabRefPreferences prefs, JournalAbbreviat this.prefs = Objects.requireNonNull(prefs); this.encoding = StandardCharsets.UTF_8; setDefaultProperties(); - initialize(JabRefMain.class.getResource(resourcePath).openStream()); + initialize(OOBibStyle.class.getResource(resourcePath).openStream()); fromResource = true; path = resourcePath; } From 2523592f3297a8acaaca29232f8ecbfcfb4538be Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 12:44:09 +0200 Subject: [PATCH 09/17] Dropped support for selecting sub/super to equations --- CHANGELOG.md | 1 + .../net/sf/jabref/benchmarks/Benchmarks.java | 3 +- .../sf/jabref/gui/preftabs/AdvancedTab.java | 7 ---- .../importer/fetcher/ACMPortalFetcher.java | 3 +- .../importer/fetcher/IEEEXploreFetcher.java | 33 +++++-------------- .../sf/jabref/logic/formatter/Formatters.java | 2 +- .../bibtexfields/HtmlToLatexFormatter.java | 18 ++-------- .../sf/jabref/logic/layout/LayoutEntry.java | 2 +- .../jabref/preferences/JabRefPreferences.java | 3 +- src/main/resources/l10n/JabRef_da.properties | 1 - src/main/resources/l10n/JabRef_de.properties | 1 - src/main/resources/l10n/JabRef_en.properties | 1 - src/main/resources/l10n/JabRef_es.properties | 1 - src/main/resources/l10n/JabRef_fa.properties | 1 - src/main/resources/l10n/JabRef_fr.properties | 1 - src/main/resources/l10n/JabRef_in.properties | 1 - src/main/resources/l10n/JabRef_it.properties | 1 - src/main/resources/l10n/JabRef_ja.properties | 1 - src/main/resources/l10n/JabRef_nl.properties | 1 - src/main/resources/l10n/JabRef_no.properties | 1 - .../resources/l10n/JabRef_pt_BR.properties | 1 - src/main/resources/l10n/JabRef_ru.properties | 1 - src/main/resources/l10n/JabRef_sv.properties | 1 - src/main/resources/l10n/JabRef_tr.properties | 1 - src/main/resources/l10n/JabRef_vi.properties | 1 - src/main/resources/l10n/JabRef_zh.properties | 1 - .../logic/cleanup/CleanupWorkerTest.java | 3 +- .../jabref/logic/formatter/FormatterTest.java | 2 +- .../HtmlToLatexFormatterTest.java | 2 +- 29 files changed, 20 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a03a5555625..1e81b485670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed [#1592](https://github.com/JabRef/jabref/issues/1592): LibreOffice: wrong numbers in citation labels ### Removed +- It is not longer possible to choose to convert HTML sub- and superscripts to equations diff --git a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java index e022055a267..f21f5419c21 100644 --- a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java @@ -117,8 +117,7 @@ public String latexToHTMLConversion() { @Benchmark public String htmlToLatexConversion() { - HtmlToLatexFormatter f = new HtmlToLatexFormatter( - Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); + HtmlToLatexFormatter f = new HtmlToLatexFormatter(); return f.format(htmlConversionString); } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java b/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java index c9b146bfc03..62bf6b98f31 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java @@ -44,7 +44,6 @@ class AdvancedTab extends JPanel implements PrefsTab { private final JCheckBox useIEEEAbrv; private final JTextField remoteServerPort; - private final JCheckBox useConvertToEquation; private final JCheckBox useCaseKeeperOnSearch; private final JCheckBox useUnitFormatterOnSearch; private final RemotePreferences remotePreferences; @@ -57,7 +56,6 @@ public AdvancedTab(JabRefPreferences prefs) { useRemoteServer = new JCheckBox(Localization.lang("Listen for remote operation on port") + ':'); useIEEEAbrv = new JCheckBox(Localization.lang("Use IEEE LaTeX abbreviations")); remoteServerPort = new JTextField(); - useConvertToEquation = new JCheckBox(Localization.lang("Prefer converting subscripts and superscripts to equations rather than text")); useCaseKeeperOnSearch = new JCheckBox(Localization.lang("Add {} to specified title words on search to keep the correct case")); useUnitFormatterOnSearch = new JCheckBox(Localization.lang("Format units by adding non-breaking separators and keeping the correct case on search")); @@ -95,9 +93,6 @@ public AdvancedTab(JabRefPreferences prefs) { builder.nextLine(); builder.appendSeparator(Localization.lang("Import conversions")); builder.nextLine(); - builder.append(new JPanel()); - builder.append(useConvertToEquation); - builder.nextLine(); builder.append(pan); builder.append(useCaseKeeperOnSearch); builder.nextLine(); @@ -116,7 +111,6 @@ public void setValues() { useRemoteServer.setSelected(remotePreferences.useRemoteServer()); remoteServerPort.setText(String.valueOf(remotePreferences.getPort())); useIEEEAbrv.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)); - useConvertToEquation.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); useCaseKeeperOnSearch.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)); useUnitFormatterOnSearch.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)); } @@ -129,7 +123,6 @@ public void storeSettings() { } storeRemoteSettings(); - preferences.putBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION, useConvertToEquation.isSelected()); preferences.putBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH, useCaseKeeperOnSearch.isSelected()); preferences.putBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH, useUnitFormatterOnSearch.isSelected()); } diff --git a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java index 2048a1271ba..4d019069515 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java @@ -62,8 +62,7 @@ public class ACMPortalFetcher implements PreviewEntryFetcher { private static final Log LOGGER = LogFactory.getLog(ACMPortalFetcher.class); - private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter( - Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); + private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(); private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter(); private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter(); private String terms; diff --git a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java index d6d2372be57..471ce763a1b 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java @@ -81,8 +81,7 @@ public class IEEEXploreFetcher implements EntryFetcher { private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter(); private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter(); - private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter( - Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); + private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(); private final JCheckBox absCheckBox = new JCheckBox(Localization.lang("Include abstracts"), false); private boolean shouldContinue; @@ -281,17 +280,10 @@ private BibEntry cleanup(BibEntry entry) { // Replace general expressions title = title.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$"); // Deal with subscripts and superscripts - if (Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)) { - title = SUPER_DETECTION_1.matcher(title).replaceAll(SUPER_EQ_RESULT); - title = SUB_DETECTION_1.matcher(title).replaceAll(SUB_EQ_RESULT); - title = SUPER_DETECTION_2.matcher(title).replaceAll(SUPER_EQ_RESULT); - title = SUB_DETECTION_2.matcher(title).replaceAll(SUB_EQ_RESULT); - } else { - title = SUPER_DETECTION_1.matcher(title).replaceAll(SUPER_TEXT_RESULT); - title = SUB_DETECTION_1.matcher(title).replaceAll(SUB_TEXT_RESULT); - title = SUPER_DETECTION_2.matcher(title).replaceAll(SUPER_TEXT_RESULT); - title = SUB_DETECTION_2.matcher(title).replaceAll(SUB_TEXT_RESULT); - } + title = SUPER_DETECTION_1.matcher(title).replaceAll(SUPER_TEXT_RESULT); + title = SUB_DETECTION_1.matcher(title).replaceAll(SUB_TEXT_RESULT); + title = SUPER_DETECTION_2.matcher(title).replaceAll(SUPER_TEXT_RESULT); + title = SUB_DETECTION_2.matcher(title).replaceAll(SUB_TEXT_RESULT); // Replace \infin with \infty title = title.replaceAll("\\\\infin", "\\\\infty"); @@ -501,17 +493,10 @@ private BibEntry cleanup(BibEntry entry) { // Replace general expressions abstr = abstr.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$"); // Deal with subscripts and superscripts - if (Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)) { - abstr = SUPER_DETECTION_1.matcher(abstr).replaceAll(SUPER_EQ_RESULT); - abstr = SUB_DETECTION_1.matcher(abstr).replaceAll(SUB_EQ_RESULT); - abstr = SUPER_DETECTION_2.matcher(abstr).replaceAll(SUPER_EQ_RESULT); - abstr = SUB_DETECTION_2.matcher(abstr).replaceAll(SUB_EQ_RESULT); - } else { - abstr = SUPER_DETECTION_1.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); - abstr = SUB_DETECTION_1.matcher(abstr).replaceAll(SUB_TEXT_RESULT); - abstr = SUPER_DETECTION_2.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); - abstr = SUB_DETECTION_2.matcher(abstr).replaceAll(SUB_TEXT_RESULT); - } + abstr = SUPER_DETECTION_1.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); + abstr = SUB_DETECTION_1.matcher(abstr).replaceAll(SUB_TEXT_RESULT); + abstr = SUPER_DETECTION_2.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); + abstr = SUB_DETECTION_2.matcher(abstr).replaceAll(SUB_TEXT_RESULT); // Replace \infin with \infty abstr = abstr.replace("\\infin", "\\infty"); // Write back diff --git a/src/main/java/net/sf/jabref/logic/formatter/Formatters.java b/src/main/java/net/sf/jabref/logic/formatter/Formatters.java index 68c93a25d56..c4d70477409 100644 --- a/src/main/java/net/sf/jabref/logic/formatter/Formatters.java +++ b/src/main/java/net/sf/jabref/logic/formatter/Formatters.java @@ -45,7 +45,7 @@ public class Formatters { public static final List CONVERTERS = Arrays.asList( - new HtmlToLatexFormatter(false), // TODO: Get the correct value from USE_CONVERT_TO_EQUATION + new HtmlToLatexFormatter(), new HtmlToUnicodeFormatter(), new LatexToUnicodeFormatter(), new UnicodeToLatexFormatter() diff --git a/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java b/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java index ebf06cc28c1..db5b8ac4365 100644 --- a/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java +++ b/src/main/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java @@ -39,13 +39,6 @@ public class HtmlToLatexFormatter implements LayoutFormatter, Formatter { private static final Pattern ESCAPED_PATTERN3 = Pattern.compile("&#([x]*)([0]*)(\\p{XDigit}+);"); private static final Pattern ESCAPED_PATTERN4 = Pattern.compile("&(\\w+);"); - private final boolean convertToEquation; - - - public HtmlToLatexFormatter(boolean convertToEquation) { - this.convertToEquation = convertToEquation; - } - @Override public String format(String text) { String result = Objects.requireNonNull(text); @@ -56,15 +49,8 @@ public String format(String text) { StringBuilder sb = new StringBuilder(); // Deal with the form kand k - // If the result is in text or equation form can be controlled - // From the "Advanced settings" tab - if (convertToEquation) { - result = result.replaceAll("<[ ]?sup>([^<]+)", "\\$\\^\\{$1\\}\\$"); - result = result.replaceAll("<[ ]?sub>([^<]+)", "\\$_\\{$1\\}\\$"); - } else { - result = result.replaceAll("<[ ]?sup>([^<]+)", "\\\\textsuperscript\\{$1\\}"); - result = result.replaceAll("<[ ]?sub>([^<]+)", "\\\\textsubscript\\{$1\\}"); - } + result = result.replaceAll("<[ ]?sup>([^<]+)", "\\\\textsuperscript\\{$1\\}"); + result = result.replaceAll("<[ ]?sub>([^<]+)", "\\\\textsubscript\\{$1\\}"); // TODO: maybe rewrite this based on regular expressions instead // Note that (at least) the IEEE Xplore fetcher must be fixed as it relies on the current way to diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index 759e17d3784..cabaa3d2131 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -440,7 +440,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { switch (name) { case "HTMLToLatexFormatter": // For backward compatibility case "HtmlToLatex": - return new HtmlToLatexFormatter(prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); + return new HtmlToLatexFormatter(); case "UnicodeToLatexFormatter": // For backward compatibility case "UnicodeToLatex": return new UnicodeToLatexFormatter(); diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index c6e62bdb915..033f1f68954 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -365,7 +365,7 @@ public class JabRefPreferences { activeFormatterCleanups.add(new FieldFormatterCleanup("title", new ProtectTermsFormatter())); activeFormatterCleanups.add(new FieldFormatterCleanup("title", new UnitsToLatexFormatter())); activeFormatterCleanups.add(new FieldFormatterCleanup("title", new LatexCleanupFormatter())); - activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter(false))); // TODO: Get the actual value USE_CONVERT_TO_EQUATION + activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter())); FieldFormatterCleanups formatterCleanups = new FieldFormatterCleanups(true, activeFormatterCleanups); CLEANUP_DEFAULT_PRESET = new CleanupPreset(EnumSet.complementOf(deactivedJobs), formatterCleanups); } @@ -862,7 +862,6 @@ private JabRefPreferences() { defaults.put(REG_EXP_SEARCH_EXPRESSION_KEY, defaultExpression); defaults.put(AUTOLINK_USE_REG_EXP_SEARCH_KEY, Boolean.FALSE); defaults.put(USE_IEEE_ABRV, Boolean.FALSE); - defaults.put(USE_CONVERT_TO_EQUATION, Boolean.FALSE); defaults.put(USE_CASE_KEEPER_ON_SEARCH, Boolean.TRUE); defaults.put(USE_UNIT_FORMATTER_ON_SEARCH, Boolean.TRUE); defaults.put(MAX_BACK_HISTORY_SIZE, 10); diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 1f09d720a84..67f68b2c23b 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1226,7 +1226,6 @@ Searching...= You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection= Unknown_DOI\:_'%0'.= -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions= Please_enter_a_search_string= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 853948a7bc8..dee230addbb 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -1934,7 +1934,6 @@ Searching...=Suche_läuft... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Sie_haben_mehr_als_%0_Einträge_zum_Download_ausgewählt._Einige_Webseiten_könnten_zu_viele_Downloads_blockieren._Möchten_Sie_fortfahren? Confirm_selection=Auswahl_bestätigen Unknown_DOI\:_'%0'.=Unbekannte_DOI\:_'0%'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Hoch-_und_tiefgestellte_Zeichen_in_eine_Gleichung_konvertieren_und_nicht_als_Text_darstellen Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Nach_der_Suche_{}_zu_festgesetzten_Titelworten_hinzufügen,_um_Groß-/Kleinschreibung_beizubehalten Import_conversions=Konvertierungen_importieren Please_enter_a_search_string=Bitte_geben_Sie_eine_Suchphrase_ein diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2e2d6dff0b8..1d87886261e 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1832,7 +1832,6 @@ Searching...=Searching... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue? Confirm_selection=Confirm_selection Unknown_DOI\:_'%0'.=Unknown_DOI\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case Import_conversions=Import_conversions Please_enter_a_search_string=Please_enter_a_search_string diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index a7c6884fe26..d3ba5a7bec0 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1134,7 +1134,6 @@ Searching...=Buscando... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Ha_seleccionado_más_de_%0_entradas_para_descargar._Algunos_sitios_web_podrían_bloquearle_si_hace_demasiadas_descargas._¿Desea_continuar? Confirm_selection=Confirmar_selección Unknown_DOI\:_'%0'.=DOI_desconocido\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Preferir_convertir_subíndices_y_superíndices_a_ecuaciónantes_que_a_texto Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Añadir_{}_para_especificar_las_palabras_del_título_para_mantener_mayúsculas/minúsculas_correctamente Import_conversions=Importar_conversiones Please_enter_a_search_string=Introduzca_una_cadena_de_búsqueda,_por_favor diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index 2e92ec35fda..2d051c0c722 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -1888,7 +1888,6 @@ Searching...= You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection= Unknown_DOI\:_'%0'.= -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions= Please_enter_a_search_string= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 576a040f542..649d1d731ef 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1166,7 +1166,6 @@ Searching...=Recherche... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Vous_avez_sélectionné_plus_de_%0_entrées_à_télécharger._Certains_sites_web_pourraient_vous_bloquer_si_vous_effectuez_de_trop_nombreux_et_rapides_téléchargements._Voulez-vous_continuer? Confirm_selection=Confirmez_la_sélection Unknown_DOI\:_'%0'.=DOI_inconnu_\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Conversion_des_indices_et_exposants_en_équations_plutôt_qu'en_texte Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Ajouter_{}_aux_mots_du_titre_spécifiés_lors_d'une_recherche_pour_préserver_la_casse_correcte Import_conversions=Importer_les_conversions Please_enter_a_search_string=Entrez_s'il_vous_plait_une_chaine_de_recherche diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 24a7595923e..3b8b2b2f818 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1143,7 +1143,6 @@ Searching...=Sedang_mencari... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Anda_memilih_lebih_dari_%0_entri._Sejumlah_situs_web_akan_memblokir_anda_kalau_melakukan_terlalu_banyak_pemuatturunan_dengan_cepat._Apa_mau_teruskan? Confirm_selection=Mengkonfirmasi_pilihan Unknown_DOI\:_'%0'.=DOI_tidak_dikenal\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions=Impor_konversi Please_enter_a_search_string=Tuliskan_string_pencarian diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 3ae8e350e86..b9a6561346d 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1244,7 +1244,6 @@ Searching...=Ricerca_in_corso... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Sono_state_selezionate_pi\u00f9_di_%0_voci_da_scaricare._Alcuni_siti_potrebbero_bloccare_la_connessione_se_si_eseguono_scaricamenti_troppo_numerosi_e_rapidi._Continuare? Confirm_selection=Conferma_la_selezione Unknown_DOI\:_'%0'.=DOI_sconosciuto\:_'%0' -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Conversione_di_apici_e_pedici_in_equazioni_piuttosto_che_in_testo. Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Aggiungere_{}_alle_parole_del_titolo_specificate_per_mantenere_la_corretta_capitalizzazione_nella_ricerca. Import_conversions=Importare_le_conversioni Please_enter_a_search_string=Inserire_una_stringa_di_ricerca diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index b1e8d314abb..d6cbde88f90 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -1915,7 +1915,6 @@ Searching...=検索中... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=ダウンロードする項目を%0個以上選択しました。あまりに多くのダウンロードを急に行うと、其れをブロックするウェブサイトもあります。続けますか? Confirm_selection=選択範囲を確認 Unknown_DOI\:_'%0'.=「%0」は既知のDOIではありません -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=上添字及び下添字をテキストではなく数式に変換する Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=大小文字を正しく維持するため、検索中に指定したタイトル語に{}を付け加える Import_conversions=読み込み時変換 Please_enter_a_search_string=検索文字列を入力してください diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 19016e7e695..95b71fe05df 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -1917,7 +1917,6 @@ Searching...= You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection= Unknown_DOI\:_'%0'.=Unbekende_DOI\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions= Please_enter_a_search_string= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index e5747132d9b..fb3d3e1f6e0 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2312,7 +2312,6 @@ Searching...= You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection= Unknown_DOI\:_'%0'.= -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions= Please_enter_a_search_string= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 415dd4be244..d9d4e1aaf9b 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1141,7 +1141,6 @@ Searching...=Buscando... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Você_selecionou_mais_de_%0_entradas_para_download._Alguns_sites_podem_bloquear_seu_acesso_se_você_fizer_muitos_downloads_num_período_curto_de_tempo._Deseja_continuar_mesmo_assim? Confirm_selection=Confirmar_seleção Unknown_DOI\:_'%0'.=DOI_desconhecido\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Dar_preferência_à_conversão_de_subscritos_sobrescritos_para_equações_ao_invés_de_textos Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Adicione_{}_às_palavras_do_título_na_busca_para_manter_maiúsculas_minúsculas Import_conversions=Importar_conversões Please_enter_a_search_string=Favor_digitar_uma_string_de_busca diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 8e36e2193b4..578b1a8e65d 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -1885,7 +1885,6 @@ Searching...=Выполняется_поиск... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=Выбрано_более_%0_записей_для_загрузки._Возможна_блокировка_пользователя_некоторыми_веб-сайтами_при_большом_числе_быстрых_загрузок._Продолжить? Confirm_selection=Подтвердить_выбор Unknown_DOI\:_'%0'.=Неизвестный_DOI\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Преобразовывать_надстрочный_и_подстрочный_индекс_в_формулу_вместо_текста Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Добавлять_{}_к_указанным_заглавным_словам_при_поиске_для_соблюдения_правильности_регистра Import_conversions=Импорт_преобразований Please_enter_a_search_string=Введите_строку_для_поиска diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 6c2ba56626f..8e618bc4a72 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -867,7 +867,6 @@ Possible_duplicate_entries=Möjliga_dubbletter Possible_duplicate_of_existing_entry._Click_to_resolve.=Möjlig_dubblett_av_befintlig_post._Klicka_för_att_reda_ut. Preamble=Preamble Preamble_editor,_store_changes=Preamble-editorn,_spara_ändringar -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Preferences=Inställningar Preferences_recorded.=Inställningar_sparade. Preview=Postvisning diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 7ae734f66d7..daa1a5b68b8 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1163,7 +1163,6 @@ Searching...=Arıyor... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?=İndirmek_için_%0'dan_fazla_girdi_seçtiniz._Çok_sayıda_hızlı_indirme_yaparsanız_bazı_web_siteleri_sizi_bloke_edebilir._Devam_etmek_istiyor_musunuz? Confirm_selection=Seçimi_onayla Unknown_DOI\:_'%0'.=Bilinmeyen_DOI\:_'%0'. -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=Alt_ve_üstsimgeleri_metinden_ziyade_denklemlere_dönüştürmeyi_tercih_et Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=Aramada_doğru_küçük_büyük_harf_seçimi_için_belirli_başlık_sözcüklerine_{}_ekleyin Import_conversions=Dönüşümleri_içe_aktar Please_enter_a_search_string=Lütfen_bir_arama_dizgesi_girin diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 78865a76a74..8287ab5aaab 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -1911,7 +1911,6 @@ Searching...= You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection= Unknown_DOI\:_'%0'.= -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text= Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case= Import_conversions= Please_enter_a_search_string= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index 0292f2f0fea..e8949a25a47 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1217,7 +1217,6 @@ Searching...=正在搜索... You_have_selected_more_than_%0_entries_for_download._Some_web_sites_might_block_you_if_you_make_too_many_rapid_downloads._Do_you_want_to_continue?= Confirm_selection=确认选择 Unknown_DOI\:_'%0'.= -Prefer_converting_subscripts_and_superscripts_to_equations_rather_than_text=将上下标转换成公式而不是文本 Add_{}_to_specified_title_words_on_search_to_keep_the_correct_case=搜索时为特殊的标题单词添加_{}_以保证大小写正确 Import_conversions=导入约定 Please_enter_a_search_string=请输入一个搜索字符串 diff --git a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java index c59ab7b2224..91d81b055b5 100644 --- a/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java @@ -261,8 +261,7 @@ public void cleanupRenamePdfRenamesRelativeFile() throws IOException { @Test public void cleanupHtmlToLatexConvertsEpsilonToLatex() { CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(true, - Collections.singletonList(new FieldFormatterCleanup("title", new HtmlToLatexFormatter( - Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)))))); + Collections.singletonList(new FieldFormatterCleanup("title", new HtmlToLatexFormatter())))); BibEntry entry = new BibEntry(); entry.setField("title", "Ε"); diff --git a/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java b/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java index ed755a49690..442e9421f08 100644 --- a/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java +++ b/src/test/java/net/sf/jabref/logic/formatter/FormatterTest.java @@ -105,7 +105,7 @@ public static Collection instancesToTest() { return Arrays.asList( new Object[]{new CapitalizeFormatter()}, new Object[]{new ClearFormatter()}, - new Object[]{new HtmlToLatexFormatter(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION))}, + new Object[]{new HtmlToLatexFormatter()}, new Object[]{new HtmlToUnicodeFormatter()}, new Object[]{new IdentityFormatter()}, new Object[]{new LatexCleanupFormatter()}, diff --git a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java index fef63b4c4da..beede42e473 100644 --- a/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java +++ b/src/test/java/net/sf/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java @@ -23,7 +23,7 @@ public static void setUpBeforeClass() throws Exception { @Before public void setUp() { - formatter = new HtmlToLatexFormatter(Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION)); + formatter = new HtmlToLatexFormatter(); } @Test From 431176b5dddfac71ee231fe2c351d675ac1f58a3 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 13:20:08 +0200 Subject: [PATCH 10/17] Added preference classes for LatexFieldFormatter and FieldContentParser --- .../java/net/sf/jabref/gui/StringDialog.java | 4 +- .../jabref/gui/TransferableBibtexEntry.java | 4 +- .../jabref/gui/entryeditor/EntryEditor.java | 10 +++- .../jabref/gui/mergeentries/MergeEntries.java | 4 +- .../gui/plaintextimport/TextInputDialog.java | 4 +- .../jabref/gui/worker/SendAsEMailAction.java | 4 +- .../importer/fileformat/BibtexParser.java | 4 +- .../logic/bibtex/FieldContentParser.java | 6 +- .../bibtex/FieldContentParserPreferences.java | 24 ++++++++ .../logic/bibtex/LatexFieldFormatter.java | 37 +++++------- .../LatexFieldFormatterPreferences.java | 58 +++++++++++++++++++ .../logic/exporter/BibtexDatabaseWriter.java | 8 ++- .../java/net/sf/jabref/logic/xmp/XMPUtil.java | 4 +- .../logic/bibtex/BibEntryWriterTest.java | 3 +- .../logic/bibtex/FieldContentParserTest.java | 2 +- .../bibtex/LatexFieldFormatterTests.java | 2 +- .../net/sf/jabref/logic/xmp/XMPUtilTest.java | 4 +- 17 files changed, 139 insertions(+), 43 deletions(-) create mode 100644 src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java create mode 100644 src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java diff --git a/src/main/java/net/sf/jabref/gui/StringDialog.java b/src/main/java/net/sf/jabref/gui/StringDialog.java index 8e2dab96fc2..50a5d4ec512 100644 --- a/src/main/java/net/sf/jabref/gui/StringDialog.java +++ b/src/main/java/net/sf/jabref/gui/StringDialog.java @@ -55,6 +55,7 @@ import net.sf.jabref.gui.undo.UndoableStringChange; import net.sf.jabref.gui.util.PositionWindow; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.bibtex.comparator.BibtexStringComparator; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibDatabase; @@ -266,7 +267,8 @@ public void setValueAt(Object value, int row, int col) { if (!value.equals(subject.getContent())) { try { - new LatexFieldFormatter(Globals.prefs).format((String) value, "__dummy"); + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)) + .format((String) value, "__dummy"); } catch (IllegalArgumentException ex) { return; } diff --git a/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java b/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java index 2bfa4b9acae..9245af85f72 100644 --- a/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java +++ b/src/main/java/net/sf/jabref/gui/TransferableBibtexEntry.java @@ -27,6 +27,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; @@ -64,7 +65,8 @@ public Object getTransferData(DataFlavor flavor) } else if (flavor.equals(DataFlavor.stringFlavor)) { try { StringWriter sw = new StringWriter(); - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter( + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), false); for (BibEntry entry : data) { bibtexEntryWriter.write(entry, sw, BibDatabaseMode.BIBTEX); } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index bf7271cb8fe..ef51e832455 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -96,6 +96,7 @@ import net.sf.jabref.logic.autocompleter.AutoCompleter; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.labelpattern.LabelPatternUtil; import net.sf.jabref.logic.search.SearchQueryHighlightListener; @@ -592,7 +593,8 @@ public void updateSource() { public static String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException { StringWriter stringWriter = new StringWriter(200); - LatexFieldFormatter formatter = LatexFieldFormatter.buildIgnoreHashes(Globals.prefs); + LatexFieldFormatter formatter = LatexFieldFormatter + .buildIgnoreHashes(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)); new BibEntryWriter(formatter, false).writeWithoutPrependedNewlines(entry, stringWriter, type); return stringWriter.getBuffer().toString(); @@ -813,7 +815,8 @@ private boolean storeSource() { String newValue = newEntry.getField(field); if (!Objects.equals(oldValue, newValue)) { // Test if the field is legally set. - new LatexFieldFormatter(Globals.prefs).format(newValue, field); + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)) + .format(newValue, field); compound.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); entry.setField(field, newValue); @@ -1167,7 +1170,8 @@ public void actionPerformed(ActionEvent event) { // properly formatted. If that happens, the field // is not stored and the textarea turns red. if (toSet != null) { - new LatexFieldFormatter(Globals.prefs).format(toSet, fieldEditor.getFieldName()); + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)) + .format(toSet, fieldEditor.getFieldName()); } String oldValue = entry.getField(fieldEditor.getFieldName()); diff --git a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java index 73a426e8432..7d15dd53d13 100644 --- a/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java +++ b/src/main/java/net/sf/jabref/gui/mergeentries/MergeEntries.java @@ -46,6 +46,7 @@ import net.sf.jabref.gui.PreviewPanel; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.formatter.casechanger.SentenceCaseFormatter; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.strings.DiffHighlighting; @@ -452,7 +453,8 @@ private void updateAll() { // Update the BibTeX source view StringWriter writer = new StringWriter(); try { - new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(mergedEntry, writer, databaseType); + new BibEntryWriter(new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), + false).write(mergedEntry, writer, databaseType); } catch (IOException ex) { LOGGER.error("Error in entry", ex); } diff --git a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java index 10cca6ab86b..4107bb59e61 100644 --- a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java @@ -123,6 +123,7 @@ import net.sf.jabref.importer.fileformat.FreeCiteImporter; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.model.EntryTypes; @@ -537,7 +538,8 @@ private boolean parseWithFreeCiteAndAddEntries() { private void updateSourceView() { StringWriter sw = new StringWriter(200); try { - new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(entry, sw, + new BibEntryWriter(new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), + false).write(entry, sw, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); sourcePreview.setText(sw.getBuffer().toString()); } catch (IOException ex) { diff --git a/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java b/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java index 33322e5e461..aa90899d572 100644 --- a/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java +++ b/src/main/java/net/sf/jabref/gui/worker/SendAsEMailAction.java @@ -30,6 +30,7 @@ import net.sf.jabref.gui.desktop.JabRefDesktop; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.entry.BibEntry; @@ -80,7 +81,8 @@ public void run() { List bes = panel.getSelectedEntries(); // write the entries using sw, which is used later to form the email content - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter( + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), true); for (BibEntry entry : bes) { try { diff --git a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java index fc594d601c1..c614bced668 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java @@ -34,6 +34,7 @@ import net.sf.jabref.MetaData; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.bibtex.FieldContentParser; +import net.sf.jabref.logic.bibtex.FieldContentParserPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.database.KeyCollisionException; @@ -71,7 +72,8 @@ public class BibtexParser { private Map entryTypes; private boolean eof; private int line = 1; - private final FieldContentParser fieldContentParser = new FieldContentParser(Globals.prefs); + private final FieldContentParser fieldContentParser = new FieldContentParser( + FieldContentParserPreferences.fromPreferences(Globals.prefs)); private ParserResult parserResult; private static final Integer LOOKAHEAD = 64; private final Deque pureTextFromFile = new LinkedList<>(); diff --git a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java index cd3f6d25de3..2deedeba503 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java @@ -16,7 +16,6 @@ package net.sf.jabref.logic.bibtex; import java.util.HashSet; -import java.util.List; import java.util.regex.Pattern; import net.sf.jabref.logic.util.strings.StringUtil; @@ -34,14 +33,13 @@ public class FieldContentParser { private static final Pattern WHITESPACE = Pattern.compile("\\s+"); - public FieldContentParser(JabRefPreferences prefs) { + public FieldContentParser(FieldContentParserPreferences prefs) { multiLineFields = new HashSet<>(); // the following two are also coded in net.sf.jabref.logic.bibtex.LatexFieldFormatter.format(String, String) multiLineFields.add("abstract"); multiLineFields.add("review"); // the file field should not be formatted, therefore we treat it as a multi line field - List nonWrappableFields = prefs.getStringList(JabRefPreferences.NON_WRAPPABLE_FIELDS); - multiLineFields.addAll(nonWrappableFields); + multiLineFields.addAll(prefs.getNonWrappableFields()); } /** diff --git a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java new file mode 100644 index 00000000000..1eafaf80f3f --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java @@ -0,0 +1,24 @@ +package net.sf.jabref.logic.bibtex; + +import java.util.List; + +import net.sf.jabref.JabRefPreferences; + +public class FieldContentParserPreferences { + + private final List nonWrappableFields; + + + public FieldContentParserPreferences(List nonWrappableFields) { + this.nonWrappableFields = nonWrappableFields; + } + + public List getNonWrappableFields() { + return nonWrappableFields; + } + + public static FieldContentParserPreferences fromPreferences(JabRefPreferences jabRefPreferences) { + return new FieldContentParserPreferences( + jabRefPreferences.getStringList(JabRefPreferences.NON_WRAPPABLE_FIELDS)); + } +} diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java index 9bb0a71d266..6dfee365111 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java @@ -40,32 +40,23 @@ public class LatexFieldFormatter { private final boolean neverFailOnHashes; - private final boolean resolveStringsAllFields; - private final char valueDelimiterStartOfValue; - private final char valueDelimiterEndOfValue; - private final List doNotResolveStringsFors; - private final int lineLength; + private final LatexFieldFormatterPreferences prefs; private final FieldContentParser parser; - public LatexFieldFormatter(JabRefPreferences prefs) { + public LatexFieldFormatter(LatexFieldFormatterPreferences prefs) { this(true, prefs); } - private LatexFieldFormatter(boolean neverFailOnHashes, JabRefPreferences prefs) { + private LatexFieldFormatter(boolean neverFailOnHashes, LatexFieldFormatterPreferences prefs) { this.neverFailOnHashes = neverFailOnHashes; + this.prefs = prefs; - this.resolveStringsAllFields = prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS); - valueDelimiterStartOfValue = prefs.getValueDelimiters(0); - valueDelimiterEndOfValue = prefs.getValueDelimiters(1); - doNotResolveStringsFors = prefs.getStringList(JabRefPreferences.DO_NOT_RESOLVE_STRINGS_FOR); - lineLength = prefs.getInt(JabRefPreferences.LINE_LENGTH); - - parser = new FieldContentParser(prefs); + parser = new FieldContentParser(prefs.getFieldContentParserPreferences()); } - public static LatexFieldFormatter buildIgnoreHashes(JabRefPreferences prefs) { + public static LatexFieldFormatter buildIgnoreHashes(LatexFieldFormatterPreferences prefs) { return new LatexFieldFormatter(true, prefs); } @@ -81,7 +72,7 @@ public String format(String content, String fieldName) throws IllegalArgumentException { if (content == null) { - return valueDelimiterStartOfValue + String.valueOf(valueDelimiterEndOfValue); + return prefs.getValueDelimiterStartOfValue() + String.valueOf(prefs.getValueDelimiterEndOfValue()); } String result = content; @@ -172,9 +163,9 @@ private String formatAndResolveStrings(String content, String fieldName) { private boolean shouldResolveStrings(String fieldName) { boolean resolveStrings = true; - if (resolveStringsAllFields) { + if (prefs.isResolveStringsAllFields()) { // Resolve strings for all fields except some: - for (String exception : doNotResolveStringsFors) { + for (String exception : prefs.getDoNotResolveStringsFor()) { if (exception.equals(fieldName)) { resolveStrings = false; break; @@ -192,18 +183,18 @@ private String formatWithoutResolvingStrings(String content, String fieldName) { checkBraces(content); stringBuilder = new StringBuilder( - String.valueOf(valueDelimiterStartOfValue)); + String.valueOf(prefs.getValueDelimiterStartOfValue())); stringBuilder.append(parser.format(content, fieldName)); - stringBuilder.append(valueDelimiterEndOfValue); + stringBuilder.append(prefs.getValueDelimiterEndOfValue()); return stringBuilder.toString(); } private void writeText(String text, int startPos, int endPos) { - stringBuilder.append(valueDelimiterStartOfValue); + stringBuilder.append(prefs.getValueDelimiterStartOfValue()); boolean escape = false; boolean inCommandName = false; boolean inCommand = false; @@ -262,7 +253,7 @@ private void writeText(String text, int startPos, int endPos) { } escape = c == '\\'; } - stringBuilder.append(valueDelimiterEndOfValue); + stringBuilder.append(prefs.getValueDelimiterEndOfValue()); } private void writeStringLabel(String text, int startPos, int endPos, @@ -272,7 +263,7 @@ private void writeStringLabel(String text, int startPos, int endPos, } private void putIn(String s) { - stringBuilder.append(StringUtil.wrap(s, lineLength)); + stringBuilder.append(StringUtil.wrap(s, prefs.getLineLength())); } private static void checkBraces(String text) throws IllegalArgumentException { diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java new file mode 100644 index 00000000000..6bb2fad073b --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java @@ -0,0 +1,58 @@ +package net.sf.jabref.logic.bibtex; + +import java.util.List; + +import net.sf.jabref.JabRefPreferences; + +public class LatexFieldFormatterPreferences { + + private final boolean resolveStringsAllFields; + private final char valueDelimiterStartOfValue; + private final char valueDelimiterEndOfValue; + private final List doNotResolveStringsFor; + private final int lineLength; + private final FieldContentParserPreferences fieldContentParserPreferences; + + + public LatexFieldFormatterPreferences(boolean resolveStringsAllFields, char valueDelimiterStartOfValue, + char valueDelimiterEndOfValue, List doNotResolveStringsFor, int lineLength, + FieldContentParserPreferences fieldContentParserPreferences) { + this.resolveStringsAllFields = resolveStringsAllFields; + this.valueDelimiterStartOfValue = valueDelimiterStartOfValue; + this.valueDelimiterEndOfValue = valueDelimiterEndOfValue; + this.doNotResolveStringsFor = doNotResolveStringsFor; + this.lineLength = lineLength; + this.fieldContentParserPreferences = fieldContentParserPreferences; + } + + public static LatexFieldFormatterPreferences fromPreferences(JabRefPreferences prefs) { + return new LatexFieldFormatterPreferences(prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS), + prefs.getValueDelimiters(0), prefs.getValueDelimiters(1), + prefs.getStringList(JabRefPreferences.DO_NOT_RESOLVE_STRINGS_FOR), + prefs.getInt(JabRefPreferences.LINE_LENGTH), FieldContentParserPreferences.fromPreferences(prefs)); + } + + public boolean isResolveStringsAllFields() { + return resolveStringsAllFields; + } + + public char getValueDelimiterStartOfValue() { + return valueDelimiterStartOfValue; + } + + public char getValueDelimiterEndOfValue() { + return valueDelimiterEndOfValue; + } + + public List getDoNotResolveStringsFor() { + return doNotResolveStringsFor; + } + + public int getLineLength() { + return lineLength; + } + + public FieldContentParserPreferences getFieldContentParserPreferences() { + return fieldContentParserPreferences; + } +} diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index 9396dfe01db..197d7e04880 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -26,6 +26,7 @@ import net.sf.jabref.MetaData; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; @@ -112,7 +113,9 @@ protected void writeString(BibtexString bibtexString, boolean isFirstString, int getWriter().write("{}"); } else { try { - String formatted = new LatexFieldFormatter(jabRefPreferences).format(bibtexString.getContent(), + String formatted = new LatexFieldFormatter( + LatexFieldFormatterPreferences.fromPreferences(jabRefPreferences)) + .format(bibtexString.getContent(), LatexFieldFormatter.BIBTEX_STRING); getWriter().write(formatted); } catch (IllegalArgumentException ex) { @@ -158,7 +161,8 @@ protected void writePrelogue(BibDatabaseContext bibDatabaseContext, Charset enco @Override protected void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile) throws SaveException { - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(jabRefPreferences), true); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter( + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(jabRefPreferences)), true); try { bibtexEntryWriter.write(entry, getWriter(), mode, isReformatFile); } catch (IOException e) { diff --git a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java index 5e5ff75c83c..d4280c0cfb2 100644 --- a/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java +++ b/src/main/java/net/sf/jabref/logic/xmp/XMPUtil.java @@ -47,6 +47,7 @@ import net.sf.jabref.logic.TypedBibEntry; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.Author; @@ -1190,7 +1191,8 @@ public static void main(String[] args) throws IOException, TransformerException // Read from pdf and write as BibTex List l = XMPUtil.readXMP(new File(args[0]), Globals.prefs); - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter( + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), false); for (BibEntry entry : l) { StringWriter sw = new StringWriter(); diff --git a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java index 398ade15e58..15aa1ff6568 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java @@ -39,7 +39,8 @@ public static void tearDown() { @Before public void setUpWriter() { - writer = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), true); + writer = new BibEntryWriter( + new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), true); } @Test diff --git a/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java b/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java index 64937e9bce9..2af06571390 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/FieldContentParserTest.java @@ -20,7 +20,7 @@ public static void loadPreferences() { @Before public void setUp() throws Exception { - parser = new FieldContentParser(Globals.prefs); + parser = new FieldContentParser(FieldContentParserPreferences.fromPreferences(Globals.prefs)); } @Test diff --git a/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java b/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java index db50abccaf0..ba17d60329d 100644 --- a/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java +++ b/src/test/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterTests.java @@ -20,7 +20,7 @@ public static void setUpBeforeClass(){ @Before public void setUp() { - this.formatter = new LatexFieldFormatter(Globals.prefs); + this.formatter = new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)); } @Test diff --git a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java index 80933894cb3..11864d22c69 100644 --- a/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/xmp/XMPUtilTest.java @@ -31,6 +31,7 @@ import net.sf.jabref.importer.fileformat.BibtexParser; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; @@ -141,7 +142,8 @@ public static BibEntry bibtexString2BibtexEntry(String s) throws IOException { public static String bibtexEntry2BibtexString(BibEntry e) throws IOException { StringWriter sw = new StringWriter(); - new BibEntryWriter(new LatexFieldFormatter(Globals.prefs), false).write(e, sw, BibDatabaseMode.BIBTEX); + new BibEntryWriter(new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), + false).write(e, sw, BibDatabaseMode.BIBTEX); return sw.getBuffer().toString(); } From b527f216ce2586f2b865f0da2288480b9e0f1e97 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 13:22:38 +0200 Subject: [PATCH 11/17] Removed some left over code --- .../java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java | 2 -- src/main/java/net/sf/jabref/preferences/JabRefPreferences.java | 1 - 2 files changed, 3 deletions(-) diff --git a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java index 471ce763a1b..9bbf4ec6ee1 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java @@ -73,11 +73,9 @@ public class IEEEXploreFetcher implements EntryFetcher { private static final Pattern SUB_DETECTION_1 = Pattern.compile("/sub ([^/]+)/"); private static final Pattern SUB_DETECTION_2 = Pattern.compile("\\(sub\\)([^(]+)\\(/sub\\)"); private static final String SUB_TEXT_RESULT = "\\\\textsubscript\\{$1\\}"; - private static final String SUB_EQ_RESULT = "\\$_\\{$1\\}\\$"; private static final Pattern SUPER_DETECTION_1 = Pattern.compile("/sup ([^/]+)/"); private static final Pattern SUPER_DETECTION_2 = Pattern.compile("\\(sup\\)([^(]+)\\(/sup\\)"); private static final String SUPER_TEXT_RESULT = "\\\\textsuperscript\\{$1\\}"; - private static final String SUPER_EQ_RESULT = "\\$\\^\\{$1\\}\\$"; private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter(); private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter(); diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 033f1f68954..dd299ab52b4 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -338,7 +338,6 @@ public class JabRefPreferences { public static final String CUSTOM_TAB_FIELDS = "customTabFields_"; public static final String USE_UNIT_FORMATTER_ON_SEARCH = "useUnitFormatterOnSearch"; public static final String USE_CASE_KEEPER_ON_SEARCH = "useCaseKeeperOnSearch"; - public static final String USE_CONVERT_TO_EQUATION = "useConvertToEquation"; public static final String USE_IEEE_ABRV = "useIEEEAbrv"; public static final String AKS_AUTO_NAMING_PDFS_AGAIN = "AskAutoNamingPDFsAgain"; From 283dfcbef8028436409d957bc04bd140e9f2894e Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 14:29:33 +0200 Subject: [PATCH 12/17] Added JournalAbbreviationPreferences --- .../java/net/sf/jabref/gui/BasePanel.java | 4 +- .../gui/entryeditor/FieldExtraComponents.java | 3 +- .../jabref/gui/journals/AbbreviateAction.java | 5 +- .../gui/journals/ManageJournalsPanel.java | 7 ++- .../gui/journals/UnabbreviateAction.java | 4 +- .../sf/jabref/gui/preftabs/AdvancedTab.java | 3 +- .../importer/fetcher/IEEEXploreFetcher.java | 5 +- .../AutoCompletePreferences.java | 5 ++ .../autocompleter/AutoCompleterFactory.java | 10 ++-- .../autocompleter/ContentAutoCompleters.java | 6 +-- .../autocompleter/JournalAutoCompleter.java | 11 +++-- .../journals/JournalAbbreviationLoader.java | 18 ++++---- .../JournalAbbreviationPreferences.java | 46 +++++++++++++++++++ .../sf/jabref/logic/layout/LayoutEntry.java | 3 +- .../layout/format/JournalAbbreviator.java | 13 ++++-- .../AutoCompleterFactoryTest.java | 4 +- .../logic/journals/AbbreviationsTest.java | 16 +++++-- 17 files changed, 117 insertions(+), 46 deletions(-) create mode 100644 src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index a73d38262e7..0d37f709f97 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1572,7 +1572,7 @@ public void setupMainPanel() { // Set up AutoCompleters for this panel: if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) { autoCompleters = new ContentAutoCompleters(getDatabase(), bibDatabaseContext.getMetaData(), - autoCompletePreferences, Globals.journalAbbreviationLoader, Globals.prefs); + autoCompletePreferences, Globals.journalAbbreviationLoader); // ensure that the autocompleters are in sync with entries this.getDatabase().registerListener(new AutoCompleteListener()); } else { @@ -1598,7 +1598,7 @@ public void updateSearchManager() { private void instantiateSearchAutoCompleter() { AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs); AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(autoCompletePreferences, - Globals.journalAbbreviationLoader, Globals.prefs); + Globals.journalAbbreviationLoader); searchAutoCompleter = autoCompleterFactory.getPersonAutoCompleter(); for (BibEntry entry : database.getEntries()) { searchAutoCompleter.addBibtexEntry(entry); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java b/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java index cdcf17a4e57..186b9054976 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FieldExtraComponents.java @@ -45,6 +45,7 @@ import net.sf.jabref.gui.fieldeditors.FieldEditor; import net.sf.jabref.gui.mergeentries.MergeEntryDOIDialog; import net.sf.jabref.gui.undo.UndoableFieldChange; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationRepository; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.net.URLUtil; @@ -94,7 +95,7 @@ public static Optional getJournalExtraComponent(JabRefFrame frame, B button.addActionListener(actionEvent -> { String text = editor.getText(); JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader - .getRepository(Globals.prefs); + .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)); if (abbreviationRepository.isKnownName(text)) { String s = abbreviationRepository.getNextAbbreviation(text).orElse(text); diff --git a/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java b/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java index f06c182af81..ac94c7899d4 100644 --- a/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java +++ b/src/main/java/net/sf/jabref/gui/journals/AbbreviateAction.java @@ -21,6 +21,7 @@ import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.worker.AbstractWorker; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; @@ -52,7 +53,9 @@ public void run() { } UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator( - Globals.journalAbbreviationLoader.getRepository(Globals.prefs), iso); + Globals.journalAbbreviationLoader + .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)), + iso); NamedCompound ce = new NamedCompound(Localization.lang("Abbreviate journal names")); int count = 0; diff --git a/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java b/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java index f50afa9a5e9..4fc7f667a02 100644 --- a/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java +++ b/src/main/java/net/sf/jabref/gui/journals/ManageJournalsPanel.java @@ -66,6 +66,7 @@ import net.sf.jabref.gui.net.MonitoredURLDownload; import net.sf.jabref.logic.journals.Abbreviation; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.preferences.JabRefPreferences; @@ -185,7 +186,9 @@ public ManageJournalsPanel(final JabRefFrame frame) { viewBuiltin.addActionListener(e -> { JTable table = new JTable(JournalAbbreviationsUtil - .getTableModel(Globals.journalAbbreviationLoader.getRepository(Globals.prefs).getAbbreviations())); + .getTableModel(Globals.journalAbbreviationLoader + .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getAbbreviations())); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); @@ -392,7 +395,7 @@ private void storeSettings() { Globals.prefs.putStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS, extFiles); // Update journal abbreviation loader - Globals.journalAbbreviationLoader.update(Globals.prefs); + Globals.journalAbbreviationLoader.update(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)); } diff --git a/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java b/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java index 73a11e3aaa9..28b5a3a505b 100644 --- a/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java +++ b/src/main/java/net/sf/jabref/gui/journals/UnabbreviateAction.java @@ -21,6 +21,7 @@ import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.worker.AbstractWorker; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; @@ -50,7 +51,8 @@ public void run() { } UndoableUnabbreviator undoableAbbreviator = new UndoableUnabbreviator( - Globals.journalAbbreviationLoader.getRepository(Globals.prefs)); + Globals.journalAbbreviationLoader + .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs))); NamedCompound ce = new NamedCompound(Localization.lang("Unabbreviate journal names")); int count = 0; diff --git a/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java b/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java index 62bf6b98f31..b2b78cfbd87 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/AdvancedTab.java @@ -29,6 +29,7 @@ import net.sf.jabref.gui.help.HelpAction; import net.sf.jabref.gui.help.HelpFile; import net.sf.jabref.gui.remote.JabRefMessageHandler; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.remote.RemotePreferences; import net.sf.jabref.logic.remote.RemoteUtil; @@ -119,7 +120,7 @@ public void setValues() { public void storeSettings() { if (preferences.getBoolean(JabRefPreferences.USE_IEEE_ABRV) != useIEEEAbrv.isSelected()) { preferences.putBoolean(JabRefPreferences.USE_IEEE_ABRV, useIEEEAbrv.isSelected()); - Globals.journalAbbreviationLoader.update(preferences); + Globals.journalAbbreviationLoader.update(JournalAbbreviationPreferences.fromPreferences(preferences)); } storeRemoteSettings(); diff --git a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java index 9bbf4ec6ee1..9d8bae307bf 100644 --- a/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java +++ b/src/main/java/net/sf/jabref/importer/fetcher/IEEEXploreFetcher.java @@ -44,6 +44,7 @@ import net.sf.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter; import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.net.URLDownload; import net.sf.jabref.model.entry.BibEntry; @@ -435,7 +436,9 @@ private BibEntry cleanup(BibEntry entry) { fullName = fullName.trim(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) { - fullName = abbreviationLoader.getRepository(Globals.prefs).getMedlineAbbreviation(fullName) + fullName = abbreviationLoader + .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getMedlineAbbreviation(fullName) .orElse(fullName); } } diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java index c0694feae1e..ced72ddbb8b 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java @@ -20,6 +20,7 @@ import java.util.Objects; import net.sf.jabref.preferences.JabRefPreferences; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; public class AutoCompletePreferences { @@ -98,4 +99,8 @@ public String getCompleteNamesAsString() { public void setCompleteNames(String value) { preferences.put(PREF_COMPLETE_FIELDS, value); } + + public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { + return JournalAbbreviationPreferences.fromPreferences(preferences); + } } \ No newline at end of file diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java index 31c744e1e96..f0f2d2a1b3d 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java @@ -18,8 +18,8 @@ import java.util.Arrays; import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.model.entry.FieldProperties; import net.sf.jabref.model.entry.InternalBibtexFields; @@ -32,13 +32,11 @@ public class AutoCompleterFactory { private final AutoCompletePreferences preferences; private final JournalAbbreviationLoader abbreviationLoader; - private final JabRefPreferences jabRefPreferences; - public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader, - JabRefPreferences jabRefPreferences) { + + public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) { this.preferences = Objects.requireNonNull(preferences); this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); - this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); } public AutoCompleter getFor(String fieldName) { @@ -49,7 +47,7 @@ public AutoCompleter getFor(String fieldName) { } else if ("crossref".equals(fieldName)) { return new BibtexKeyAutoCompleter(preferences); } else if ("journal".equals(fieldName) || "publisher".equals(fieldName)) { - return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader, jabRefPreferences); + return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader); } else { return new DefaultAutoCompleter(fieldName, preferences); } diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java b/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java index b71f0bbf725..2951af38ae9 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/ContentAutoCompleters.java @@ -4,7 +4,6 @@ import java.util.Map; import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.database.BibDatabase; @@ -15,11 +14,10 @@ public ContentAutoCompleters() { } public ContentAutoCompleters(BibDatabase database, MetaData metaData, AutoCompletePreferences preferences, - JournalAbbreviationLoader abbreviationLoader, JabRefPreferences jabRefPreferences) { + JournalAbbreviationLoader abbreviationLoader) { Objects.requireNonNull(preferences); - AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader, - jabRefPreferences); + AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); List completeFields = preferences.getCompleteNames(); for (String field : completeFields) { AutoCompleter autoCompleter = autoCompleterFactory.getFor(field); diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java b/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java index ca5e878116f..64cab011c0d 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/JournalAutoCompleter.java @@ -20,21 +20,21 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.Abbreviation; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; public class JournalAutoCompleter extends EntireFieldAutoCompleter { private final JournalAbbreviationLoader abbreviationLoader; - private final JabRefPreferences jabRefPreferences; + private final JournalAbbreviationPreferences journalAbbreviationPreferences; JournalAutoCompleter(String fieldName, AutoCompletePreferences preferences, - JournalAbbreviationLoader abbreviationLoader, JabRefPreferences jabRefPreferences) { + JournalAbbreviationLoader abbreviationLoader) { super(fieldName, preferences); this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader); - this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); + this.journalAbbreviationPreferences = preferences.getJournalAbbreviationPreferences(); } @Override @@ -42,7 +42,8 @@ public List complete(String toComplete) { List completions = super.complete(toComplete); // Also return journal names in the journal abbreviation list - for (Abbreviation abbreviation : abbreviationLoader.getRepository(jabRefPreferences).getAbbreviations()) { + for (Abbreviation abbreviation : abbreviationLoader + .getRepository(journalAbbreviationPreferences).getAbbreviations()) { if (abbreviation.getName().startsWith(toComplete)) { completions.add(abbreviation.getName()); } diff --git a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java index 8fcc80198ab..0926e967f2d 100644 --- a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationLoader.java @@ -22,8 +22,6 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.preferences.JabRefPreferences; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,7 +35,8 @@ public class JournalAbbreviationLoader { private static final String JOURNALS_IEEE_ABBREVIATION_LIST_WITH_TEXT = "/journals/IEEEJournalListText.txt"; private JournalAbbreviationRepository journalAbbrev; - public void update(JabRefPreferences jabRefPreferences) { + + public void update(JournalAbbreviationPreferences journalAbbreviationPreferences) { journalAbbrev = new JournalAbbreviationRepository(); // the order of reading the journal lists is important @@ -48,14 +47,14 @@ public void update(JabRefPreferences jabRefPreferences) { journalAbbrev.addEntries(readJournalListFromResource(JOURNALS_FILE_BUILTIN)); // read IEEE list - if (jabRefPreferences.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) { + if (journalAbbreviationPreferences.isUseIEEEAbbreviations()) { journalAbbrev.addEntries(getOfficialIEEEAbbreviations()); } else { journalAbbrev.addEntries(getStandardIEEEAbbreviations()); } // Read external lists - List lists = jabRefPreferences.getStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS); + List lists = journalAbbreviationPreferences.getExternalJournalLists(); if (!(lists.isEmpty())) { Collections.reverse(lists); for (String filename : lists) { @@ -69,11 +68,12 @@ public void update(JabRefPreferences jabRefPreferences) { } // Read personal list - String personalJournalList = jabRefPreferences.get(JabRefPreferences.PERSONAL_JOURNAL_LIST); + String personalJournalList = journalAbbreviationPreferences.getPersonalJournalLists(); if ((personalJournalList != null) && !personalJournalList.trim().isEmpty()) { try { journalAbbrev.addEntries( - readJournalListFromFile(new File(personalJournalList), jabRefPreferences.getDefaultEncoding())); + readJournalListFromFile(new File(personalJournalList), + journalAbbreviationPreferences.getDefaultEncoding())); } catch (FileNotFoundException e) { LOGGER.info("Personal journal list file '" + personalJournalList + "' not found.", e); } @@ -93,9 +93,9 @@ public static List getBuiltInAbbreviations() { return readJournalListFromResource(JOURNALS_FILE_BUILTIN); } - public JournalAbbreviationRepository getRepository(JabRefPreferences jabRefPreferences) { + public JournalAbbreviationRepository getRepository(JournalAbbreviationPreferences journalAbbreviationPreferences) { if (journalAbbrev == null) { - update(jabRefPreferences); + update(journalAbbreviationPreferences); } return journalAbbrev; } diff --git a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java new file mode 100644 index 00000000000..c7b3fa056f0 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java @@ -0,0 +1,46 @@ +package net.sf.jabref.logic.journals; + +import java.nio.charset.Charset; +import java.util.List; + +import net.sf.jabref.JabRefPreferences; + +public class JournalAbbreviationPreferences { + + private final List externalJournalLists; + private final String personalJournalLists; + private final boolean useIEEEAbbreviations; + private final Charset defaultEncoding; + + + public JournalAbbreviationPreferences(List externalJournalLists, String personalJournalLists, + boolean useIEEEAbbreviations, Charset defaultEncoding) { + this.externalJournalLists = externalJournalLists; + this.personalJournalLists = personalJournalLists; + this.useIEEEAbbreviations = useIEEEAbbreviations; + this.defaultEncoding = defaultEncoding; + } + + public static JournalAbbreviationPreferences fromPreferences(JabRefPreferences jabRefPreferences) { + return new JournalAbbreviationPreferences( + jabRefPreferences.getStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS), + jabRefPreferences.get(JabRefPreferences.PERSONAL_JOURNAL_LIST), + jabRefPreferences.getBoolean(JabRefPreferences.USE_IEEE_ABRV), jabRefPreferences.getDefaultEncoding()); + } + + public List getExternalJournalLists() { + return externalJournalLists; + } + + public String getPersonalJournalLists() { + return personalJournalLists; + } + + public boolean isUseIEEEAbbreviations() { + return useIEEEAbbreviations; + } + + public Charset getDefaultEncoding() { + return defaultEncoding; + } +} diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index cabaa3d2131..61364e2ea5a 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -30,6 +30,7 @@ import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.layout.format.AuthorAbbreviator; import net.sf.jabref.logic.layout.format.AuthorAndsCommaReplacer; import net.sf.jabref.logic.layout.format.AuthorAndsReplacer; @@ -513,7 +514,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "Iso690NamesAuthors": return new Iso690NamesAuthors(); case "JournalAbbreviator": - return new JournalAbbreviator(repositoryLoader, prefs); + return new JournalAbbreviator(repositoryLoader, JournalAbbreviationPreferences.fromPreferences(prefs)); case "LastPage": return new LastPage(); case "FormatChars": // For backward compatibility diff --git a/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java b/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java index d21ce1b51d3..d0771933283 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/JournalAbbreviator.java @@ -29,8 +29,8 @@ import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.logic.layout.LayoutFormatter; /** @@ -51,15 +51,18 @@ public class JournalAbbreviator implements LayoutFormatter { private final JournalAbbreviationLoader repostioryLoader; - private final JabRefPreferences jabRefPreferences; + private final JournalAbbreviationPreferences journalAbbreviationPreferences; - public JournalAbbreviator(JournalAbbreviationLoader repostioryLoader, JabRefPreferences jabRefPreferences) { + + public JournalAbbreviator(JournalAbbreviationLoader repostioryLoader, + JournalAbbreviationPreferences journalAbbreviationPreferences) { this.repostioryLoader = Objects.requireNonNull(repostioryLoader); - this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences); + this.journalAbbreviationPreferences = Objects.requireNonNull(journalAbbreviationPreferences); } @Override public String format(String fieldText) { - return repostioryLoader.getRepository(jabRefPreferences).getIsoAbbreviation(fieldText).orElse(fieldText); + return repostioryLoader.getRepository(journalAbbreviationPreferences) + .getIsoAbbreviation(fieldText).orElse(fieldText); } } diff --git a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java index 5c60108e0a4..ee925b1a108 100644 --- a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java +++ b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java @@ -20,12 +20,12 @@ public void setUp() throws Exception { AutoCompletePreferences preferences = mock(AutoCompletePreferences.class); abbreviationLoader = mock(JournalAbbreviationLoader.class); Globals.prefs = JabRefPreferences.getInstance(); - autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader, Globals.prefs); + autoCompleterFactory = new AutoCompleterFactory(preferences, abbreviationLoader); } @Test(expected = NullPointerException.class) public void initFactoryWithNullPreferenceThrowsException() { - new AutoCompleterFactory(null, abbreviationLoader, Globals.prefs); + new AutoCompleterFactory(null, abbreviationLoader); } @Test diff --git a/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java b/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java index c356b81ccf8..008d052afcb 100644 --- a/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java +++ b/src/test/java/net/sf/jabref/logic/journals/AbbreviationsTest.java @@ -29,7 +29,8 @@ public void getNextAbbreviationAbbreviatesIEEEJournalTitle() { when(prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)).thenReturn(true); assertEquals("#IEEE_J_PROC#", - abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proceedings of the IEEE").get()); + abbreviations.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getNextAbbreviation("Proceedings of the IEEE").get()); } @Test @@ -37,24 +38,29 @@ public void getNextAbbreviationExpandsIEEEAbbreviation() { when(prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)).thenReturn(true); assertEquals("Proceedings of the IEEE", - abbreviations.getRepository(Globals.prefs).getNextAbbreviation("#IEEE_J_PROC#").get()); + abbreviations.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getNextAbbreviation("#IEEE_J_PROC#").get()); } @Test public void getNextAbbreviationAbbreviatesJournalTitle() { assertEquals("Proc. IEEE", - abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proceedings of the IEEE").get()); + abbreviations.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getNextAbbreviation("Proceedings of the IEEE").get()); } @Test public void getNextAbbreviationRemovesPoint() { - assertEquals("Proc IEEE", abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proc. IEEE").get()); + assertEquals("Proc IEEE", + abbreviations.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getNextAbbreviation("Proc. IEEE").get()); } @Test public void getNextAbbreviationExpandsAbbreviation() { assertEquals("Proceedings of the IEEE", - abbreviations.getRepository(Globals.prefs).getNextAbbreviation("Proc IEEE").get()); + abbreviations.getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) + .getNextAbbreviation("Proc IEEE").get()); } } From b73afb832882d9799d7621b064bd9a188c3feab6 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 14:57:47 +0200 Subject: [PATCH 13/17] Encapsulated LatexFieldFormatterPreferences in SavePreferences --- .../net/sf/jabref/benchmarks/Benchmarks.java | 6 ++-- .../net/sf/jabref/cli/ArgumentProcessor.java | 5 ++-- .../net/sf/jabref/collab/ChangeScanner.java | 2 +- .../java/net/sf/jabref/gui/BasePanel.java | 2 +- .../gui/actions/ManageKeywordsAction.java | 2 +- .../jabref/gui/exporter/AutoSaveManager.java | 2 +- .../gui/exporter/SaveDatabaseAction.java | 2 +- .../importer/fileformat/BibtexParser.java | 2 +- .../importer/fileformat/JSONEntryParser.java | 2 +- .../importer/fileformat/RepecNepImporter.java | 2 +- .../bibtex/FieldContentParserPreferences.java | 8 ++++- .../LatexFieldFormatterPreferences.java | 8 ++++- .../jabref/logic/cleanup/CleanupWorker.java | 2 +- .../logic/cleanup/RenamePdfCleanup.java | 2 +- .../logic/exporter/BibDatabaseWriter.java | 26 ++++++++++------ .../logic/exporter/BibtexDatabaseWriter.java | 19 ++++++------ .../logic/exporter/SavePreferences.java | 30 +++++++++++++------ .../sf/jabref/logic/groups/AbstractGroup.java | 2 +- .../sf/jabref/logic/groups/ExplicitGroup.java | 2 +- .../sf/jabref/logic/groups/GroupTreeNode.java | 2 +- .../sf/jabref/logic/groups/GroupsParser.java | 2 +- .../JournalAbbreviationPreferences.java | 2 +- .../labelpattern/DatabaseLabelPattern.java | 2 +- .../net/sf/jabref/logic/layout/Layout.java | 2 +- .../sf/jabref/logic/layout/LayoutEntry.java | 2 +- .../sf/jabref/logic/layout/LayoutHelper.java | 2 +- .../jabref/logic/layout/format/FileLink.java | 2 +- .../logic/layout/format/NameFormatter.java | 2 +- .../logic/layout/format/WrapFileLinks.java | 2 +- .../jabref/logic/openoffice/OOBibStyle.java | 2 +- .../jabref/logic/openoffice/StyleLoader.java | 2 +- .../specialfields/SpecialFieldsUtils.java | 2 +- .../AutoCompleterFactoryTest.java | 2 +- .../exporter/BibtexDatabaseWriterTest.java | 2 +- .../jabref/logic/search/SearchQueryTest.java | 2 +- 35 files changed, 93 insertions(+), 65 deletions(-) diff --git a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java index f21f5419c21..59bf3e6758d 100644 --- a/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java @@ -60,8 +60,7 @@ public void init() throws Exception { entry.setField("rnd", "2" + randomizer.nextInt()); database.insertEntry(entry); } - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, - Globals.prefs); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); StringSaveSession saveSession = databaseWriter.savePartOfDatabase( new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences()); @@ -81,8 +80,7 @@ public ParserResult parse() throws IOException { @Benchmark public String write() throws Exception { - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, - Globals.prefs); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); StringSaveSession saveSession = databaseWriter.savePartOfDatabase( new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences()); diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 9d1fe06ee9a..4f61e9976a1 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -288,7 +288,7 @@ private boolean generateAux(List loaded, String[] data) { try { System.out.println(Localization.lang("Saving") + ": " + subName); SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); Defaults defaults = new Defaults(BibDatabaseMode .fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); SaveSession session = databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults), @@ -332,8 +332,7 @@ private void exportFile(List loaded, String[] data) { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs); Defaults defaults = new Defaults(BibDatabaseMode.fromPreference( Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, - Globals.prefs); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); SaveSession session = databaseWriter.saveDatabase( new BibDatabaseContext(pr.getDatabase(), pr.getMetaData(), defaults), prefs); diff --git a/src/main/java/net/sf/jabref/collab/ChangeScanner.java b/src/main/java/net/sf/jabref/collab/ChangeScanner.java index f15942b6551..ab9987a9a42 100644 --- a/src/main/java/net/sf/jabref/collab/ChangeScanner.java +++ b/src/main/java/net/sf/jabref/collab/ChangeScanner.java @@ -167,7 +167,7 @@ private void storeTempDatabase() { Defaults defaults = new Defaults(BibDatabaseMode .fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(inTemp, mdInTemp, defaults), prefs); ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle())); } catch (SaveException ex) { diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 0d37f709f97..8e0f54bfaff 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1105,7 +1105,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(enc) .withSaveType(saveType); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(), prefs); } else { diff --git a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java index cea990ad08f..ab2a817742a 100644 --- a/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/ManageKeywordsAction.java @@ -44,7 +44,6 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefGUI; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.autocompleter.AutoCompleteListener; @@ -55,6 +54,7 @@ import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; import net.sf.jabref.specialfields.Printed; import net.sf.jabref.specialfields.Priority; import net.sf.jabref.specialfields.Quality; diff --git a/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java index 0ca3d1111e5..e1e06b55b0e 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java +++ b/src/main/java/net/sf/jabref/gui/exporter/AutoSaveManager.java @@ -102,7 +102,7 @@ private static boolean autoSave(BasePanel panel) { .withMakeBackup(false) .withEncoding(panel.getBibDatabaseContext().getMetaData().getEncoding()); - BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); + BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); SaveSession ss = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); ss.commit(backupFile.toPath()); } catch (SaveException e) { diff --git a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index 29fdc4f7a2a..a36a6593518 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -173,7 +173,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding); - BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs); + BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs); diff --git a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java index c614bced668..9cfd91af080 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/BibtexParser.java @@ -30,7 +30,6 @@ import java.util.Optional; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.bibtex.FieldContentParser; @@ -45,6 +44,7 @@ import net.sf.jabref.model.entry.FieldProperties; import net.sf.jabref.model.entry.IdGenerator; import net.sf.jabref.model.entry.InternalBibtexFields; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java b/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java index 0d7e276fc46..134501c69f4 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/JSONEntryParser.java @@ -21,9 +21,9 @@ import java.util.List; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.MonthUtil; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java index facee5c8e22..31e7881705e 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/RepecNepImporter.java @@ -33,10 +33,10 @@ import java.util.Objects; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.IdGenerator; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java index 1eafaf80f3f..486d2583340 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParserPreferences.java @@ -1,14 +1,20 @@ package net.sf.jabref.logic.bibtex; +import java.util.Collections; import java.util.List; -import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.preferences.JabRefPreferences; public class FieldContentParserPreferences { private final List nonWrappableFields; + public FieldContentParserPreferences() { + // This constructor is only to allow an empty constructor in SavePreferences + this.nonWrappableFields = Collections.emptyList(); + } + public FieldContentParserPreferences(List nonWrappableFields) { this.nonWrappableFields = nonWrappableFields; } diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java index 6bb2fad073b..8342a18ff08 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatterPreferences.java @@ -1,8 +1,9 @@ package net.sf.jabref.logic.bibtex; +import java.util.Collections; import java.util.List; -import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.preferences.JabRefPreferences; public class LatexFieldFormatterPreferences { @@ -25,6 +26,11 @@ public LatexFieldFormatterPreferences(boolean resolveStringsAllFields, char valu this.fieldContentParserPreferences = fieldContentParserPreferences; } + public LatexFieldFormatterPreferences() { + // This constructor is only to allow an empty constructor in SavePreferences + this(true, '{', '}', Collections.emptyList(), 0, new FieldContentParserPreferences()); + } + public static LatexFieldFormatterPreferences fromPreferences(JabRefPreferences prefs) { return new LatexFieldFormatterPreferences(prefs.getBoolean(JabRefPreferences.RESOLVE_STRINGS_ALL_FIELDS), prefs.getValueDelimiters(0), prefs.getValueDelimiters(1), diff --git a/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java b/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java index 697388170bb..f604eca8c86 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/CleanupWorker.java @@ -20,10 +20,10 @@ import java.util.Objects; import net.sf.jabref.BibDatabaseContext; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; public class CleanupWorker { diff --git a/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java b/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java index e619e938867..db2ebed4080 100644 --- a/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java +++ b/src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java @@ -21,13 +21,13 @@ import java.util.Optional; import net.sf.jabref.BibDatabaseContext; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.TypedBibEntry; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.ParsedFileField; +import net.sf.jabref.preferences.JabRefPreferences; public class RenamePdfCleanup implements CleanupJob { diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java index f8d74d2f606..0561174839b 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibDatabaseWriter.java @@ -34,6 +34,7 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.MetaData; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.bibtex.comparator.BibtexStringComparator; import net.sf.jabref.logic.bibtex.comparator.CrossRefEntryComparator; import net.sf.jabref.logic.bibtex.comparator.FieldComparator; @@ -178,7 +179,8 @@ public E savePartOfDatabase(BibDatabaseContext bibDatabaseContext, writePreamble(bibDatabaseContext.getDatabase().getPreamble()); // Write strings if there are any. - writeStrings(bibDatabaseContext.getDatabase(), preferences.isReformatFile()); + writeStrings(bibDatabaseContext.getDatabase(), preferences.isReformatFile(), + preferences.getLatexFieldFormatterPreferences()); // Write database entries. List sortedEntries = getSortedEntries(bibDatabaseContext, entries, preferences); @@ -196,7 +198,8 @@ public E savePartOfDatabase(BibDatabaseContext bibDatabaseContext, entryType -> typesToWrite.put(entryType.getName(), entryType)); } - writeEntry(entry, bibDatabaseContext.getMode(), preferences.isReformatFile()); + writeEntry(entry, bibDatabaseContext.getMode(), preferences.isReformatFile(), + preferences.getLatexFieldFormatterPreferences()); } if (preferences.getSaveType() != SavePreferences.DatabaseSaveType.PLAIN_BIBTEX) { @@ -220,7 +223,8 @@ public E savePartOfDatabase(BibDatabaseContext bibDatabaseContext, protected abstract void writePrelogue(BibDatabaseContext bibDatabaseContext, Charset encoding) throws SaveException; - protected abstract void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile) throws SaveException; + protected abstract void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile, + LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException; protected abstract void writeEpilogue(String epilogue) throws SaveException; @@ -247,7 +251,8 @@ protected void writeMetaData(MetaData metaData) throws SaveException { * * @param database The database whose strings we should write. */ - private void writeStrings(BibDatabase database, Boolean reformatFile) throws SaveException { + private void writeStrings(BibDatabase database, Boolean reformatFile, + LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException { List strings = database.getStringKeySet().stream().map(database::getString).collect( Collectors.toList()); strings.sort(new BibtexStringComparator(true)); @@ -263,7 +268,8 @@ private void writeStrings(BibDatabase database, Boolean reformatFile) throws Sav boolean isFirstStringInType = true; for (BibtexString bs : strings) { if (remaining.containsKey(bs.getName()) && (bs.getType() == t)) { - writeString(bs, isFirstStringInType, remaining, maxKeyLength, reformatFile); + writeString(bs, isFirstStringInType, remaining, maxKeyLength, reformatFile, + latexFieldFormatterPreferences); isFirstStringInType = false; } } @@ -271,7 +277,7 @@ private void writeStrings(BibDatabase database, Boolean reformatFile) throws Sav } protected void writeString(BibtexString bibtexString, boolean isFirstString, Map remaining, int maxKeyLength, - Boolean reformatFile) + Boolean reformatFile, LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException { // First remove this from the "remaining" list so it can't cause problem with circular refs: remaining.remove(bibtexString.getName()); @@ -290,14 +296,16 @@ protected void writeString(BibtexString bibtexString, boolean isFirstString, Map // If the label we found exists as a key in the "remaining" Map, we go on and write it now: if (remaining.containsKey(label)) { BibtexString referred = remaining.get(label); - writeString(referred, isFirstString, remaining, maxKeyLength, reformatFile); + writeString(referred, isFirstString, remaining, maxKeyLength, reformatFile, + latexFieldFormatterPreferences); } } - writeString(bibtexString, isFirstString, maxKeyLength, reformatFile); + writeString(bibtexString, isFirstString, maxKeyLength, reformatFile, latexFieldFormatterPreferences); } - protected abstract void writeString(BibtexString bibtexString, boolean isFirstString, int maxKeyLength, Boolean reformatFile) + protected abstract void writeString(BibtexString bibtexString, boolean isFirstString, int maxKeyLength, + Boolean reformatFile, LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException; protected void writeEntryTypeDefinitions(Map types) throws SaveException { diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index 197d7e04880..ebf9098d8e6 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -22,7 +22,6 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.MetaData; import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; @@ -39,10 +38,9 @@ public class BibtexDatabaseWriter extends BibDatabaseWrit private static final String COMMENT_PREFIX = "@Comment"; private static final String PREAMBLE_PREFIX = "@Preamble"; - private final JabRefPreferences jabRefPreferences; - public BibtexDatabaseWriter(SaveSessionFactory saveSessionFactory, JabRefPreferences jabRefPreferences) { + + public BibtexDatabaseWriter(SaveSessionFactory saveSessionFactory) { super(saveSessionFactory); - this.jabRefPreferences = jabRefPreferences; } @Override @@ -89,9 +87,10 @@ protected void writePreamble(String preamble) throws SaveException { } @Override - protected void writeString(BibtexString bibtexString, boolean isFirstString, int maxKeyLength, Boolean reformatFile) throws SaveException { + protected void writeString(BibtexString bibtexString, boolean isFirstString, int maxKeyLength, Boolean reformatFile, + LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException { try { - // If the string has not been modified, write it back as it was + // If the string has not been modified, write it back as it wass if (!reformatFile && !bibtexString.hasChanged()) { getWriter().write(bibtexString.getParsedSerialization()); return; @@ -113,8 +112,7 @@ protected void writeString(BibtexString bibtexString, boolean isFirstString, int getWriter().write("{}"); } else { try { - String formatted = new LatexFieldFormatter( - LatexFieldFormatterPreferences.fromPreferences(jabRefPreferences)) + String formatted = new LatexFieldFormatter(latexFieldFormatterPreferences) .format(bibtexString.getContent(), LatexFieldFormatter.BIBTEX_STRING); getWriter().write(formatted); @@ -160,9 +158,10 @@ protected void writePrelogue(BibDatabaseContext bibDatabaseContext, Charset enco } @Override - protected void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile) throws SaveException { + protected void writeEntry(BibEntry entry, BibDatabaseMode mode, Boolean isReformatFile, + LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException { BibEntryWriter bibtexEntryWriter = new BibEntryWriter( - new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(jabRefPreferences)), true); + new LatexFieldFormatter(latexFieldFormatterPreferences), true); try { bibtexEntryWriter.write(entry, getWriter(), mode, isReformatFile); } catch (IOException e) { diff --git a/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java index 23ffe25e3dd..06fb6091429 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java +++ b/src/main/java/net/sf/jabref/logic/exporter/SavePreferences.java @@ -2,6 +2,7 @@ import java.nio.charset.Charset; +import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.config.SaveOrderConfig; import net.sf.jabref.preferences.JabRefPreferences; @@ -14,13 +15,15 @@ public class SavePreferences { private final boolean makeBackup; private final DatabaseSaveType saveType; private final boolean takeMetadataSaveOrderInAccount; + private final LatexFieldFormatterPreferences latexFieldFormatterPreferences; public SavePreferences() { - this(true, null, null, false, DatabaseSaveType.ALL, true, false); + this(true, null, null, false, DatabaseSaveType.ALL, true, false, new LatexFieldFormatterPreferences()); } public SavePreferences(Boolean saveInOriginalOrder, SaveOrderConfig saveOrder, Charset encoding, Boolean makeBackup, - DatabaseSaveType saveType, Boolean takeMetadataSaveOrderInAccount, Boolean reformatFile) { + DatabaseSaveType saveType, Boolean takeMetadataSaveOrderInAccount, Boolean reformatFile, + LatexFieldFormatterPreferences latexFieldFormatterPreferences) { this.saveInOriginalOrder = saveInOriginalOrder; this.saveOrder = saveOrder; this.encoding = encoding; @@ -28,6 +31,7 @@ public SavePreferences(Boolean saveInOriginalOrder, SaveOrderConfig saveOrder, C this.saveType = saveType; this.takeMetadataSaveOrderInAccount = takeMetadataSaveOrderInAccount; this.reformatFile = reformatFile; + this.latexFieldFormatterPreferences = latexFieldFormatterPreferences; } public static SavePreferences loadForExportFromPreferences(JabRefPreferences preferences) { @@ -45,8 +49,10 @@ public static SavePreferences loadForExportFromPreferences(JabRefPreferences pre DatabaseSaveType saveType = DatabaseSaveType.ALL; Boolean takeMetadataSaveOrderInAccount = false; Boolean reformatFile = preferences.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT); + LatexFieldFormatterPreferences latexFieldFormatterPreferences = LatexFieldFormatterPreferences + .fromPreferences(preferences); return new SavePreferences(saveInOriginalOrder, saveOrder, encoding, makeBackup, saveType, - takeMetadataSaveOrderInAccount, reformatFile); + takeMetadataSaveOrderInAccount, reformatFile, latexFieldFormatterPreferences); } public static SavePreferences loadForSaveFromPreferences(JabRefPreferences preferences) { @@ -57,8 +63,10 @@ public static SavePreferences loadForSaveFromPreferences(JabRefPreferences prefe DatabaseSaveType saveType = DatabaseSaveType.ALL; Boolean takeMetadataSaveOrderInAccount = true; Boolean reformatFile = preferences.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT); + LatexFieldFormatterPreferences latexFieldFormatterPreferences = LatexFieldFormatterPreferences + .fromPreferences(preferences); return new SavePreferences(saveInOriginalOrder, saveOrder, encoding, makeBackup, saveType, - takeMetadataSaveOrderInAccount, reformatFile); + takeMetadataSaveOrderInAccount, reformatFile, latexFieldFormatterPreferences); } public Boolean getTakeMetadataSaveOrderInAccount() { @@ -75,7 +83,7 @@ public boolean isSaveInOriginalOrder() { public SavePreferences withSaveInOriginalOrder(Boolean saveInOriginalOrder) { return new SavePreferences(saveInOriginalOrder, this.saveOrder, this.encoding, this.makeBackup, this.saveType, - this.takeMetadataSaveOrderInAccount, this.reformatFile); + this.takeMetadataSaveOrderInAccount, this.reformatFile, this.latexFieldFormatterPreferences); } public boolean getMakeBackup() { @@ -84,7 +92,7 @@ public boolean getMakeBackup() { public SavePreferences withMakeBackup(Boolean makeBackup) { return new SavePreferences(this.saveInOriginalOrder, this.saveOrder, this.encoding, makeBackup, this.saveType, - this.takeMetadataSaveOrderInAccount, this.reformatFile); + this.takeMetadataSaveOrderInAccount, this.reformatFile, this.latexFieldFormatterPreferences); } public Charset getEncoding() { @@ -93,7 +101,7 @@ public Charset getEncoding() { public SavePreferences withEncoding(Charset encoding) { return new SavePreferences(this.saveInOriginalOrder, this.saveOrder, encoding, this.makeBackup, this.saveType, - this.takeMetadataSaveOrderInAccount, this.reformatFile); + this.takeMetadataSaveOrderInAccount, this.reformatFile, this.latexFieldFormatterPreferences); } public DatabaseSaveType getSaveType() { @@ -102,7 +110,7 @@ public DatabaseSaveType getSaveType() { public SavePreferences withSaveType(DatabaseSaveType saveType) { return new SavePreferences(this.saveInOriginalOrder, this.saveOrder, this.encoding, this.makeBackup, saveType, - this.takeMetadataSaveOrderInAccount, this.reformatFile); + this.takeMetadataSaveOrderInAccount, this.reformatFile, this.latexFieldFormatterPreferences); } public Boolean isReformatFile() { @@ -111,13 +119,17 @@ public Boolean isReformatFile() { public SavePreferences withReformatFile(boolean reformatFile) { return new SavePreferences(this.saveInOriginalOrder, this.saveOrder, this.encoding, this.makeBackup, - this.saveType, this.takeMetadataSaveOrderInAccount, reformatFile); + this.saveType, this.takeMetadataSaveOrderInAccount, reformatFile, this.latexFieldFormatterPreferences); } public Charset getEncodingOrDefault() { return encoding == null ? Charset.defaultCharset() : encoding; } + public LatexFieldFormatterPreferences getLatexFieldFormatterPreferences() { + return latexFieldFormatterPreferences; + } + public enum DatabaseSaveType { ALL, PLAIN_BIBTEX diff --git a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java index fa67145e0e2..6759bd6c38c 100644 --- a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java @@ -19,11 +19,11 @@ import java.util.List; import java.util.Optional; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.search.SearchMatcher; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; /** * A group of BibtexEntries. diff --git a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java index 6c796ead849..bafb1c33e5c 100644 --- a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java @@ -21,11 +21,11 @@ import java.util.Set; import java.util.TreeSet; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; import net.sf.jabref.logic.util.strings.StringUtil; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java index 7a5e60c3ea5..7ef67103cc5 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupTreeNode.java @@ -21,13 +21,13 @@ import java.util.Optional; import java.util.stream.Collectors; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.search.SearchMatcher; import net.sf.jabref.logic.search.matchers.MatcherSet; import net.sf.jabref.logic.search.matchers.MatcherSets; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; /** * A node in the groups tree that holds exactly one AbstractGroup. diff --git a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java index c54c347f5ac..6d73a378a2a 100644 --- a/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java +++ b/src/main/java/net/sf/jabref/logic/groups/GroupsParser.java @@ -19,9 +19,9 @@ import java.util.List; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.importer.fileformat.ParseException; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.preferences.JabRefPreferences; /** * Converts string representation of groups to a parsed {@link GroupTreeNode}. diff --git a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java index c7b3fa056f0..3ba35a8b3b2 100644 --- a/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java +++ b/src/main/java/net/sf/jabref/logic/journals/JournalAbbreviationPreferences.java @@ -3,7 +3,7 @@ import java.nio.charset.Charset; import java.util.List; -import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.preferences.JabRefPreferences; public class JournalAbbreviationPreferences { diff --git a/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java b/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java index c341a6fabd4..4c3836e9e49 100644 --- a/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java +++ b/src/main/java/net/sf/jabref/logic/labelpattern/DatabaseLabelPattern.java @@ -17,7 +17,7 @@ import java.util.List; -import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.preferences.JabRefPreferences; public class DatabaseLabelPattern extends AbstractLabelPattern { diff --git a/src/main/java/net/sf/jabref/logic/layout/Layout.java b/src/main/java/net/sf/jabref/logic/layout/Layout.java index 94a1c305df8..7093d8a311a 100644 --- a/src/main/java/net/sf/jabref/logic/layout/Layout.java +++ b/src/main/java/net/sf/jabref/logic/layout/Layout.java @@ -22,10 +22,10 @@ import java.util.regex.Pattern; import net.sf.jabref.BibDatabaseContext; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java index 61364e2ea5a..b434b69a7da 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -26,7 +26,6 @@ import java.util.regex.Pattern; import net.sf.jabref.BibDatabaseContext; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; @@ -96,6 +95,7 @@ import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java b/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java index e18712bb628..3dfe088d6a3 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java @@ -22,8 +22,8 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.preferences.JabRefPreferences; /** * Helper class to get a Layout object. diff --git a/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java b/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java index 6e57c72445e..dc9b55a108c 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/FileLink.java @@ -22,11 +22,11 @@ import java.util.Optional; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.layout.ParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.entry.FileField; import net.sf.jabref.model.entry.ParsedFileField; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java index b1bfd534ab3..1cc455bf7e1 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatter.java @@ -19,10 +19,10 @@ import java.util.List; import java.util.Map; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.bst.BibtexNameFormatter; import net.sf.jabref.logic.layout.LayoutFormatter; import net.sf.jabref.model.entry.AuthorList; +import net.sf.jabref.preferences.JabRefPreferences; /** * This layout formatter uses the Bibtex name.format$ method and provides ultimate flexibility: diff --git a/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java b/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java index bdbf9651443..9920e60a55a 100644 --- a/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java +++ b/src/main/java/net/sf/jabref/logic/layout/format/WrapFileLinks.java @@ -25,11 +25,11 @@ import java.util.Optional; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.layout.AbstractParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.model.entry.FileField; import net.sf.jabref.model.entry.ParsedFileField; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java index 0a6ca84726e..ff6a1255e3f 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java @@ -36,7 +36,6 @@ import java.util.TreeSet; import java.util.regex.Pattern; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatter; @@ -46,6 +45,7 @@ import net.sf.jabref.model.entry.Author; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java b/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java index 66fbd0c4e14..1d0d1f5761a 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/StyleLoader.java @@ -24,8 +24,8 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java index d086cd3caac..940cd3302b1 100644 --- a/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java +++ b/src/main/java/net/sf/jabref/specialfields/SpecialFieldsUtils.java @@ -21,13 +21,13 @@ import java.util.Set; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.undo.UndoableFieldChange; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.EntryUtil; +import net.sf.jabref.preferences.JabRefPreferences; import static net.sf.jabref.model.entry.BibEntry.KEYWORDS_FIELD; diff --git a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java index ee925b1a108..61b9c6080f0 100644 --- a/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java +++ b/src/test/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactoryTest.java @@ -1,8 +1,8 @@ package net.sf.jabref.logic.autocompleter; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Assert; import org.junit.Before; diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 120e54af36f..807b51c71b9 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -52,7 +52,7 @@ public void setUp() { Globals.prefs = JabRefPreferences.getInstance(); // Write to a string instead of to a file - databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new, Globals.prefs); + databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); database = new BibDatabase(); metaData = new MetaData(); diff --git a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java index 00ff9288c34..16550db3198 100644 --- a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java +++ b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java @@ -1,8 +1,8 @@ package net.sf.jabref.logic.search; import net.sf.jabref.Globals; -import net.sf.jabref.JabRefPreferences; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Test; From d03326a18488be94d7ecd22e2bc75f7107d20863 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Mon, 18 Jul 2016 15:08:18 +0200 Subject: [PATCH 14/17] Changed getShortDescription to accept boolean argument --- .../net/sf/jabref/gui/groups/GroupDialog.java | 2 +- .../jabref/gui/groups/GroupTreeNodeViewModel.java | 6 ++++-- .../logic/autocompleter/AutoCompleterFactory.java | 1 - .../net/sf/jabref/logic/groups/AbstractGroup.java | 4 ++-- .../sf/jabref/logic/groups/AllEntriesGroup.java | 2 +- .../net/sf/jabref/logic/groups/ExplicitGroup.java | 2 +- .../net/sf/jabref/logic/groups/KeywordGroup.java | 4 ++-- .../net/sf/jabref/logic/groups/SearchGroup.java | 15 ++++++--------- .../sf/jabref/sql/importer/DatabaseImporter.java | 2 +- .../sf/jabref/logic/groups/GroupTreeNodeTest.java | 5 ++--- .../sf/jabref/logic/groups/SearchGroupTest.java | 6 +++--- 11 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java index 2acb30890e4..18932a7d4b3 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupDialog.java @@ -293,7 +293,7 @@ public void actionPerformed(ActionEvent e) { // disabled // therefore I don't catch anything here resultingGroup = new SearchGroup(nameField.getText().trim(), searchGroupSearchExpression.getText().trim(), - isCaseSensitive(), isRegex(), getContext(), Globals.prefs); + isCaseSensitive(), isRegex(), getContext()); } catch (Exception e1) { // should never happen } diff --git a/src/main/java/net/sf/jabref/gui/groups/GroupTreeNodeViewModel.java b/src/main/java/net/sf/jabref/gui/groups/GroupTreeNodeViewModel.java index 1d2706592ee..99d2e65b886 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupTreeNodeViewModel.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupTreeNodeViewModel.java @@ -191,7 +191,7 @@ public String getText() { sb.append(group.getName()); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS) - && JabRefGUI.getMainFrame() != null) { + && (JabRefGUI.getMainFrame() != null)) { BasePanel currentBasePanel = JabRefGUI.getMainFrame().getCurrentBasePanel(); if (currentBasePanel != null) { sb.append(" [").append(node.numberOfHits(currentBasePanel.getDatabase().getEntries())).append(']'); @@ -202,7 +202,9 @@ public String getText() { } public String getDescription() { - return "" + node.getGroup().getShortDescription() + ""; + return "" + + node.getGroup().getShortDescription(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) + + ""; } public Icon getIcon() { diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java index f0f2d2a1b3d..1089cc36eee 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompleterFactory.java @@ -19,7 +19,6 @@ import java.util.Objects; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; -import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; import net.sf.jabref.model.entry.FieldProperties; import net.sf.jabref.model.entry.InternalBibtexFields; diff --git a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java index 6759bd6c38c..dd2812a434e 100644 --- a/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/AbstractGroup.java @@ -71,7 +71,7 @@ public static AbstractGroup fromString(String s, JabRefPreferences jabRefPrefere return AllEntriesGroup.fromString(s); } if (s.startsWith(SearchGroup.ID)) { - return SearchGroup.fromString(s, jabRefPreferences); + return SearchGroup.fromString(s); } if (s.startsWith(ExplicitGroup.ID)) { return ExplicitGroup.fromString(s, jabRefPreferences); @@ -209,7 +209,7 @@ public void setHierarchicalContext(GroupHierarchyType context) { /** * Returns a short description of the group in HTML (for a tooltip). */ - public abstract String getShortDescription(); + public abstract String getShortDescription(boolean showDynamic); // by general AbstractGroup contract, toString() must return // something from which this object can be reconstructed diff --git a/src/main/java/net/sf/jabref/logic/groups/AllEntriesGroup.java b/src/main/java/net/sf/jabref/logic/groups/AllEntriesGroup.java index f4b72ab3b72..c4e45ab03aa 100644 --- a/src/main/java/net/sf/jabref/logic/groups/AllEntriesGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/AllEntriesGroup.java @@ -94,7 +94,7 @@ public String getDescription() { } @Override - public String getShortDescription() { + public String getShortDescription(boolean showDynamic) { return Localization.lang("All Entries (this group cannot be edited or removed)"); } diff --git a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java index bafb1c33e5c..fb0d9b67010 100644 --- a/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/ExplicitGroup.java @@ -145,7 +145,7 @@ public static String getDescriptionForPreview() { } @Override - public String getShortDescription() { + public String getShortDescription(boolean showDynamic) { StringBuilder sb = new StringBuilder(); sb.append("").append(getName()).append(" -").append(Localization.lang("static group")); switch (getHierarchicalContext()) { diff --git a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java index 679f51c29ca..3d1abdf3334 100644 --- a/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/KeywordGroup.java @@ -368,10 +368,10 @@ public static String getDescriptionForPreview(String field, String expr, boolean } @Override - public String getShortDescription() { + public String getShortDescription(boolean showDynamic) { StringBuilder sb = new StringBuilder(); sb.append(""); - if (jabRefPreferences.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { + if (showDynamic) { sb.append("").append(StringUtil.quoteForHTML(getName())).append(""); } else { sb.append(StringUtil.quoteForHTML(getName())); diff --git a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java index 4c8cbe141d4..298ef24e230 100644 --- a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java @@ -41,17 +41,14 @@ public class SearchGroup extends AbstractGroup { private static final Log LOGGER = LogFactory.getLog(SearchGroup.class); - private final JabRefPreferences jabRefPreferences; - /** * Creates a SearchGroup with the specified properties. */ public SearchGroup(String name, String searchExpression, boolean caseSensitive, boolean regExp, - GroupHierarchyType context, JabRefPreferences jabRefPreferences) { + GroupHierarchyType context) { super(name, context); this.query = new SearchQuery(searchExpression, caseSensitive, regExp); - this.jabRefPreferences = jabRefPreferences; } /** @@ -60,7 +57,7 @@ public SearchGroup(String name, String searchExpression, boolean caseSensitive, * @param s The String representation obtained from * SearchGroup.toString(), or null if incompatible */ - public static AbstractGroup fromString(String s, JabRefPreferences jabRefPreferences) { + public static AbstractGroup fromString(String s) { if (!s.startsWith(SearchGroup.ID)) { throw new IllegalArgumentException("SearchGroup cannot be created from \"" + s + "\"."); } @@ -76,7 +73,7 @@ public static AbstractGroup fromString(String s, JabRefPreferences jabRefPrefere // fields; these are ignored now, all fields are always searched return new SearchGroup(StringUtil.unquote(name, AbstractGroup.QUOTE_CHAR), StringUtil.unquote(expression, AbstractGroup.QUOTE_CHAR), caseSensitive, regExp, - GroupHierarchyType.getByNumber(context), jabRefPreferences); + GroupHierarchyType.getByNumber(context)); } @Override @@ -143,7 +140,7 @@ public boolean contains(BibEntry entry) { public AbstractGroup deepCopy() { try { return new SearchGroup(getName(), getSearchExpression(), isCaseSensitive(), - isRegExp(), getHierarchicalContext(), jabRefPreferences); + isRegExp(), getHierarchicalContext()); } catch (Throwable t) { // this should never happen, because the constructor obviously // succeeded in creating _this_ instance! @@ -172,10 +169,10 @@ public String getDescription() { } @Override - public String getShortDescription() { + public String getShortDescription(boolean showDynamic) { StringBuilder sb = new StringBuilder(); sb.append(""); - if (jabRefPreferences.getBoolean(JabRefPreferences.GROUP_SHOW_DYNAMIC)) { + if (showDynamic) { sb.append("").append(StringUtil.quoteForHTML(getName())).append(""); } else { sb.append(StringUtil.quoteForHTML(getName())); diff --git a/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java b/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java index b01ab845d1d..036d6778eb6 100644 --- a/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java +++ b/src/main/java/net/sf/jabref/sql/importer/DatabaseImporter.java @@ -244,7 +244,7 @@ private void importGroupsTree(MetaData metaData, Map entries, group = new SearchGroup(rsGroups.getString("label"), StringUtil.unquote(rsGroups.getString("search_expression"), '\\'), rsGroups.getBoolean("case_sensitive"), rsGroups.getBoolean("reg_exp"), - GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context")), Globals.prefs); + GroupHierarchyType.getByNumber(rsGroups.getInt("hierarchical_context"))); break; default: break; diff --git a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java index 87a8f81b160..a357b0598f2 100644 --- a/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/GroupTreeNodeTest.java @@ -100,7 +100,7 @@ private AbstractGroup getKeywordGroup(String name) throws ParseException { } private AbstractGroup getSearchGroup(String name) { - return new SearchGroup(name, "searchExpression", true, false, GroupHierarchyType.INCLUDING, Globals.prefs); + return new SearchGroup(name, "searchExpression", true, false, GroupHierarchyType.INCLUDING); } private AbstractGroup getExplict(String name) throws ParseException { @@ -302,8 +302,7 @@ public void setGroupExplicitToSearchDoesNotKeepPreviousAssignments() throws Exce AbstractGroup oldGroup = new ExplicitGroup("OldGroup", GroupHierarchyType.INDEPENDENT, Globals.prefs); oldGroup.add(entry); GroupTreeNode node = GroupTreeNode.fromGroup(oldGroup); - AbstractGroup newGroup = new SearchGroup("NewGroup", "test", false, false, GroupHierarchyType.INDEPENDENT, - Globals.prefs); + AbstractGroup newGroup = new SearchGroup("NewGroup", "test", false, false, GroupHierarchyType.INDEPENDENT); node.setGroup(newGroup, true, entries); diff --git a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java index 5203b51778b..c9648ac2bc2 100644 --- a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java @@ -21,7 +21,7 @@ public static void setUp() { @Test public void testContains() { SearchGroup group = new SearchGroup("myExplicitGroup", "review", - true, true, GroupHierarchyType.INDEPENDENT, Globals.prefs); + true, true, GroupHierarchyType.INDEPENDENT); assertEquals("SearchGroup:myExplicitGroup;0;review;1;1;", group.toString()); BibEntry entry = new BibEntry(); @@ -34,14 +34,14 @@ public void testContains() { @Test public void testToStringSimple() { SearchGroup group = new SearchGroup("myExplicitGroup", "author=harrer", - true, true, GroupHierarchyType.INDEPENDENT, Globals.prefs); + true, true, GroupHierarchyType.INDEPENDENT); assertEquals("SearchGroup:myExplicitGroup;0;author=harrer;1;1;", group.toString()); } @Test public void testToStringComplex() { SearchGroup group = new SearchGroup("myExplicitGroup", "author=\"harrer\"", true, false, - GroupHierarchyType.INCLUDING, Globals.prefs); + GroupHierarchyType.INCLUDING); assertEquals("SearchGroup:myExplicitGroup;2;author=\"harrer\";1;0;", group.toString()); } From 9b75beef661000c76cc6b22bed4910332dac55a2 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 20 Jul 2016 09:23:10 +0200 Subject: [PATCH 15/17] Removed Globals.prefs from tests and removed unused imports --- .../AutoCompletePreferences.java | 2 +- .../logic/bibtex/FieldContentParser.java | 1 - .../sf/jabref/logic/groups/SearchGroup.java | 1 - .../jabref/logic/groups/SearchGroupTest.java | 2 +- .../jabref/logic/search/SearchQueryTest.java | 2 +- .../sf/jabref/model/entry/BibEntryTests.java | 46 +++++++++---------- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java index ced72ddbb8b..5c1891e5bf3 100644 --- a/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java +++ b/src/main/java/net/sf/jabref/logic/autocompleter/AutoCompletePreferences.java @@ -19,8 +19,8 @@ import java.util.Map; import java.util.Objects; -import net.sf.jabref.preferences.JabRefPreferences; import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; +import net.sf.jabref.preferences.JabRefPreferences; public class AutoCompletePreferences { diff --git a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java index 2deedeba503..a363afc295f 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/FieldContentParser.java @@ -19,7 +19,6 @@ import java.util.regex.Pattern; import net.sf.jabref.logic.util.strings.StringUtil; -import net.sf.jabref.preferences.JabRefPreferences; /** * This class provides the reformatting needed when reading BibTeX fields formatted diff --git a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java index 298ef24e230..e2ded390473 100644 --- a/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java +++ b/src/main/java/net/sf/jabref/logic/groups/SearchGroup.java @@ -23,7 +23,6 @@ import net.sf.jabref.logic.util.strings.QuotedStringTokenizer; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java index c9648ac2bc2..1521c48811f 100644 --- a/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java +++ b/src/test/java/net/sf/jabref/logic/groups/SearchGroupTest.java @@ -27,7 +27,7 @@ public void testContains() { BibEntry entry = new BibEntry(); assertFalse(group.contains(entry)); - entry.addKeyword("review", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + entry.addKeyword("review", ", "); assertTrue(group.contains(entry)); } diff --git a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java index 16550db3198..57508c1048f 100644 --- a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java +++ b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java @@ -35,7 +35,7 @@ public void testIsGrammarBasedSearch() { @Test public void testGrammarSearch() { BibEntry entry = new BibEntry(); - entry.addKeyword("one two", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + entry.addKeyword("one two", ", "); SearchQuery searchQuery = new SearchQuery("keywords=\"one two\"", false, false); assertTrue(searchQuery.isMatch(entry)); } diff --git a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java index d92b0d018e2..0d0d40cfa79 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/net/sf/jabref/model/entry/BibEntryTests.java @@ -212,13 +212,13 @@ public void setNullField() { @Test(expected = NullPointerException.class) public void addNullKeywordThrowsNPE() { - keywordEntry.addKeyword(null, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword(null, ", "); Assert.fail(); } @Test(expected = NullPointerException.class) public void putNullKeywordListThrowsNPE() { - keywordEntry.putKeywords(null, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.putKeywords(null, ", "); Assert.fail(); } @@ -235,48 +235,48 @@ public void testGetSeparatedKeywordsAreCorrect() { @Test public void testAddKeywordIsCorrect() { - keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FooBar", ", "); String[] expected = {"Foo", "Bar", "FooBar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordHasChanged() { - keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FooBar", ", "); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testAddKeywordTwiceYiedsOnlyOne() { - keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); - keywordEntry.addKeyword("FooBar", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FooBar", ", "); + keywordEntry.addKeyword("FooBar", ", "); String[] expected = {"Foo", "Bar", "FooBar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void addKeywordIsCaseSensitive() { - keywordEntry.addKeyword("FOO", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FOO", ", "); String[] expected = {"Foo", "Bar", "FOO"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordWithDifferentCapitalizationChanges() { - keywordEntry.addKeyword("FOO", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("FOO", ", "); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testAddKeywordEmptyKeywordIsNotAdded() { - keywordEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("", ", "); String[] expected = {"Foo", "Bar"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testAddKeywordEmptyKeywordNotChanged() { - keywordEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.addKeyword("", ", "); Assert.assertFalse(keywordEntry.hasChanged()); } @@ -287,85 +287,85 @@ public void texNewBibEntryHasNoKeywords() { @Test public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { - emptyEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + emptyEntry.addKeyword("", ", "); Assert.assertTrue(emptyEntry.getKeywords().isEmpty()); } @Test public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { - emptyEntry.addKeyword("", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + emptyEntry.addKeyword("", ", "); Assert.assertFalse(emptyEntry.hasChanged()); } @Test public void testAddKeywordsWorksAsExpected() { String[] expected = {"Foo", "Bar"}; - emptyEntry.addKeywords(keywordEntry.getKeywords(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + emptyEntry.addKeywords(keywordEntry.getKeywords(), ", "); Assert.assertArrayEquals(expected, emptyEntry.getKeywords().toArray()); } @Test public void testPutKeywordsOverwritesOldKeywords() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ", "); String[] expected = {"Yin", "Yang"}; Assert.assertArrayEquals(expected, keywordEntry.getKeywords().toArray()); } @Test public void testPutKeywordsHasChanged() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ", "); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { - keywordEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.putKeywords(Collections.emptyList(), ", "); Assert.assertTrue(keywordEntry.getKeywords().isEmpty()); } @Test public void testPutKeywordsPutEmpyListHasChanged() { - keywordEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + keywordEntry.putKeywords(Collections.emptyList(), ", "); Assert.assertTrue(keywordEntry.hasChanged()); } @Test public void testPutKeywordsPutEmpyListToEmptyBibentry() { - emptyEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + emptyEntry.putKeywords(Collections.emptyList(), ", "); Assert.assertTrue(emptyEntry.getKeywords().isEmpty()); } @Test public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { - emptyEntry.putKeywords(Collections.emptyList(), Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + emptyEntry.putKeywords(Collections.emptyList(), ", "); Assert.assertFalse(emptyEntry.hasChanged()); } @Test public void putKeywordsToEmptyReturnsNoChange() { Optional change = emptyEntry.putKeywords(Collections.emptyList(), - Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + ", "); Assert.assertEquals(Optional.empty(), change); } @Test public void clearKeywordsReturnsChange() { Optional change = keywordEntry.putKeywords(Collections.emptyList(), - Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + ", "); Assert.assertEquals(Optional.of(new FieldChange(keywordEntry, "keywords", "Foo, Bar", null)), change); } @Test public void changeKeywordsReturnsChange() { Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest"), - Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + ", "); Assert.assertEquals(Optional.of(new FieldChange(keywordEntry, "keywords", "Foo, Bar", "Test, FooTest")), change); } @Test public void putKeywordsToSameReturnsNoChange() { Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar"), - Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); + ", "); Assert.assertEquals(Optional.empty(), change); } From a92e658fb04cbe2797cfa9c6dbb98a78ce476b4a Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 20 Jul 2016 09:27:46 +0200 Subject: [PATCH 16/17] Unused import --- .../java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java index 6dfee365111..95e4e49b89d 100644 --- a/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/net/sf/jabref/logic/bibtex/LatexFieldFormatter.java @@ -21,7 +21,6 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.entry.InternalBibtexFields; -import net.sf.jabref.preferences.JabRefPreferences; /** * Currently the only implementation of net.sf.jabref.exporter.FieldFormatter From b2a437c4bc0dd913e51ebca4d117b2a2abe2c554 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 20 Jul 2016 09:33:08 +0200 Subject: [PATCH 17/17] Unused import --- .../java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java | 2 +- src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java index ebf9098d8e6..173a0c8ae9d 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -90,7 +90,7 @@ protected void writePreamble(String preamble) throws SaveException { protected void writeString(BibtexString bibtexString, boolean isFirstString, int maxKeyLength, Boolean reformatFile, LatexFieldFormatterPreferences latexFieldFormatterPreferences) throws SaveException { try { - // If the string has not been modified, write it back as it wass + // If the string has not been modified, write it back as it was if (!reformatFile && !bibtexString.hasChanged()) { getWriter().write(bibtexString.getParsedSerialization()); return; diff --git a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java index 57508c1048f..930b22697f4 100644 --- a/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java +++ b/src/test/java/net/sf/jabref/logic/search/SearchQueryTest.java @@ -1,8 +1,6 @@ package net.sf.jabref.logic.search; -import net.sf.jabref.Globals; import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Test;