diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 9e8e4c8839a..75e4616323e 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -117,6 +117,7 @@ import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.labelpattern.LabelPatternUtil; import net.sf.jabref.logic.layout.Layout; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.logic.util.io.FileBasedLock; @@ -991,7 +992,9 @@ private void copyKeyAndTitle() { "\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); Layout layout; try { - layout = new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText(); + layout = new LayoutHelper(sr, + LayoutFormatterPreferences.fromPreferences(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 768e76d86f8..3e6caaa9060 100644 --- a/src/main/java/net/sf/jabref/gui/PreviewPanel.java +++ b/src/main/java/net/sf/jabref/gui/PreviewPanel.java @@ -55,6 +55,7 @@ import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.layout.Layout; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; import net.sf.jabref.logic.search.SearchQueryHighlightListener; import net.sf.jabref.model.entry.BibEntry; @@ -263,7 +264,8 @@ private void updateLayout() { StringReader sr = new StringReader(layoutFile.replace("__NEWLINE__", "\n")); try { layout = Optional - .of(new LayoutHelper(sr, Globals.prefs, Globals.journalAbbreviationLoader).getLayoutFromText()); + .of(new LayoutHelper(sr, LayoutFormatterPreferences.fromPreferences(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 4146581d273..7b6a1cfd44e 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -57,6 +57,7 @@ import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.openoffice.OOBibStyle; import net.sf.jabref.logic.openoffice.OpenOfficePreferences; import net.sf.jabref.logic.openoffice.StyleLoader; @@ -126,7 +127,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.prefs, Globals.journalAbbreviationLoader, + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader), Globals.prefs.getDefaultEncoding()); } 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 9e44a4337c5..64ca345e8f3 100644 --- a/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java +++ b/src/main/java/net/sf/jabref/logic/exporter/ExportFormat.java @@ -34,6 +34,7 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.Globals; import net.sf.jabref.logic.layout.Layout; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; import net.sf.jabref.model.entry.BibEntry; @@ -219,7 +220,8 @@ public void performExport(final BibDatabaseContext databaseContext, final String // Print header try (Reader reader = getReader(lfFileName + ".begin.layout")) { - LayoutHelper layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); + LayoutHelper layoutHelper = new LayoutHelper(reader, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader)); beginLayout = layoutHelper.getLayoutFromText(); } catch (IOException ex) { // If an exception was cast, export filter doesn't have a begin @@ -245,7 +247,8 @@ public void performExport(final BibDatabaseContext databaseContext, final String Layout defLayout; LayoutHelper layoutHelper; try (Reader reader = getReader(lfFileName + ".layout")) { - layoutHelper = new LayoutHelper(reader, Globals.prefs, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader)); defLayout = layoutHelper.getLayoutFromText(); } if (defLayout != null) { @@ -267,7 +270,8 @@ 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.prefs, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, LayoutFormatterPreferences + .fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader)); layout = layoutHelper.getLayoutFromText(); layouts.put(type, layout); if (layout != null) { @@ -291,7 +295,8 @@ 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.prefs, Globals.journalAbbreviationLoader); + layoutHelper = new LayoutHelper(reader, + LayoutFormatterPreferences.fromPreferences(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 7093d8a311a..fb32ab07a49 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,8 @@ import java.util.regex.Pattern; import net.sf.jabref.BibDatabaseContext; -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; @@ -42,7 +40,7 @@ public class Layout { private static final Log LOGGER = LogFactory.getLog(Layout.class); - public Layout(List parsedEntries, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { + public Layout(List parsedEntries, LayoutFormatterPreferences prefs) { List tmpEntries = new ArrayList<>(parsedEntries.size()); List blockEntries = null; @@ -68,7 +66,7 @@ public Layout(List parsedEntries, JabRefPreferences prefs, JournalAbb blockEntries.add(parsedEntry); le = new LayoutEntry(blockEntries, parsedEntry.i == LayoutHelper.IS_FIELD_END ? LayoutHelper.IS_FIELD_START : LayoutHelper.IS_GROUP_START, - prefs, repositoryLoader); + prefs); tmpEntries.add(le); blockEntries = null; } else { @@ -83,7 +81,7 @@ public Layout(List parsedEntries, JabRefPreferences prefs, JournalAbb } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, prefs, repositoryLoader)); + tmpEntries.add(new LayoutEntry(parsedEntry, prefs)); } 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 b434b69a7da..1172fa87167 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutEntry.java @@ -28,8 +28,6 @@ import net.sf.jabref.BibDatabaseContext; 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; @@ -95,7 +93,6 @@ 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; @@ -117,13 +114,10 @@ class LayoutEntry { private static final Log LOGGER = LogFactory.getLog(LayoutEntry.class); - private final JournalAbbreviationLoader repositoryLoader; + private final LayoutFormatterPreferences prefs; - private final JabRefPreferences prefs; - - public LayoutEntry(StringInt si, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { - this.repositoryLoader = repositoryLoader; + public LayoutEntry(StringInt si, LayoutFormatterPreferences prefs) { this.prefs = prefs; type = si.i; switch (type) { @@ -143,9 +137,7 @@ public LayoutEntry(StringInt si, JabRefPreferences prefs, JournalAbbreviationLoa } } - public LayoutEntry(List parsedEntries, int layoutType, JabRefPreferences prefs, - JournalAbbreviationLoader repositoryLoader) { - this.repositoryLoader = repositoryLoader; + public LayoutEntry(List parsedEntries, int layoutType, LayoutFormatterPreferences prefs) { this.prefs = prefs; List tmpEntries = new ArrayList<>(); String blockStart = parsedEntries.get(0).s; @@ -171,7 +163,7 @@ public LayoutEntry(List parsedEntries, int layoutType, JabRefPreferen 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, prefs, repositoryLoader); + LayoutEntry le = new LayoutEntry(blockEntries, groupType, prefs); tmpEntries.add(le); blockEntries = null; } else { @@ -187,7 +179,7 @@ public LayoutEntry(List parsedEntries, int layoutType, JabRefPreferen } if (blockEntries == null) { - tmpEntries.add(new LayoutEntry(parsedEntry, prefs, repositoryLoader)); + tmpEntries.add(new LayoutEntry(parsedEntry, prefs)); } else { blockEntries.add(parsedEntry); } @@ -514,7 +506,8 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "Iso690NamesAuthors": return new Iso690NamesAuthors(); case "JournalAbbreviator": - return new JournalAbbreviator(repositoryLoader, JournalAbbreviationPreferences.fromPreferences(prefs)); + return new JournalAbbreviator(prefs.getJournalAbbreviationLoader(), + prefs.getJournalAbbreviationPreferences()); case "LastPage": return new LastPage(); case "FormatChars": // For backward compatibility @@ -551,7 +544,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "Default": return new Default(); case "FileLink": - return new FileLink(prefs); + return new FileLink(prefs.getFileLinkPreferences()); case "Number": return new Number(); case "RisAuthors": @@ -565,7 +558,7 @@ private LayoutFormatter getLayoutFormatterByName(String name) throws Exception { case "WrapContent": return new WrapContent(); case "WrapFileLinks": - return new WrapFileLinks(prefs); + return new WrapFileLinks(prefs.getFileLinkPreferences()); default: return new NotFoundFormatter(name); } @@ -582,15 +575,15 @@ private List getOptionalLayout(String formatterName) { List results = new ArrayList<>(formatterStrings.size()); - Map userNameFormatter = NameFormatter.getNameFormatters(prefs); + Map userNameFormatter = NameFormatter.getNameFormatters(prefs.getNameFormatterPreferences()); for (List strings : formatterStrings) { String className = strings.get(0).trim(); // Check if this is a name formatter defined by this export filter: - if (prefs.customExportNameFormatters != null) { - String contents = prefs.customExportNameFormatters.get(className); + if (prefs.getCustomExportNameFormatters() != null) { + String contents = prefs.getCustomExportNameFormatters().get(className); if (contents != null) { NameFormatter nf = new NameFormatter(); nf.setParameter(contents); diff --git a/src/main/java/net/sf/jabref/logic/layout/LayoutFormatterPreferences.java b/src/main/java/net/sf/jabref/logic/layout/LayoutFormatterPreferences.java new file mode 100644 index 00000000000..76fd6cc9900 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutFormatterPreferences.java @@ -0,0 +1,59 @@ +package net.sf.jabref.logic.layout; + +import java.util.Map; +import java.util.Objects; + +import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.journals.JournalAbbreviationPreferences; +import net.sf.jabref.logic.layout.format.FileLinkPreferences; +import net.sf.jabref.logic.layout.format.NameFormatterPreferences; +import net.sf.jabref.preferences.JabRefPreferences; + +public class LayoutFormatterPreferences { + + private final NameFormatterPreferences nameFormatterPreferences; + private final JournalAbbreviationPreferences journalAbbreviationPreferences; + private final FileLinkPreferences fileLinkPreferences; + private final Map customExportNameFormatters; + private final JournalAbbreviationLoader journalAbbreviationLoader; + + public LayoutFormatterPreferences(NameFormatterPreferences nameFormatterPreferences, + JournalAbbreviationPreferences journalAbbreviationPreferences, FileLinkPreferences fileLinkPreferences, + Map customExportNameFormatters, JournalAbbreviationLoader journalAbbreviationLoader) { + this.nameFormatterPreferences = nameFormatterPreferences; + this.journalAbbreviationPreferences = journalAbbreviationPreferences; + this.customExportNameFormatters = customExportNameFormatters; + this.fileLinkPreferences = fileLinkPreferences; + this.journalAbbreviationLoader = journalAbbreviationLoader; + } + + public static LayoutFormatterPreferences fromPreferences(JabRefPreferences jabRefPreferences, + JournalAbbreviationLoader journalAbbreviationLoader) { + Objects.requireNonNull(jabRefPreferences); + Objects.requireNonNull(journalAbbreviationLoader); + return new LayoutFormatterPreferences(NameFormatterPreferences.fromPreferences(jabRefPreferences), + JournalAbbreviationPreferences.fromPreferences(jabRefPreferences), + FileLinkPreferences.fromPreferences(jabRefPreferences), + jabRefPreferences.customExportNameFormatters, journalAbbreviationLoader); + } + + public NameFormatterPreferences getNameFormatterPreferences() { + return nameFormatterPreferences; + } + + public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { + return journalAbbreviationPreferences; + } + + public Map getCustomExportNameFormatters() { + return customExportNameFormatters; + } + + public FileLinkPreferences getFileLinkPreferences() { + return fileLinkPreferences; + } + + public JournalAbbreviationLoader getJournalAbbreviationLoader() { + return journalAbbreviationLoader; + } +} 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 3dfe088d6a3..cb49be1c42e 100644 --- a/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java +++ b/src/main/java/net/sf/jabref/logic/layout/LayoutHelper.java @@ -22,9 +22,6 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.logic.journals.JournalAbbreviationLoader; -import net.sf.jabref.preferences.JabRefPreferences; - /** * Helper class to get a Layout object. * @@ -51,14 +48,12 @@ public class LayoutHelper { private final PushbackReader in; private final List parsedEntries = new ArrayList<>(); - private final JournalAbbreviationLoader repositoryLoader; - private final JabRefPreferences prefs; + private final LayoutFormatterPreferences prefs; private boolean endOfFile; - public LayoutHelper(Reader in, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) { + public LayoutHelper(Reader in, LayoutFormatterPreferences prefs) { this.in = new PushbackReader(Objects.requireNonNull(in)); - this.repositoryLoader = Objects.requireNonNull(repositoryLoader); this.prefs = Objects.requireNonNull(prefs); } @@ -73,7 +68,7 @@ public Layout getLayoutFromText() throws IOException { } } - return new Layout(parsedEntries, prefs, repositoryLoader); + return new Layout(parsedEntries, prefs); } 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 3c161db0652..63e2e2f6dd4 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 @@ -17,17 +17,13 @@ import java.io.File; import java.io.IOException; -import java.util.Collections; import java.util.List; import java.util.Optional; -import net.sf.jabref.Globals; import net.sf.jabref.logic.layout.ParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; -import net.sf.jabref.model.entry.FieldName; 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; @@ -41,11 +37,11 @@ public class FileLink implements ParamLayoutFormatter { private static final Log LOGGER = LogFactory.getLog(FileLink.class); private String fileType; - private final JabRefPreferences prefs; + private final FileLinkPreferences prefs; - public FileLink(JabRefPreferences prefs) { - this.prefs = prefs; + public FileLink(FileLinkPreferences fileLinkPreferences) { + this.prefs = fileLinkPreferences; } @Override @@ -82,10 +78,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 (prefs.fileDirForDatabase == null) { - dirs = Collections.singletonList(prefs.get(FieldName.FILE + Globals.DIR_SUFFIX)); + if (prefs.getFileDirForDatabase() == null) { + dirs = prefs.getGeneratedDirForDatabase(); } else { - dirs = prefs.fileDirForDatabase; + dirs = prefs.getFileDirForDatabase(); } Optional f = FileUtil.expandFilename(link, dirs); diff --git a/src/main/java/net/sf/jabref/logic/layout/format/FileLinkPreferences.java b/src/main/java/net/sf/jabref/logic/layout/format/FileLinkPreferences.java new file mode 100644 index 00000000000..6f682225345 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/layout/format/FileLinkPreferences.java @@ -0,0 +1,33 @@ +package net.sf.jabref.logic.layout.format; + +import java.util.Collections; +import java.util.List; + +import net.sf.jabref.Globals; +import net.sf.jabref.model.entry.FieldName; +import net.sf.jabref.preferences.JabRefPreferences; + +public class FileLinkPreferences { + + private final List generatedDirForDatabase; + private final List fileDirForDatabase; + + + public FileLinkPreferences(List generatedDirForDatabase, List fileDirForDatabase) { + this.generatedDirForDatabase = generatedDirForDatabase; + this.fileDirForDatabase = fileDirForDatabase; + } + + public static FileLinkPreferences fromPreferences(JabRefPreferences prefs) { + return new FileLinkPreferences(Collections.singletonList(prefs.get(FieldName.FILE + Globals.DIR_SUFFIX)), + prefs.fileDirForDatabase); + } + + public List getGeneratedDirForDatabase() { + return generatedDirForDatabase; + } + + public List getFileDirForDatabase() { + return fileDirForDatabase; + } +} 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 1cc455bf7e1..da2b8b34daa 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 @@ -22,7 +22,6 @@ 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: @@ -184,12 +183,12 @@ public void setParameter(String parameter) { this.parameter = parameter; } - public static Map getNameFormatters(JabRefPreferences prefs) { + public static Map getNameFormatters(NameFormatterPreferences prefs) { Map result = new HashMap<>(); - List names = prefs.getStringList(NameFormatter.NAME_FORMATER_KEY); - List formats = prefs.getStringList(NameFormatter.NAME_FORMATTER_VALUE); + List names = prefs.getNameFormatterKey(); + List formats = prefs.getNameFormatterValue(); for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { diff --git a/src/main/java/net/sf/jabref/logic/layout/format/NameFormatterPreferences.java b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatterPreferences.java new file mode 100644 index 00000000000..2c6a9b748b8 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/layout/format/NameFormatterPreferences.java @@ -0,0 +1,31 @@ +package net.sf.jabref.logic.layout.format; + +import java.util.List; + +import net.sf.jabref.preferences.JabRefPreferences; + +public class NameFormatterPreferences { + + private final List nameFormatterKey; + private final List nameFormatterValue; + + + public NameFormatterPreferences(List nameFormatterKey, List nameFormatterValue) { + this.nameFormatterKey = nameFormatterKey; + this.nameFormatterValue = nameFormatterValue; + } + + public static NameFormatterPreferences fromPreferences(JabRefPreferences jabRefPreferences) { + return new NameFormatterPreferences(jabRefPreferences.getStringList(NameFormatter.NAME_FORMATER_KEY), + jabRefPreferences.getStringList(NameFormatter.NAME_FORMATTER_VALUE)); + } + + public List getNameFormatterKey() { + return nameFormatterKey; + } + + + public List getNameFormatterValue() { + return nameFormatterValue; + } +} 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 592ca3b4ec5..fa4eae9fdd0 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 @@ -18,19 +18,15 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import net.sf.jabref.Globals; import net.sf.jabref.logic.layout.AbstractParamLayoutFormatter; import net.sf.jabref.logic.util.io.FileUtil; -import net.sf.jabref.model.entry.FieldName; 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; @@ -118,7 +114,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; + private final FileLinkPreferences prefs; static { WrapFileLinks.ESCAPE_SEQ.put('i', WrapFileLinks.ITERATION_COUNT); @@ -130,8 +126,8 @@ public class WrapFileLinks extends AbstractParamLayoutFormatter { } - public WrapFileLinks(JabRefPreferences prefs) { - this.prefs = prefs; + public WrapFileLinks(FileLinkPreferences fileLinkPreferences) { + this.prefs = fileLinkPreferences; } @Override @@ -178,10 +174,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 (prefs.fileDirForDatabase == null) { - dirs = Collections.singletonList(prefs.get(FieldName.FILE + Globals.DIR_SUFFIX)); + if (prefs.getFileDirForDatabase() == null) { + dirs = prefs.getGeneratedDirForDatabase(); } else { - dirs = prefs.fileDirForDatabase; + dirs = prefs.getFileDirForDatabase(); } 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 488d1412042..8b9d0b5a62a 100644 --- a/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java +++ b/src/main/java/net/sf/jabref/logic/openoffice/OOBibStyle.java @@ -36,9 +36,9 @@ import java.util.TreeSet; import java.util.regex.Pattern; -import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatter; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.database.BibDatabase; @@ -46,7 +46,6 @@ import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -147,16 +146,14 @@ enum BibStyleMode { private static final String AUTHOR_LAST_SEPARATOR = "AuthorLastSeparator"; private static final String AUTHOR_SEPARATOR = "AuthorSeparator"; - private final JournalAbbreviationLoader repositoryLoader; - private final JabRefPreferences prefs; + private final LayoutFormatterPreferences prefs; private static final Pattern QUOTED = Pattern.compile("\".*\""); private static final Log LOGGER = LogFactory.getLog(OOBibStyle.class); - public OOBibStyle(File styleFile, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader, + public OOBibStyle(File styleFile, LayoutFormatterPreferences prefs, Charset encoding) throws IOException { - this.repositoryLoader = Objects.requireNonNull(repositoryLoader); this.prefs = Objects.requireNonNull(prefs); this.styleFile = Objects.requireNonNull(styleFile); this.encoding = Objects.requireNonNull(encoding); @@ -166,9 +163,8 @@ public OOBibStyle(File styleFile, JabRefPreferences prefs, JournalAbbreviationLo path = styleFile.getPath(); } - public OOBibStyle(String resourcePath, JabRefPreferences prefs, JournalAbbreviationLoader repositoryLoader) + public OOBibStyle(String resourcePath, LayoutFormatterPreferences prefs) throws IOException { - this.repositoryLoader = Objects.requireNonNull(repositoryLoader); this.prefs = Objects.requireNonNull(prefs); this.encoding = StandardCharsets.UTF_8; setDefaultProperties(); @@ -383,8 +379,7 @@ 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.prefs, this.repositoryLoader) - .getLayoutFromText(); + Layout layout = new LayoutHelper(new StringReader(formatString), this.prefs).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 1d0d1f5761a..578d6af288a 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,7 @@ import java.util.List; import java.util.Objects; -import net.sf.jabref.logic.journals.JournalAbbreviationLoader; -import net.sf.jabref.preferences.JabRefPreferences; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,10 +40,9 @@ public class StyleLoader { private final List internalStyleFiles = Arrays.asList(DEFAULT_AUTHORYEAR_STYLE_PATH, DEFAULT_NUMERICAL_STYLE_PATH); - private final JournalAbbreviationLoader journalAbbreviationLoader; private final OpenOfficePreferences preferences; private final Charset encoding; - private final JabRefPreferences jabrefPreferences; + private final LayoutFormatterPreferences layoutFormatterPreferences; // Lists of the internal // and external styles @@ -52,11 +50,10 @@ public class StyleLoader { private final List externalStyles = new ArrayList<>(); - public StyleLoader(OpenOfficePreferences preferences, JabRefPreferences jabrefPreferences, - JournalAbbreviationLoader journalAbbreviationLoader, Charset encoding) { - this.journalAbbreviationLoader = Objects.requireNonNull(journalAbbreviationLoader); + public StyleLoader(OpenOfficePreferences preferences, LayoutFormatterPreferences jabrefPreferences, + Charset encoding) { this.preferences = Objects.requireNonNull(preferences); - this.jabrefPreferences = Objects.requireNonNull(jabrefPreferences); + this.layoutFormatterPreferences = Objects.requireNonNull(jabrefPreferences); this.encoding = Objects.requireNonNull(encoding); loadInternalStyles(); loadExternalStyles(); @@ -76,8 +73,7 @@ public List getStyles() { public boolean addStyleIfValid(String filename) { Objects.requireNonNull(filename); try { - OOBibStyle newStyle = new OOBibStyle(new File(filename), jabrefPreferences, journalAbbreviationLoader, - encoding); + OOBibStyle newStyle = new OOBibStyle(new File(filename), layoutFormatterPreferences, encoding); if (externalStyles.contains(newStyle)) { LOGGER.info("External style file " + filename + " already existing."); } else if (newStyle.isValid()) { @@ -103,8 +99,7 @@ private void loadExternalStyles() { List lists = preferences.getExternalStyles(); for (String filename : lists) { try { - OOBibStyle style = new OOBibStyle(new File(filename), jabrefPreferences, journalAbbreviationLoader, - encoding); + OOBibStyle style = new OOBibStyle(new File(filename), layoutFormatterPreferences, encoding); if (style.isValid()) { //Problem! externalStyles.add(style); } else { @@ -123,7 +118,7 @@ private void loadInternalStyles() { internalStyles.clear(); for (String filename : internalStyleFiles) { try { - internalStyles.add(new OOBibStyle(filename, jabrefPreferences, journalAbbreviationLoader)); + internalStyles.add(new OOBibStyle(filename, layoutFormatterPreferences)); } 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 550ef8e8f30..b8d8a4b0527 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 @@ -39,6 +39,7 @@ import net.sf.jabref.BibDatabaseContext; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.database.BibDatabase; @@ -398,7 +399,8 @@ 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, prefs, repositoryLoader).getLayoutFromText(); + layout = new LayoutHelper(sr, LayoutFormatterPreferences.fromPreferences(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 467bbf64ecd..a791adfce2b 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,9 @@ 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, Globals.prefs, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); + Layout layout = new LayoutHelper(sr, + LayoutFormatterPreferences.fromPreferences(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 e045a7eff4d..5d5e8cdf196 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,9 @@ 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, Globals.prefs, mock(JournalAbbreviationLoader.class)).getLayoutFromText(); + Layout layout = new LayoutHelper(sr, + LayoutFormatterPreferences.fromPreferences(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 df66e221d17..bf173f5f0cf 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,41 @@ public void setUp() throws Exception { @Test public void testEmpty() { - assertEquals("", new FileLink(Globals.prefs).format("")); + assertEquals("", new FileLink(FileLinkPreferences.fromPreferences(Globals.prefs)).format("")); } @Test public void testNull() { - assertEquals("", new FileLink(Globals.prefs).format(null)); + assertEquals("", new FileLink(FileLinkPreferences.fromPreferences(Globals.prefs)).format(null)); } @Test public void testOnlyFilename() { - assertEquals("test.pdf", new FileLink(Globals.prefs).format("test.pdf")); + assertEquals("test.pdf", new FileLink(FileLinkPreferences.fromPreferences(Globals.prefs)).format("test.pdf")); } @Test public void testCompleteRecord() { - assertEquals("test.pdf", new FileLink(Globals.prefs).format("paper:test.pdf:PDF")); + assertEquals("test.pdf", + new FileLink(FileLinkPreferences.fromPreferences(Globals.prefs)).format("paper:test.pdf:PDF")); } @Test public void testMultipleFiles() { - ParamLayoutFormatter a = new FileLink(Globals.prefs); + ParamLayoutFormatter a = new FileLink(FileLinkPreferences.fromPreferences(Globals.prefs)); assertEquals("test.pdf", a.format("paper:test.pdf:PDF;presentation:pres.ppt:PPT")); } @Test public void testMultipleFilesPick() { - ParamLayoutFormatter a = new FileLink(Globals.prefs); + ParamLayoutFormatter a = new FileLink(FileLinkPreferences.fromPreferences(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(Globals.prefs); + ParamLayoutFormatter a = new FileLink(FileLinkPreferences.fromPreferences(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 5e39f3981ea..f42a0d692d4 100644 --- a/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java +++ b/src/test/java/net/sf/jabref/logic/openoffice/OOBibStyleTest.java @@ -20,6 +20,7 @@ import net.sf.jabref.importer.fileformat.ImportFormat; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; import net.sf.jabref.logic.layout.Layout; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -49,8 +50,8 @@ public void tearDown() { @Test public void testAuthorYear() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertTrue(style.isValid()); assertTrue(style.isFromResource()); assertFalse(style.isBibtexKeyCiteMarkers()); @@ -67,7 +68,8 @@ 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, Globals.prefs, mock(JournalAbbreviationLoader.class), + OOBibStyle style = new OOBibStyle(defFile, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), Globals.prefs.getDefaultEncoding()); assertTrue(style.isValid()); assertFalse(style.isFromResource()); @@ -82,8 +84,8 @@ public void testAuthorYearAsFile() throws URISyntaxException, IOException { @Test public void testNumerical() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertTrue(style.isValid()); assertFalse(style.isBibtexKeyCiteMarkers()); assertFalse(style.isBoldCitations()); @@ -96,8 +98,8 @@ public void testNumerical() throws IOException { @Test public void testGetNumCitationMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertEquals("[1] ", style.getNumCitationMarker(Arrays.asList(1), -1, true)); assertEquals("[1]", style.getNumCitationMarker(Arrays.asList(1), -1, false)); assertEquals("[1] ", style.getNumCitationMarker(Arrays.asList(1), 0, true)); @@ -113,8 +115,8 @@ public void testGetNumCitationMarker() throws IOException { @Test public void testGetNumCitationMarkerUndefined() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertEquals("[" + OOBibStyle.UNDEFINED_CITATION_MARKER + "; 2-4] ", style.getNumCitationMarker(Arrays.asList(4, 2, 3, 0), 1, true)); @@ -131,8 +133,8 @@ public void testGetNumCitationMarkerUndefined() throws IOException { @Test public void testGetCitProperty() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertEquals(", ", style.getStringCitProperty("AuthorSeparator")); assertEquals(3, style.getIntCitProperty("MaxAuthors")); assertTrue(style.getBooleanCitProperty(OOBibStyle.MULTI_CITE_CHRONOLOGICAL)); @@ -146,8 +148,8 @@ 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, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); BibDatabase db = result.getDatabase(); for (BibEntry entry : db.getEntries()) { @@ -167,8 +169,8 @@ 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, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); BibDatabase db = result.getDatabase(); Layout l = style.getReferenceFormat("default"); @@ -187,8 +189,8 @@ public void testLayout() throws IOException { @Test public void testInstitutionAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); BibDatabase database = new BibDatabase(); Layout l = style.getReferenceFormat("article"); @@ -206,8 +208,8 @@ public void testInstitutionAuthor() throws IOException { @Test public void testVonAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); BibDatabase database = new BibDatabase(); Layout l = style.getReferenceFormat("article"); @@ -225,8 +227,8 @@ public void testVonAuthor() throws IOException { @Test public void testInstitutionAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -245,8 +247,8 @@ public void testInstitutionAuthorMarker() throws IOException { @Test public void testVonAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -265,8 +267,8 @@ public void testVonAuthorMarker() throws IOException { @Test public void testNullAuthorMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -283,8 +285,8 @@ public void testNullAuthorMarker() throws IOException { @Test public void testNullYearMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -301,8 +303,8 @@ public void testNullYearMarker() throws IOException { @Test public void testEmptyEntryMarker() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -318,8 +320,8 @@ public void testEmptyEntryMarker() throws IOException { @Test public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -354,8 +356,8 @@ public void testGetCitationMarkerInParenthesisUniquefiers() throws IOException { @Test public void testGetCitationMarkerInTextUniquefiers() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -390,8 +392,8 @@ public void testGetCitationMarkerInTextUniquefiers() throws IOException { @Test public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -425,8 +427,8 @@ public void testGetCitationMarkerInParenthesisUniquefiersThreeSameAuthor() throw @Test public void testGetCitationMarkerInTextUniquefiersThreeSameAuthor() throws IOException { - OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); Map entryDBMap = new HashMap<>(); List entries = new ArrayList<>(); @@ -461,38 +463,38 @@ 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, Globals.prefs, - mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertEquals(style1, style2); } @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, Globals.prefs, - mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertNotEquals(style1, style2); } @Test public void testCompareToEqual() throws IOException { - OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(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, Globals.prefs, - mock(JournalAbbreviationLoader.class)); - OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, Globals.prefs, - mock(JournalAbbreviationLoader.class)); + OOBibStyle style1 = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); + OOBibStyle style2 = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class))); assertTrue(style1.compareTo(style2) > 0); assertFalse(style2.compareTo(style1) > 0); } @@ -501,7 +503,8 @@ 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, Globals.prefs, mock(JournalAbbreviationLoader.class)); + OOBibStyle style = new OOBibStyle(fileName, + LayoutFormatterPreferences.fromPreferences(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 7aa75441839..6e53aafe18e 100644 --- a/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java +++ b/src/test/java/net/sf/jabref/logic/openoffice/StyleLoaderTest.java @@ -10,6 +10,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefMain; import net.sf.jabref.logic.journals.JournalAbbreviationLoader; +import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.After; @@ -48,30 +49,32 @@ public void tearDown() throws Exception { @Test(expected = NullPointerException.class) public void throwNPEWithNullPreferences() { - loader = new StyleLoader(null, Globals.prefs, - mock(JournalAbbreviationLoader.class), mock(Charset.class)); + loader = new StyleLoader(null, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + mock(Charset.class)); fail(); } @Test(expected = NullPointerException.class) public void throwNPEWithNullRepository() { - loader = new StyleLoader(mock(OpenOfficePreferences.class), Globals.prefs, - null, mock(Charset.class)); + loader = new StyleLoader(mock(OpenOfficePreferences.class), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, null), mock(Charset.class)); fail(); } @Test(expected = NullPointerException.class) public void throwNPEWithNullCharset() { - loader = new StyleLoader(mock(OpenOfficePreferences.class), Globals.prefs, - mock(JournalAbbreviationLoader.class), null); + loader = new StyleLoader(mock(OpenOfficePreferences.class), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), null); fail(); } @Test public void testGetStylesWithEmptyExternal() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); assertEquals(2, loader.getStyles().size()); } @@ -79,8 +82,9 @@ public void testGetStylesWithEmptyExternal() { @Test public void testAddStyleLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); String filename = Paths.get(JabRefMain.class.getResource(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH).toURI()) .toFile().getPath(); @@ -92,8 +96,9 @@ 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, Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); int beforeAdding = loader.getStyles().size(); loader.addStyleIfValid("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky"); assertEquals(beforeAdding, loader.getStyles().size()); @@ -104,8 +109,9 @@ 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, Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); assertEquals(numberOfInternalStyles + 1, loader.getStyles().size()); } @@ -113,8 +119,9 @@ public void testInitalizeWithOneExternalFile() throws URISyntaxException { public void testInitalizeWithIncorrectExternalFile() { preferences.setExternalStyles(Collections.singletonList("DefinitelyNotAValidFileNameOrWeAreExtremelyUnlucky")); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); assertEquals(numberOfInternalStyles, loader.getStyles().size()); } @@ -124,8 +131,9 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept .toFile().getPath(); preferences.setExternalStyles(Collections.singletonList(filename)); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); int beforeRemoving = loader.getStyles().size(); for (OOBibStyle style : loader.getStyles()) { @@ -146,8 +154,9 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro .toFile().getPath(); preferences.setExternalStyles(Collections.singletonList(filename)); - loader = new StyleLoader(preferences, Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { if (!style.isFromResource()) { @@ -164,8 +173,9 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro @Test public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(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()) .toFile().getPath(); @@ -176,8 +186,9 @@ public void testAddSameStyleTwiceLeadsToOneMoreStyle() throws URISyntaxException @Test(expected = NullPointerException.class) public void testAddNullStyleThrowsNPE() { - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); loader.addStyleIfValid(null); fail(); } @@ -186,8 +197,9 @@ public void testAddNullStyleThrowsNPE() { @Test public void testGetDefaultUsedStyleWhenEmpty() { Globals.prefs.remove(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, style.getPath()); @@ -197,8 +209,9 @@ public void testGetDefaultUsedStyleWhenEmpty() { @Test public void testGetStoredUsedStyle() { preferences.setCurrentStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, style.getPath()); @@ -208,8 +221,9 @@ public void testGetStoredUsedStyle() { @Test public void testGtDefaultUsedStyleWhenIncorrect() { preferences.setCurrentStyle("ljlkjlkjnljnvdlsjniuhwelfhuewfhlkuewhfuwhelu"); - loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), Globals.prefs, - mock(JournalAbbreviationLoader.class), Globals.prefs.getDefaultEncoding()); + loader = new StyleLoader(new OpenOfficePreferences(Globals.prefs), + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), + Globals.prefs.getDefaultEncoding()); OOBibStyle style = loader.getUsedStyle(); assertTrue(style.isValid()); assertEquals(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, style.getPath()); @@ -220,7 +234,8 @@ public void testGtDefaultUsedStyleWhenIncorrect() { public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() { preferences.setExternalStyles(Collections.emptyList()); - loader = new StyleLoader(preferences, Globals.prefs, mock(JournalAbbreviationLoader.class), + loader = new StyleLoader(preferences, + LayoutFormatterPreferences.fromPreferences(Globals.prefs, mock(JournalAbbreviationLoader.class)), Globals.prefs.getDefaultEncoding()); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) {