diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a99c7ba398..514002db367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,16 +11,26 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ## [Unreleased] ### Changed +- We added a validity check for dates in the `date` and `urldate` fields. - We added a text file export for 'Find Unlinked Files'. [#3341](https://github.com/JabRef/jabref/issues/3341) - We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971) +- We changed the implementation of the `[shorttitle]` key pattern. It now removes small words like `a`, `an`, `on`, `the` etc. Refer to the help page for a complete overview. [Feature request in the forum](http://discourse.jabref.org/t/jabref-differences-in-shorttitle-between-versions-3-8-1-and-4-not-discounting-the-a-an-of-in-titles/1147) +- We added a formatter for adding braces around the `title` field. E.g., `title = {ExamPle}` becomes `title = {{ExamPle}}`, which prevents BibTeX to convert it to lower case. You can use it at the [cleanup entries](http://help.jabref.org/en/CleanupEntries) functionality. +- We added a formatter to ensure correct en dashes in the `title` field. E.g., `title = {Example - illustrative}` becomes `title = {Example -- illustrative}`. +- We streamlined the defaults for a [cleanup of entries](http://help.jabref.org/en/CleanupEntries) in the case of BibTeX. +- The import inspection window now uses the same font size setting as the maintable [Feature request in the forum](http://discourse.jabref.org/t/inspection-window-and-others-line-height-of-table-too-small-for-fonts/1168) ### Fixed -We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994) -We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448) -We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated [#3986](https://github.com/JabRef/jabref/issues/3986) -We fixed an issue where custom exports could not be selected in the 'Export (selected) entries' dialog [#4013](https://github.com/JabRef/jabref/issues/4013) +- We fixed an issue where the export to clipboard functionality could not be invoked. [#3994](https://github.com/JabRef/jabref/issues/3994) +- We fixed an issue with the migration of invalid Look and Feels. [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448) +- We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated. [#3986](https://github.com/JabRef/jabref/issues/3986) +- We fixed an issue where JabRef removed whitespace from the Title-fetcher which resulting in no entries being found. [#4014](https://github.com/JabRef/jabref/issues/4014) +- We fixed an issue where fetched entries from the ACM fetcher could not be imported. [#4018](https://github.com/JabRef/jabref/issues/4018) +- We fixed an issue to enable push to application on macOs again [#4041](https://github.com/JabRef/jabref/issues/4041) +- We fixed an issue where custom exports could not be selected in the 'Export (selected) entries' dialog [#4013](https://github.com/JabRef/jabref/issues/4013) + ### Removed -We removed the GTK Look and Feel from the Options, as it leads to freezes in JabRef on MacOSX and Linux [#3995](https://github.com/JabRef/jabref/issues/3995) +- We removed the GTK Look and Feel from the Options, as it leads to freezes in JabRef on MacOSX and Linux [#3995](https://github.com/JabRef/jabref/issues/3995). The GTK Look and Feel is now replaced with the "Nimbus" style as default. diff --git a/build.gradle b/build.gradle index b2005e93365..ccd34f0c82a 100644 --- a/build.gradle +++ b/build.gradle @@ -147,8 +147,8 @@ dependencies { compile 'com.github.tomtung:latex2unicode_2.12:0.2.2' - compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.1.0' - compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.1.0' + compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.1.1' + compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.1.1' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0' testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0' @@ -163,7 +163,7 @@ dependencies { testCompile 'org.reflections:reflections:0.9.11' testCompile 'org.xmlunit:xmlunit-core:2.6.0' testCompile 'org.xmlunit:xmlunit-matchers:2.6.0' - testCompile 'com.tngtech.archunit:archunit-junit:0.5.0' + testCompile 'com.tngtech.archunit:archunit-junit:0.8.0' testCompile "org.testfx:testfx-core:4.0.+" testCompile "org.testfx:testfx-junit:4.0.+" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c44b679acd3..f6b961fd5a8 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ea720f986f3..16d28051c9c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index bd370dda02a..4654655e860 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -36,16 +36,21 @@ * JabRef MainClass */ public class JabRefMain extends Application { - private static final Logger LOGGER = LoggerFactory.getLogger(JabRefMain.class); + private static String[] arguments; public static void main(String[] args) { arguments = args; - launch(arguments); } + @Override + public void start(Stage mainStage) throws Exception { + Platform.setImplicitExit(false); + SwingUtilities.invokeLater(() -> start(arguments)); + } + /** * Tests if we are running an acceptable Java and terminates JabRef when we are sure the version is not supported. * This test uses the requirements for the Java version as specified in gradle.build. It is possible to @@ -93,39 +98,65 @@ private static void ensureCorrectJavaVersion() { } private static void start(String[] args) { + // Fail on unsupported Java versions + ensureCorrectJavaVersion(); + FallbackExceptionHandler.installExceptionHandler(); + // Init preferences - JabRefPreferences preferences = JabRefPreferences.getInstance(); + final JabRefPreferences preferences = JabRefPreferences.getInstance(); Globals.prefs = preferences; - // Perform Migrations - // Perform checks and changes for users with a preference set from an older JabRef version. - PreferencesMigrations.upgradePrefsToOrgJabRef(); - PreferencesMigrations.upgradeSortOrder(); - PreferencesMigrations.upgradeFaultyEncodingStrings(); - PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern(); - PreferencesMigrations.upgradeImportFileAndDirePatterns(); - PreferencesMigrations.upgradeStoredCustomEntryTypes(); - PreferencesMigrations.upgradeKeyBindingsToJavaFX(); - PreferencesMigrations.addCrossRefRelatedFieldsForAutoComplete(); - PreferencesMigrations.upgradeObsoleteLookAndFeels(); + // Perform migrations + PreferencesMigrations.runMigrations(); + + configureProxy(preferences.getProxyPreferences()); + + Globals.startBackgroundTasks(); + + applyPreferences(preferences); // Process arguments ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START); - FallbackExceptionHandler.installExceptionHandler(); + // Check for running JabRef + if (!handleMultipleAppInstances(args) || argumentProcessor.shouldShutDown()) { + shutdownCurrentInstance(); + return; + } - ensureCorrectJavaVersion(); + // If not, start GUI + SwingUtilities + .invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank())); + } - ProxyPreferences proxyPreferences = preferences.getProxyPreferences(); - ProxyRegisterer.register(proxyPreferences); - if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { - Authenticator.setDefault(new ProxyAuthenticator()); + private static boolean handleMultipleAppInstances(String[] args) { + RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences(); + if (remotePreferences.useRemoteServer()) { + Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort()); + + if (!Globals.REMOTE_LISTENER.isOpen()) { + // we are not alone, there is already a server out there, try to contact already running JabRef: + if (new RemoteClient(remotePreferences.getPort()).sendCommandLineArguments(args)) { + // We have successfully sent our command line options through the socket to another JabRef instance. + // So we assume it's all taken care of, and quit. + LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); + return false; + } + } + // we are alone, we start the server + Globals.REMOTE_LISTENER.start(); } + return true; + } - Globals.startBackgroundTasks(); + private static void shutdownCurrentInstance() { + Globals.shutdownThreadPools(); + // needed to tell JavaFx to stop + Platform.exit(); + } + private static void applyPreferences(JabRefPreferences preferences) { // Update handling of special fields based on preferences - InternalBibtexFields - .updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS)); + InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS)); // Update name of the time stamp field based on preferences InternalBibtexFields.updateTimeStampField(Globals.prefs.getTimestampPreferences().getTimestampField()); // Update which fields should be treated as numeric, based on preferences: @@ -144,48 +175,15 @@ private static void start(String[] args) { // Initialize protected terms loader Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); - // Check for running JabRef - RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences(); - if (remotePreferences.useRemoteServer()) { - Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort()); - - if (!Globals.REMOTE_LISTENER.isOpen()) { - // we are not alone, there is already a server out there, try to contact already running JabRef: - if (new RemoteClient(remotePreferences.getPort()).sendCommandLineArguments(args)) { - // We have successfully sent our command line options through the socket to another JabRef instance. - // So we assume it's all taken care of, and quit. - LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); - Globals.shutdownThreadPools(); - // needed to tell JavaFx to stop - Platform.exit(); - return; - } - } - // we are alone, we start the server - Globals.REMOTE_LISTENER.start(); - } - // override used newline character with the one stored in the preferences // The preferences return the system newline character sequence as default OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); - - // See if we should shut down now - if (argumentProcessor.shouldShutDown()) { - Globals.shutdownThreadPools(); - Platform.exit(); - return; - } - - // If not, start GUI - SwingUtilities - .invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), - argumentProcessor.isBlank())); } - @Override - public void start(Stage mainStage) throws Exception { - Platform.setImplicitExit(false); - SwingUtilities.invokeLater(() -> start(arguments) - ); + private static void configureProxy(ProxyPreferences proxyPreferences) { + ProxyRegisterer.register(proxyPreferences); + if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { + Authenticator.setDefault(new ProxyAuthenticator()); + } } } diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 84e2a78d4d1..40b19ab5c94 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -73,6 +73,7 @@ public EntryTypeDialog(JabRefFrame frame) { setTitle(Localization.lang("Select entry type")); addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { cancelAction.actionPerformed(null); @@ -246,7 +247,6 @@ static class TypeButton extends JButton implements Comparable { private final EntryType type; - TypeButton(String label, EntryType type) { super(label); this.type = type; @@ -263,6 +263,7 @@ public EntryType getType() { } class CancelAction extends AbstractAction { + public CancelAction() { super("Cancel"); } @@ -275,6 +276,7 @@ public void actionPerformed(ActionEvent e) { } private class FetcherWorker extends SwingWorker, Void> { + private boolean fetcherException = false; private String fetcherExceptionMessage = ""; private IdBasedFetcher fetcher = null; @@ -288,10 +290,9 @@ protected Optional doInBackground() throws Exception { generateButton.setText(Localization.lang("Searching...")); }); - Globals.prefs.put(JabRefPreferences.ID_ENTRY_GENERATOR,String.valueOf(comboBox.getSelectedItem())); - searchID = idTextField.getText().trim(); - searchID = searchID.replaceAll(" ", ""); + Globals.prefs.put(JabRefPreferences.ID_ENTRY_GENERATOR, String.valueOf(comboBox.getSelectedItem())); fetcher = WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).get(comboBox.getSelectedIndex()); + searchID = idTextField.getText(); if (!searchID.isEmpty()) { try { bibEntry = fetcher.performSearchById(searchID); @@ -311,7 +312,7 @@ protected void done() { if (result.isPresent()) { final BibEntry bibEntry = result.get(); if ((DuplicateCheck.containsDuplicate(frame.getCurrentBasePanel().getDatabase(), bibEntry, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()).isPresent())) { - //If there are duplicates starts ImportInspectionDialog + //If there are duplicates starts ImportInspectionDialog final BasePanel panel = (BasePanel) frame.getTabbedPane().getSelectedComponent(); ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false); @@ -321,7 +322,7 @@ protected void done() { diag.setVisible(true); diag.toFront(); } else { - // Regenerate CiteKey of imported BibEntry + // Regenerate CiteKey of imported BibEntry new BibtexKeyGenerator(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(bibEntry); // Update Timestamps if (Globals.prefs.getTimestampPreferences().includeCreatedTimestamp()) { diff --git a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java index 882067c44c8..f6a289752c3 100644 --- a/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java +++ b/src/main/java/org/jabref/gui/importer/ImportInspectionDialog.java @@ -1358,6 +1358,12 @@ class EntryTable extends JTable { public EntryTable(TableModel model) { super(model); getTableHeader().setReorderingAllowed(false); + + setFont(GUIGlobals.currentFont); + int maxOfIconsAndFontSize = Math.max(GUIGlobals.currentFont.getSize(), Globals.prefs.getInt(JabRefPreferences.ICON_SIZE_SMALL)); + setRowHeight(Globals.prefs.getInt(JabRefPreferences.TABLE_ROW_PADDING) + maxOfIconsAndFontSize); + // Update Table header with new settings + this.getTableHeader().resizeAndRepaint(); } @Override diff --git a/src/main/java/org/jabref/gui/importer/fetcher/ACMPortalFetcher.java b/src/main/java/org/jabref/gui/importer/fetcher/ACMPortalFetcher.java index 50d034355aa..cfa133a9958 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/ACMPortalFetcher.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/ACMPortalFetcher.java @@ -78,7 +78,7 @@ public class ACMPortalFetcher implements PreviewEntryFetcher { private static final Pattern FULL_CITATION_PATTERN = Pattern.compile("([^<]*)"); diff --git a/src/main/java/org/jabref/gui/push/AbstractPushToApplication.java b/src/main/java/org/jabref/gui/push/AbstractPushToApplication.java index b901293c849..affc05c410f 100644 --- a/src/main/java/org/jabref/gui/push/AbstractPushToApplication.java +++ b/src/main/java/org/jabref/gui/push/AbstractPushToApplication.java @@ -71,7 +71,19 @@ public void pushEntries(BibDatabase database, List entries, String key try { if (OS.OS_X) { String[] commands = getCommandLine(keyString); - ProcessBuilder processBuilder = new ProcessBuilder("open -a " + commands[0] + " -n --args " + commands[1] + " " + commands[2]); + if (commands.length < 3) { + LOGGER.error("Commandline does not contain enough parameters to \"push to application\""); + return; + } + ProcessBuilder processBuilder = new ProcessBuilder( + "open", + "-a", + commands[0], + "-n", + "--args", + commands[1], + commands[2] + ); processBuilder.start(); } else { ProcessBuilder processBuilder = new ProcessBuilder(getCommandLine(keyString)); diff --git a/src/main/java/org/jabref/logic/bibtexkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/bibtexkeypattern/BracketedPattern.java index 565a6f99166..f88e98b3842 100644 --- a/src/main/java/org/jabref/logic/bibtexkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/bibtexkeypattern/BracketedPattern.java @@ -294,7 +294,8 @@ else if (val.matches("edtr\\d+")) { } else if ("fulltitle".equals(val)) { return entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse(""); } else if ("shorttitle".equals(val)) { - return getTitleWords(3, entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse("")); + return getTitleWords(3, + removeSmallWords(entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse(""))); } else if ("shorttitleINI".equals(val)) { return keepLettersAndDigitsOnly( applyModifiers(getTitleWordsWithSpaces(3, entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse("")), diff --git a/src/main/java/org/jabref/logic/cleanup/Cleanups.java b/src/main/java/org/jabref/logic/cleanup/Cleanups.java index 6cfbe895ac9..22ebc35483f 100644 --- a/src/main/java/org/jabref/logic/cleanup/Cleanups.java +++ b/src/main/java/org/jabref/logic/cleanup/Cleanups.java @@ -36,12 +36,8 @@ public class Cleanups { List recommendedBibTeXFormatters = new ArrayList<>(); recommendedBibTeXFormatters.addAll(defaultFormatters); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToLatexFormatter())); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new UnicodeToLatexFormatter())); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.BOOKTITLE, new UnicodeToLatexFormatter())); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.JOURNAL, new UnicodeToLatexFormatter())); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.AUTHOR, new UnicodeToLatexFormatter())); - recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.EDITOR, new UnicodeToLatexFormatter())); + recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new HtmlToLatexFormatter())); + recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new UnicodeToLatexFormatter())); recommendedBibTeXFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new OrdinalsToSuperscriptFormatter())); RECOMMEND_BIBTEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibTeXFormatters); @@ -49,6 +45,7 @@ public class Cleanups { recommendedBiblatexFormatters.addAll(defaultFormatters); recommendedBiblatexFormatters.add(new FieldFormatterCleanup(FieldName.TITLE, new HtmlToUnicodeFormatter())); recommendedBiblatexFormatters.add(new FieldFormatterCleanup(FieldName.INTERNAL_ALL_TEXT_FIELDS_FIELD, new LatexToUnicodeFormatter())); + // DO NOT ADD OrdinalsToSuperscriptFormatter here, because this causes issues. See https://github.com/JabRef/jabref/issues/2596. RECOMMEND_BIBLATEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBiblatexFormatters); } diff --git a/src/main/java/org/jabref/logic/formatter/Formatters.java b/src/main/java/org/jabref/logic/formatter/Formatters.java index b4930aabe6f..918f5f77fa4 100644 --- a/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -6,12 +6,14 @@ import java.util.Objects; import java.util.Optional; +import org.jabref.logic.formatter.bibtexfields.AddBracesFormatter; import org.jabref.logic.formatter.bibtexfields.ClearFormatter; import org.jabref.logic.formatter.bibtexfields.EscapeUnderscoresFormatter; import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeEnDashesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; @@ -47,10 +49,12 @@ public class Formatters { ); private static final List OTHERS = Arrays.asList( + new AddBracesFormatter(), new ClearFormatter(), new LatexCleanupFormatter(), new MinifyNameListFormatter(), new NormalizeDateFormatter(), + new NormalizeEnDashesFormatter(), new NormalizeMonthFormatter(), new NormalizeNamesFormatter(), new NormalizePagesFormatter(), diff --git a/src/main/java/org/jabref/logic/formatter/IdentityFormatter.java b/src/main/java/org/jabref/logic/formatter/IdentityFormatter.java index 1056638b512..23cf683c283 100644 --- a/src/main/java/org/jabref/logic/formatter/IdentityFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/IdentityFormatter.java @@ -8,7 +8,7 @@ /** * It may seem useless, but is needed as a fallback option */ -public class IdentityFormatter implements Formatter { +public class IdentityFormatter extends Formatter { @Override public String getName() { @@ -35,15 +35,4 @@ public String getDescription() { public String getExampleInput() { return "JabRef"; } - - @Override - public int hashCode() { - return defaultHashCode(); - } - - @Override - public boolean equals(Object obj) { - return defaultEquals(obj); - } - } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatter.java new file mode 100644 index 00000000000..7c1e03c2215 --- /dev/null +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatter.java @@ -0,0 +1,41 @@ +package org.jabref.logic.formatter.bibtexfields; + +import java.util.Objects; + +import org.jabref.logic.l10n.Localization; +import org.jabref.model.cleanup.Formatter; + +public class AddBracesFormatter extends Formatter { + + @Override + public String getName() { + return Localization.lang("Add enclosing braces"); + } + + @Override + public String getKey() { + return "add_braces"; + } + + @Override + public String format(String value) { + Objects.requireNonNull(value); + + if ((value.length() >= 2) && (value.charAt(0) != '{') && (value.charAt(value.length() - 1) != '}')) { + // Title does not start with { and does not end with }, then this formatter can be applied + return "{" + value + "}"; + } else { + return value; + } + } + + @Override + public String getDescription() { + return Localization.lang("Add braces encapsulating the complete field content."); + } + + @Override + public String getExampleInput() { + return "In CDMA"; + } +} diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/ClearFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/ClearFormatter.java index ddb2d98b095..3aa516c7fe8 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/ClearFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/ClearFormatter.java @@ -5,7 +5,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class ClearFormatter implements Formatter { +public class ClearFormatter extends Formatter { @Override public String getName() { diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatter.java index 1815d906aa9..a0dbd78195b 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatter.java @@ -6,7 +6,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class EscapeUnderscoresFormatter implements Formatter { +public class EscapeUnderscoresFormatter extends Formatter { private static final Pattern UNDERSCORES = Pattern.compile("_"); diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java index ba73bde75e3..060c1ee5b48 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java @@ -13,7 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class HtmlToLatexFormatter implements LayoutFormatter, Formatter { +public class HtmlToLatexFormatter extends Formatter implements LayoutFormatter { private static final Logger LOGGER = LoggerFactory.getLogger(HtmlToLatexFormatter.class); diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java index c598966e7c9..153ac1cbb0f 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java @@ -8,11 +8,11 @@ import org.apache.commons.lang3.StringEscapeUtils; @ApacheCommonsLang3Allowed("There is no equivalent in Google's Guava") -public class HtmlToUnicodeFormatter implements LayoutFormatter, Formatter { +public class HtmlToUnicodeFormatter extends Formatter implements LayoutFormatter { @Override public String getName() { - return "HTML to Unicode"; + return Localization.lang("HTML to Unicode"); } @Override diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatter.java index bcc5407d0a1..032914146b6 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatter.java @@ -5,7 +5,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class LatexCleanupFormatter implements Formatter { +public class LatexCleanupFormatter extends Formatter { private static final Pattern REMOVE_REDUNDANT = Pattern .compile("(?(\\d+:)?\\d+)(?:-{1,2}(?(\\d+:)?\\d+))?\\Z"); @@ -61,7 +61,7 @@ public String format(String value) { } // Remove pages prefix - String cleanValue = value.replace("pp.", "").replace("p.",""); + String cleanValue = value.replace("pp.", "").replace("p.", ""); // remove unwanted literals incl. whitespace cleanValue = cleanValue.replaceAll("\u2013|\u2014", "-").replaceAll(REJECT_LITERALS, ""); // try to find pages pattern @@ -87,14 +87,4 @@ public String getDescription() { public String getExampleInput() { return "1 - 2"; } - - @Override - public int hashCode() { - return defaultHashCode(); - } - - @Override - public boolean equals(Object obj) { - return defaultEquals(obj); - } } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatter.java index 4b9700c7616..d12871a8ca8 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatter.java @@ -10,7 +10,7 @@ /** * This class transforms ordinal numbers into LaTex superscripts. */ -public class OrdinalsToSuperscriptFormatter implements Formatter { +public class OrdinalsToSuperscriptFormatter extends Formatter { // find possible superscripts on word boundaries private static final Pattern SUPERSCRIPT_DETECT_PATTERN = Pattern.compile("\\b(\\d+)(st|nd|rd|th)\\b", @@ -61,5 +61,4 @@ public String getDescription() { public String getExampleInput() { return "11th"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java index 870deeffbb1..3b4dd551781 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RegexFormatter.java @@ -9,7 +9,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class RegexFormatter implements Formatter { +public class RegexFormatter extends Formatter { private static final Pattern PATTERN_ESCAPED_OPENING_CURLY_BRACE = Pattern.compile("\\\\\\{"); @@ -101,5 +101,4 @@ public static void setRegex(String rex) { String[] parts = rexToSet.split("\",\""); regex = parts; } - } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatter.java index 69e7c8c316a..11cf48722b1 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatter.java @@ -5,10 +5,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -/** - * Removes all matching braces around the string. - */ -public class RemoveBracesFormatter implements Formatter { +public class RemoveBracesFormatter extends Formatter { @Override public String getName() { diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatter.java index 8c8813fb72b..2356c02cab0 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatter.java @@ -9,7 +9,7 @@ /** * Removes all hyphenated line breaks in the string. */ -public class RemoveHyphenatedNewlinesFormatter implements Formatter { +public class RemoveHyphenatedNewlinesFormatter extends Formatter { private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-\r\n|-\n|-\r)"); @Override diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatter.java index cc70fd70dd3..c6942bf51ea 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatter.java @@ -9,7 +9,7 @@ /** * Removes all line breaks in the string. */ -public class RemoveNewlinesFormatter implements Formatter { +public class RemoveNewlinesFormatter extends Formatter { private static final Pattern LINEBREAKS = Pattern.compile("(\r?\n|\r)"); @Override diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java index d6bb7aff5cd..41147892971 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java @@ -11,7 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class UnicodeToLatexFormatter implements LayoutFormatter, Formatter { +public class UnicodeToLatexFormatter extends Formatter implements LayoutFormatter { private static final Logger LOGGER = LoggerFactory.getLogger(UnicodeToLatexFormatter.class); diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatter.java index 357f6f4d480..b32f14a1e11 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatter.java @@ -10,7 +10,7 @@ import org.jabref.logic.util.strings.StringLengthComparator; import org.jabref.model.cleanup.Formatter; -public class UnitsToLatexFormatter implements Formatter { +public class UnitsToLatexFormatter extends Formatter { private static final List UNIT_LIST = Arrays.asList( "A", // Ampere @@ -81,7 +81,6 @@ public class UnitsToLatexFormatter implements Formatter { private final List prefixUnitCombinations; - public UnitsToLatexFormatter() { prefixUnitCombinations = new ArrayList<>( UnitsToLatexFormatter.UNIT_LIST.size() * UnitsToLatexFormatter.UNIT_PREFIX_LIST.size()); @@ -112,7 +111,6 @@ public String format(String text) { result = result.replaceAll("([0-9])(" + listOfWord + ")", "$1\\{$2\\}"); // Only add brackets to keep case result = result.replaceAll("([0-9])-(" + listOfWord + ")", "$1\\\\mbox\\{-\\}\\{$2\\}"); // Replace hyphen with non-break hyphen result = result.replaceAll("([0-9]) (" + listOfWord + ")", "$1~\\{$2\\}"); // Replace space with a hard space - } return result; @@ -137,5 +135,4 @@ public String getName() { public String getKey() { return "units_to_latex"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatter.java index a5717038e5c..bf225dcf80d 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatter.java @@ -3,7 +3,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class CapitalizeFormatter implements Formatter { +public class CapitalizeFormatter extends Formatter { @Override public String getName() { @@ -37,5 +37,4 @@ public String getDescription() { public String getExampleInput() { return "I have {a} DREAM"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatter.java index b1b037b634c..239b35f8712 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatter.java @@ -3,7 +3,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class LowerCaseFormatter implements Formatter { +public class LowerCaseFormatter extends Formatter { @Override public String getName() { @@ -27,16 +27,6 @@ public String format(String input) { return title.toString(); } - @Override - public int hashCode() { - return defaultHashCode(); - } - - @Override - public boolean equals(Object obj) { - return defaultEquals(obj); - } - @Override public String getDescription() { return Localization.lang("Changes all letters to lower case."); @@ -46,5 +36,4 @@ public String getDescription() { public String getExampleInput() { return "KDE {Amarok}"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatter.java index 60109ca321a..c0b7c81612e 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatter.java @@ -8,7 +8,7 @@ import org.jabref.logic.util.strings.StringLengthComparator; import org.jabref.model.cleanup.Formatter; -public class ProtectTermsFormatter implements Formatter { +public class ProtectTermsFormatter extends Formatter { private final ProtectedTermsLoader protectedTermsLoader; @@ -56,5 +56,4 @@ public String getName() { public String getKey() { return "protect_terms"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java index 87342d63b3d..ab6098c44d2 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java @@ -3,7 +3,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class SentenceCaseFormatter implements Formatter { +public class SentenceCaseFormatter extends Formatter { @Override public String getName() { @@ -37,5 +37,4 @@ public String getDescription() { public String getExampleInput() { return "i have {Aa} DREAM"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatter.java index 16920a96dcf..3d0f8e0c819 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatter.java @@ -3,7 +3,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class TitleCaseFormatter implements Formatter { +public class TitleCaseFormatter extends Formatter { @Override public String getName() { @@ -49,5 +49,4 @@ public String getDescription() { public String getExampleInput() { return "{BPMN} conformance In open source Engines"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatter.java b/src/main/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatter.java index 0d88f2a8e78..6b743d7acf7 100644 --- a/src/main/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatter.java @@ -3,7 +3,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.cleanup.Formatter; -public class UpperCaseFormatter implements Formatter { +public class UpperCaseFormatter extends Formatter { @Override public String getName() { @@ -37,5 +37,4 @@ public String getDescription() { public String getExampleInput() { return "Kde {Amarok}"; } - } diff --git a/src/main/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatter.java b/src/main/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatter.java index 850be1050f2..136f8a38a39 100644 --- a/src/main/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatter.java @@ -8,7 +8,7 @@ /** * Replaces three or more authors with and others */ -public class MinifyNameListFormatter implements Formatter { +public class MinifyNameListFormatter extends Formatter { @Override public String getName() { return Localization.lang("Minify list of person names"); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index a0829e42406..24b0f338101 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -258,8 +258,10 @@ public List performSearch(String query) throws FetcherException { @Override public Optional performSearchById(String identifier) throws FetcherException { - return searchForEntryById(identifier).map( - (arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())); + String cleanedIdentifier = identifier.trim(); + cleanedIdentifier = identifier.replaceAll(" ", ""); + + return searchForEntryById(cleanedIdentifier).map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index 697df25f5fc..766f2570164 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -45,7 +45,6 @@ public HelpFile getHelpPage() { @Override public Optional performSearchById(String identifier) throws FetcherException { Optional doi = DOI.parse(identifier); - try { if (doi.isPresent()) { URL doiURL = new URL(doi.get().getURIAsASCIIString()); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IacrEprintFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IacrEprintFetcher.java index a87989b9481..af03b30b49f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IacrEprintFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IacrEprintFetcher.java @@ -37,8 +37,10 @@ public class IacrEprintFetcher implements IdBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(IacrEprintFetcher.class); private static final Pattern DATE_FROM_WEBSITE_AFTER_2000_PATTERN = Pattern.compile("[a-z ]+(\\d{1,2} [A-Za-z][a-z]{2} \\d{4})"); - private static final DateTimeFormatter DATE_FORMAT_WEBSITE_AFTER_2000 = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.US); private static final Pattern DATE_FROM_WEBSITE_BEFORE_2000_PATTERN = Pattern.compile("[A-Za-z ]+? ([A-Za-z][a-z]{2,10} \\d{1,2}(th|st|nd|rd)?, \\d{4})\\.?"); + private static final Pattern WITHOUT_LETTERS_SPACE = Pattern.compile("[^0-9/]"); + + private static final DateTimeFormatter DATE_FORMAT_WEBSITE_AFTER_2000 = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.US); private static final DateTimeFormatter DATE_FORMAT_WEBSITE_BEFORE_2000_LONG_MONTHS = DateTimeFormatter.ofPattern("MMMM d['th']['st']['nd']['rd'] yyyy", Locale.US); private static final DateTimeFormatter DATE_FORMAT_WEBSITE_BEFORE_2000_SHORT_MONTHS = DateTimeFormatter.ofPattern("MMM d['th']['st']['nd']['rd'] yyyy", Locale.US); private static final DateTimeFormatter DATE_FORMAT_BIBTEX = DateTimeFormatter.ISO_LOCAL_DATE; @@ -55,7 +57,7 @@ public IacrEprintFetcher(ImportFormatPreferences prefs) { @Override public Optional performSearchById(String identifier) throws FetcherException { - String identifierWithoutLettersAndSpaces = identifier.replaceAll("[^0-9/]", " ").trim(); + String identifierWithoutLettersAndSpaces = WITHOUT_LETTERS_SPACE.matcher(identifier).replaceAll(" ").trim(); if (!IDENTIFIER_PREDICATE.test(identifierWithoutLettersAndSpaces)) { throw new FetcherException(Localization.lang("Invalid identifier: '%0'.", identifier)); diff --git a/src/main/java/org/jabref/logic/integrity/DateChecker.java b/src/main/java/org/jabref/logic/integrity/DateChecker.java new file mode 100644 index 00000000000..83f0077b8aa --- /dev/null +++ b/src/main/java/org/jabref/logic/integrity/DateChecker.java @@ -0,0 +1,24 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.Date; +import org.jabref.model.strings.StringUtil; + +public class DateChecker implements ValueChecker { + + @Override + public Optional checkValue(String value) { + if (StringUtil.isBlank(value)) { + return Optional.empty(); + } + + Optional parsedDate = Date.parse(value); + if (!parsedDate.isPresent()) { + return Optional.of(Localization.lang("incorrect format")); + } + + return Optional.empty(); + } +} diff --git a/src/main/java/org/jabref/logic/integrity/FieldCheckers.java b/src/main/java/org/jabref/logic/integrity/FieldCheckers.java index 4358d4729a5..79cca452b11 100644 --- a/src/main/java/org/jabref/logic/integrity/FieldCheckers.java +++ b/src/main/java/org/jabref/logic/integrity/FieldCheckers.java @@ -50,6 +50,13 @@ private static Multimap getAllMap(BibDatabaseContext datab fieldCheckers.put(FieldName.YEAR, new YearChecker()); fieldCheckers.put(FieldName.KEY, new ValidBibtexKeyChecker(enforceLegalKey)); + if (databaseContext.isBiblatexMode()) { + fieldCheckers.put(FieldName.DATE, new DateChecker()); + fieldCheckers.put(FieldName.URLDATE, new DateChecker()); + fieldCheckers.put(FieldName.EVENTDATE, new DateChecker()); + fieldCheckers.put(FieldName.ORIGDATE, new DateChecker()); + } + return fieldCheckers; } diff --git a/src/main/java/org/jabref/logic/layout/format/LatexToUnicodeFormatter.java b/src/main/java/org/jabref/logic/layout/format/LatexToUnicodeFormatter.java index 4f3ced5f3c1..f16a5dd4c54 100644 --- a/src/main/java/org/jabref/logic/layout/format/LatexToUnicodeFormatter.java +++ b/src/main/java/org/jabref/logic/layout/format/LatexToUnicodeFormatter.java @@ -9,7 +9,7 @@ * This formatter converts LaTeX character sequences their equivalent unicode characters, * and removes other LaTeX commands without handling them. */ -public class LatexToUnicodeFormatter implements LayoutFormatter, Formatter { +public class LatexToUnicodeFormatter extends Formatter implements LayoutFormatter { @Override public String getName() { diff --git a/src/main/java/org/jabref/logic/layout/format/ReplaceUnicodeLigaturesFormatter.java b/src/main/java/org/jabref/logic/layout/format/ReplaceUnicodeLigaturesFormatter.java index f51c2e7b084..cce05eb57dc 100644 --- a/src/main/java/org/jabref/logic/layout/format/ReplaceUnicodeLigaturesFormatter.java +++ b/src/main/java/org/jabref/logic/layout/format/ReplaceUnicodeLigaturesFormatter.java @@ -9,7 +9,7 @@ import org.jabref.logic.util.strings.UnicodeLigaturesMap; import org.jabref.model.cleanup.Formatter; -public class ReplaceUnicodeLigaturesFormatter implements LayoutFormatter, Formatter { +public class ReplaceUnicodeLigaturesFormatter extends Formatter implements LayoutFormatter { private Map ligaturesMap; diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index e21a0fab82a..736cde821ec 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -22,17 +22,30 @@ import org.slf4j.LoggerFactory; public class PreferencesMigrations { - private static final Logger LOGGER = LoggerFactory.getLogger(PreferencesMigrations.class); private PreferencesMigrations() { } /** - * Migrate all preferences from net/sf/jabref to org/jabref + * Perform checks and changes for users with a preference set from an older JabRef version. */ - public static void upgradePrefsToOrgJabRef() { + public static void runMigrations() { + upgradePrefsToOrgJabRef(); + upgradeSortOrder(); + upgradeFaultyEncodingStrings(); + upgradeLabelPatternToBibtexKeyPattern(); + upgradeImportFileAndDirePatterns(); + upgradeStoredCustomEntryTypes(); + upgradeKeyBindingsToJavaFX(); + addCrossRefRelatedFieldsForAutoComplete(); + upgradeObsoleteLookAndFeels(); + } + /** + * Migrate all preferences from net/sf/jabref to org/jabref + */ + private static void upgradePrefsToOrgJabRef() { JabRefPreferences prefs = Globals.prefs; Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class); try { @@ -69,7 +82,7 @@ private static void copyPrefsRecursively(Preferences from, Preferences to) throw /** * Added from Jabref 2.11 beta 4 onwards to fix wrong encoding names */ - public static void upgradeFaultyEncodingStrings() { + private static void upgradeFaultyEncodingStrings() { JabRefPreferences prefs = Globals.prefs; String defaultEncoding = prefs.get(JabRefPreferences.DEFAULT_ENCODING); if (defaultEncoding == null) { @@ -110,7 +123,7 @@ public static void upgradeFaultyEncodingStrings() { * these preferences, but it is only used when the new preference does not * exist */ - public static void upgradeSortOrder() { + private static void upgradeSortOrder() { JabRefPreferences prefs = Globals.prefs; if (prefs.get(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER, null) == null) { @@ -138,8 +151,7 @@ public static void upgradeSortOrder() { /** * Migrate all customized entry types from versions <=3.7 */ - public static void upgradeStoredCustomEntryTypes() { - + private static void upgradeStoredCustomEntryTypes() { JabRefPreferences prefs = Globals.prefs; Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class); @@ -159,8 +171,7 @@ public static void upgradeStoredCustomEntryTypes() { /** * Migrate LabelPattern configuration from versions <=3.5 to new BibtexKeyPatterns */ - public static void upgradeLabelPatternToBibtexKeyPattern() { - + private static void upgradeLabelPatternToBibtexKeyPattern() { JabRefPreferences prefs = Globals.prefs; try { @@ -223,7 +234,7 @@ private static void migrateFileImportPattern(String oldStylePattern, String newS } } - public static void upgradeImportFileAndDirePatterns() { + static void upgradeImportFileAndDirePatterns() { JabRefPreferences prefs = Globals.prefs; Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class); @@ -244,7 +255,7 @@ public static void upgradeImportFileAndDirePatterns() { // the user defined old-style patterns, and the default pattern is "". } - public static void upgradeKeyBindingsToJavaFX() { + private static void upgradeKeyBindingsToJavaFX() { UnaryOperator replaceKeys = (str) -> { String result = str.replace("ctrl ", "ctrl+"); result = result.replace("shift ", "shift+"); @@ -261,7 +272,7 @@ public static void upgradeKeyBindingsToJavaFX() { } - public static void addCrossRefRelatedFieldsForAutoComplete() { + private static void addCrossRefRelatedFieldsForAutoComplete() { JabRefPreferences prefs = Globals.prefs; //LinkedHashSet because we want to retain the order and add new fields to the end Set keys = new LinkedHashSet<>(prefs.getStringList(JabRefPreferences.AUTOCOMPLETER_COMPLETE_FIELDS)); @@ -283,7 +294,7 @@ private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences ol prefs.putKeyPattern(keyPattern); } - public static void upgradeObsoleteLookAndFeels() { + private static void upgradeObsoleteLookAndFeels() { JabRefPreferences prefs = Globals.prefs; String currentLandF = prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL); @@ -304,5 +315,4 @@ public static void upgradeObsoleteLookAndFeels() { } }); } - } diff --git a/src/main/java/org/jabref/model/cleanup/Formatter.java b/src/main/java/org/jabref/model/cleanup/Formatter.java index 5b5dcd5673f..7fa32dacd94 100644 --- a/src/main/java/org/jabref/model/cleanup/Formatter.java +++ b/src/main/java/org/jabref/model/cleanup/Formatter.java @@ -1,28 +1,29 @@ package org.jabref.model.cleanup; /** - * The Formatter is used for a Filter design-pattern. Implementing classes have to accept a String and returned a - * formatted version of it. + * The Formatter is used for a Filter design-pattern. Extending classes have to accept a String and returned a + * formatted version of it. Implementations have to reside in the logic package. * * Example: * * "John von Neumann" => "von Neumann, John" * */ -public interface Formatter { +public abstract class Formatter { + /** * Returns a human readable name of the formatter usable for e.g. in the GUI * * @return the name of the formatter, always not null */ - String getName(); + public abstract String getName(); /** * Returns a unique key for the formatter that can be used for its identification * @return the key of the formatter, always not null */ - String getKey(); + public abstract String getKey(); /** * Formats a field value by with a particular formatter transformation. @@ -32,14 +33,14 @@ public interface Formatter { * @param value the input String * @return the formatted output String */ - String format(String value); + public abstract String format(String value); /** * Returns a description of the formatter. * * @return the description string, always non empty */ - String getDescription(); + public abstract String getDescription(); /** * Returns an example input string of the formatter. @@ -47,14 +48,15 @@ public interface Formatter { * * @return the example input string, always non empty */ - String getExampleInput(); + public abstract String getExampleInput(); /** * Returns a default hashcode of the formatter based on its key. * * @return the hash of the key of the formatter */ - default int defaultHashCode() { + @Override + public int hashCode() { return getKey().hashCode(); } @@ -64,7 +66,8 @@ default int defaultHashCode() { * @param obj the object to compare the formatter to * @return true if the object is a formatter with the same key */ - default boolean defaultEquals(Object obj) { + @Override + public boolean equals(Object obj) { if (obj instanceof Formatter) { return getKey().equals(((Formatter)obj).getKey()); } else { diff --git a/src/main/java/org/jabref/model/entry/Date.java b/src/main/java/org/jabref/model/entry/Date.java index fb558155984..b1655ad7c17 100644 --- a/src/main/java/org/jabref/model/entry/Date.java +++ b/src/main/java/org/jabref/model/entry/Date.java @@ -44,9 +44,17 @@ public Date(TemporalAccessor date) { */ public static Optional parse(String dateString) { Objects.requireNonNull(dateString); - List formatStrings = Arrays.asList("uuuu-M-d", "uuuu-M", "d-M-uuuu", "M/uu", "M/uuuu", "MMMM d, uuuu", + List formatStrings = Arrays.asList( + "uuuu-M-d", + "uuuu-M", + "d-M-uuuu", + "M-uuuu", + "M/uu", + "M/uuuu", + "MMMM d, uuuu", "MMMM, uuuu", - "d.M.uuuu", "uuuu.M.d", "uuuu"); + "d.M.uuuu", + "uuuu.M.d", "uuuu"); for (String formatString : formatStrings) { try { diff --git a/src/main/java/org/jabref/model/entry/identifier/DOI.java b/src/main/java/org/jabref/model/entry/identifier/DOI.java index 38c66733758..49c06bd8730 100644 --- a/src/main/java/org/jabref/model/entry/identifier/DOI.java +++ b/src/main/java/org/jabref/model/entry/identifier/DOI.java @@ -95,7 +95,9 @@ public DOI(String doi) { */ public static Optional parse(String doi) { try { - return Optional.of(new DOI(doi)); + String cleanedDOI = doi.trim(); + cleanedDOI = doi.replaceAll(" ", ""); + return Optional.of(new DOI(cleanedDOI)); } catch (IllegalArgumentException | NullPointerException e) { return Optional.empty(); } diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 06b03c9d74c..76ffddacd25 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -436,6 +436,7 @@ Export\ properties=Egenskaber for eksportfilter Export\ to\ clipboard=Eksporter til udklipsholder + Exporting=Eksporterer Extension=Efternavn diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 9f32fd7b8ea..2bf99a26419 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -448,6 +448,7 @@ Export\ properties=Eigenschaften für Exportfilter Export\ to\ clipboard=In die Zwischenablage kopieren + Exporting=Exportiere Extension=Erweiterung diff --git a/src/main/resources/l10n/JabRef_el.properties b/src/main/resources/l10n/JabRef_el.properties index 39ef44f2185..f820ae6111c 100644 --- a/src/main/resources/l10n/JabRef_el.properties +++ b/src/main/resources/l10n/JabRef_el.properties @@ -382,6 +382,7 @@ Export=Εξαγωγή + Full\ name=Πλήρες όνομα diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index a374292660b..159f4f4a85b 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1945,6 +1945,7 @@ Changes\ all\ letters\ to\ upper\ case.=Changes all letters to upper case. Changes\ the\ first\ letter\ of\ all\ words\ to\ capital\ case\ and\ the\ remaining\ letters\ to\ lower\ case.=Changes the first letter of all words to capital case and the remaining letters to lower case. Cleans\ up\ LaTeX\ code.=Cleans up LaTeX code. Converts\ HTML\ code\ to\ LaTeX\ code.=Converts HTML code to LaTeX code. +HTML\ to\ Unicode=HTML to Unicode Converts\ HTML\ code\ to\ Unicode.=Converts HTML code to Unicode. Converts\ LaTeX\ encoding\ to\ Unicode\ characters.=Converts LaTeX encoding to Unicode characters. Converts\ Unicode\ characters\ to\ LaTeX\ encoding.=Converts Unicode characters to LaTeX encoding. @@ -1956,6 +1957,7 @@ LaTeX\ to\ Unicode=LaTeX to Unicode Lower\ case=Lower case Minify\ list\ of\ person\ names=Minify list of person names Normalize\ date=Normalize date +Normalize\ en\ dashes=Normalize en dashes Normalize\ month=Normalize month Normalize\ month\ to\ BibTeX\ standard\ abbreviation.=Normalize month to BibTeX standard abbreviation. Normalize\ names\ of\ persons=Normalize names of persons @@ -1963,8 +1965,11 @@ Normalize\ page\ numbers=Normalize page numbers Normalize\ pages\ to\ BibTeX\ standard.=Normalize pages to BibTeX standard. Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Normalizes lists of persons to the BibTeX standard. Normalizes\ the\ date\ to\ ISO\ date\ format.=Normalizes the date to ISO date format. +Normalizes\ the\ en\ dashes.=Normalizes the en dashes. Ordinals\ to\ LaTeX\ superscript=Ordinals to LaTeX superscript Protect\ terms=Protect terms +Add\ enclosing\ braces=Add enclosing braces +Add\ braces\ encapsulating\ the\ complete\ field\ content.=Add braces encapsulating the complete field content. Remove\ enclosing\ braces=Remove enclosing braces Removes\ braces\ encapsulating\ the\ complete\ field\ content.=Removes braces encapsulating the complete field content. Sentence\ case=Sentence case diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index f76e6a89319..15b6fd795bd 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -446,6 +446,7 @@ Export\ properties=Exportar propiedades Export\ to\ clipboard=Exportar al portapapeles + Exporting=Exportando Extension=Extensión diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index 983cb004005..33676498c2d 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -320,6 +320,7 @@ Donate\ to\ JabRef=هدیه دادن به JabRef + Manage\ external\ file\ types=مدیریت نوع پرونده‌های خارجی diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 2dbfab36e87..e2891e720bb 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1946,6 +1946,7 @@ Changes\ all\ letters\ to\ upper\ case.=Convertit toutes les lettres en majuscul Changes\ the\ first\ letter\ of\ all\ words\ to\ capital\ case\ and\ the\ remaining\ letters\ to\ lower\ case.=Convertit en majuscules la première lettre de tous les mots, et les autres lettres en minuscules. Cleans\ up\ LaTeX\ code.=Nettoyer le code LaTeX. Converts\ HTML\ code\ to\ LaTeX\ code.=Convertit le code HTML en code LaTeX. +HTML\ to\ Unicode=HTML vers Unicode Converts\ HTML\ code\ to\ Unicode.=Convertit du code HTML en Unicode. Converts\ LaTeX\ encoding\ to\ Unicode\ characters.=Convertit l'encodage LaTeX en caractères Unicode. Converts\ Unicode\ characters\ to\ LaTeX\ encoding.=Convertit les caractères Unicode en encodage LaTeX. @@ -1966,6 +1967,8 @@ Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Harmonise les listes Normalizes\ the\ date\ to\ ISO\ date\ format.=Harmonise la date au format de date ISO. Ordinals\ to\ LaTeX\ superscript=Numéros ordinaux vers exposants LaTeX Protect\ terms=Protéger les termes +Add\ enclosing\ braces=Ajouter des accolades englobantes +Add\ braces\ encapsulating\ the\ complete\ field\ content.=Ajoute des accolades encapsulant l'ensemble du contenu du champ. Remove\ enclosing\ braces=Supprimer les paires d'accolades Removes\ braces\ encapsulating\ the\ complete\ field\ content.=Supprimer les accolades autour d'un contenu de champ entier. Sentence\ case=Casse de la phrase diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 1aca67669b7..6d2a2a6b766 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -445,6 +445,7 @@ Export\ properties=Ekspor properti Export\ to\ clipboard=Ekspor ke papan klip + Exporting=Proses mengekspor Extension=Ekstensi diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 04e124f2ed3..4930004462b 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -446,6 +446,7 @@ Export\ properties=Esporta proprietà Export\ to\ clipboard=Esporta negli appunti + Exporting=Esportazione in corso Extension=Estensione diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index e32b5ce4e75..7fa1a9680d5 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -448,6 +448,7 @@ Export\ properties=特性を書き出す Export\ to\ clipboard=クリップボードに書き出す + Exporting=書き出し中 Extension=拡張子 diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index fccc9a8b3da..d8cdb878fef 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -403,6 +403,7 @@ Export\ properties=Eigenschappen exporteren Export\ to\ clipboard=Exporteer naar klembord + Exporting=Exporteren... External\ changes=Externe wijzigingen diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 78f1c6910b1..2e331f509b7 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -433,6 +433,7 @@ Export\ properties=Egenskaper for eksportfilter Export\ to\ clipboard=Eksporter til utklippstavle + Exporting=Eksporterer Extension=Etternavn diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index b076bf11292..2c89c578847 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -439,6 +439,7 @@ Export\ properties=Propriedades de exportação Export\ to\ clipboard=Exportar para a área de transferência + Exporting=Exportando Extension=Extensão diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 60ddda56ba2..160eee78776 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -440,6 +440,7 @@ Export\ properties=Экспорт свойств Export\ to\ clipboard=Экспорт в буфер обмена + Exporting=Выполняется экспорт Extension=Расширение diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 585b2f0a79a..1e5ed156737 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -429,6 +429,7 @@ Export\ properties=Exportera egenskaper Export\ to\ clipboard=Exportera till utklipp + Exporting=Exporterar Extension=Filändelse diff --git a/src/main/resources/l10n/JabRef_tl.properties b/src/main/resources/l10n/JabRef_tl.properties index 339f1200e98..9fe70bd6b6d 100644 --- a/src/main/resources/l10n/JabRef_tl.properties +++ b/src/main/resources/l10n/JabRef_tl.properties @@ -446,6 +446,7 @@ Export\ properties=Pagpapalabas ng mga katangian Export\ to\ clipboard=Pagpapalabas sa clipboard + Exporting=Ang pagpapalabas Extension=Ekstenyon diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index b0f4bfc6c0d..04da7a81fcb 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -446,6 +446,7 @@ Export\ properties=Özellikleri dışa aktar Export\ to\ clipboard=Panoya aktar + Exporting=Dışa aktarılıyor Extension=Uzantı diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index ef371c89207..34106b26aa8 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -37,6 +37,7 @@ Accept\ change=Chấp nhận thay đổi Action=Hành động +What\ is\ Mr.\ DLib?=Ông DLib là gì? Add=Thêm @@ -46,7 +47,9 @@ The\ path\ need\ not\ be\ on\ the\ classpath\ of\ JabRef.=Đường dẫn không Add\ a\ (compiled)\ custom\ Importer\ class\ from\ a\ ZIP-archive.=Thêm một lớp ĐịnhdạngNhập tùy biến (được biên dịch) từ một tập tin-zip. The\ ZIP-archive\ need\ not\ be\ on\ the\ classpath\ of\ JabRef.=Tập tin-zip không được trùng với đường dẫn lớp của JabRef. +Add\ a\ regular\ expression\ for\ the\ key\ pattern.=Thêm một biểu thức chính quy cho mẫu chính. +Add\ selected\ entries\ to\ this\ group=Thêm các mục đã chọn vào nhóm này Add\ from\ folder=Thêm từ thư mục @@ -74,6 +77,7 @@ All\ entries\ of\ this\ type\ will\ be\ declared\ typeless.\ Continue?=Tất c All\ fields=Tất cả các dữ liệu +Always\ reformat\ BIB\ file\ on\ save\ and\ export=Luôn luôn định dạng lại file BIB khi lưu và xuất A\ SAX\ exception\ occurred\ while\ parsing\ '%0'\:=Một lỗi SAXException xảy ra khi đang phân tách '%0'\: @@ -145,6 +149,7 @@ Broken\ link=Liên kết bị đứt Browse=Duyệt by=theo +The\ conflicting\ fields\ of\ these\ entries\ will\ be\ merged\ into\ the\ 'Comment'\ field.=Các trường xung đột của các mục này sẽ được sáp nhập vào trường 'Nhận xét'. Cancel=Hủy @@ -207,6 +212,7 @@ Color\ for\ marking\ incomplete\ entries=Màu để đánh dấu các mục chư Column\ width=Chiều rộng cột Command\ line\ id=Chỉ số (id) của dòng lệnh +Comments=Nhận xét Contained\ in=Chứa trong @@ -439,6 +445,7 @@ Export\ properties=Các tính chất xuất Export\ to\ clipboard=Xuất ra bộ nhớ tạm + Exporting=Đang xuất Extension=Đuôi mở rộng diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index e959a85e92e..6763251641a 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -446,6 +446,7 @@ Export\ properties=导出属性 Export\ to\ clipboard=导出到剪贴板 + Exporting=正在导出 Extension=扩展名 diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java index 65a4e850b58..17134b98dc8 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/BibtexKeyGeneratorTest.java @@ -301,6 +301,7 @@ public void testFirstAuthor() { assertEquals("", BibtexKeyGenerator.firstAuthor("")); } + @Test public void testFirstAuthorNull() { assertThrows(NullPointerException.class, () -> BibtexKeyGenerator.firstAuthor(null)); } @@ -424,6 +425,7 @@ public void testAuthIniN() { assertEquals("Newton", BibtexKeyGenerator.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 7)); } + @Test public void testAuthIniNNull() { assertThrows(NullPointerException.class, () -> BibtexKeyGenerator.authIniN(null, 3)); } @@ -514,6 +516,7 @@ public void authNM() { assertEquals("", BibtexKeyGenerator.authNofMth("", 2, 4)); } + @Test public void authNMThrowsNPE() { assertThrows(NullPointerException.class, () -> BibtexKeyGenerator.authNofMth(null, 2, 4)); } @@ -709,6 +712,7 @@ public void testPagePrefix() { assertEquals("", BibtexKeyGenerator.pagePrefix("43+")); } + @Test public void testPagePrefixNull() { assertThrows(NullPointerException.class, () -> BibtexKeyGenerator.pagePrefix(null)); } @@ -725,6 +729,7 @@ public void testLastPage() { assertEquals("43", BibtexKeyGenerator.lastPage("43+")); } + @Test public void testLastPageNull() { assertThrows(NullPointerException.class, () -> BibtexKeyGenerator.lastPage(null)); } @@ -767,23 +772,30 @@ public void veryShortTitle() { */ @Test public void shortTitle() { - // shortTitle is getTitleWords with "3" as count + // shortTitle is getTitleWords with "3" as count and removed small words int count = 3; assertEquals("application migration effort", - BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); - assertEquals("BPEL conformance in", BibtexKeyGenerator.getTitleWords(count, - TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); - assertEquals("Process Viewing Patterns", BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED)); - assertEquals("BPMN Conformance in", - BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); - assertEquals("The Difference Between", BibtexKeyGenerator.getTitleWords(count, - TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); - assertEquals("Cloud Computing: The", - BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH))); + assertEquals("BPEL conformance open", + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON))); + assertEquals("Process Viewing Patterns", + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED))); + assertEquals("BPMN Conformance Open", + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD))); + assertEquals("Difference Graph Based", + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING))); + assertEquals("Cloud Computing: Next", + BibtexKeyGenerator.getTitleWords(count, + BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON))); assertEquals("Towards Choreography based", - BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); - assertEquals("On the Measurement", - BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); + BibtexKeyGenerator.getTitleWords(count, BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD))); + assertEquals("Measurement Design Time", + BibtexKeyGenerator.getTitleWords(count, BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS))); } /** @@ -935,7 +947,7 @@ public void testApplyModifiers() { BibEntry entry = new BibEntry(); entry.setField("title", "Green Scheduling of Whatever"); assertEquals("GSo", BibtexKeyGenerator.generateKey(entry, "shorttitleINI")); - assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry, "shorttitle", + assertEquals("GreenSchedulingWhatever", BibtexKeyGenerator.generateKey(entry, "shorttitle", new BibDatabase())); } @@ -950,7 +962,7 @@ public void testcrossrefShorttitle() { database.insertEntry(entry1); entry2.setField("title", "Green Scheduling of Whatever"); - assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry1, "shorttitle", + assertEquals("GreenSchedulingWhatever", BibtexKeyGenerator.generateKey(entry1, "shorttitle", database)); } diff --git a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java index 345d568ff5d..46bea56b6ea 100644 --- a/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java +++ b/src/test/java/org/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java @@ -231,7 +231,7 @@ public void generateKeyTitleAbbr() { public void generateKeyShorttitle() { bibtexKeyPattern.setDefaultValue("[shorttitle]"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("awesomepaperJabRef"), entry.getCiteKeyOptional()); } @Test @@ -239,7 +239,7 @@ public void generateKeyShorttitleLowerModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:lower]"); entry.setField("title", "An aweSOme Paper on JabRef"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("anawesomepaper"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("awesomepaperjabref"), entry.getCiteKeyOptional()); } @Test @@ -247,7 +247,7 @@ public void generateKeyShorttitleUpperModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:upper]"); entry.setField("title", "An aweSOme Paper on JabRef"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("ANAWESOMEPAPER"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("AWESOMEPAPERJABREF"), entry.getCiteKeyOptional()); } @Test @@ -255,7 +255,7 @@ public void generateKeyShorttitleTitleCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:title_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("AwesomePaperJabref"), entry.getCiteKeyOptional()); } @Test @@ -263,7 +263,7 @@ public void generateKeyShorttitleSentenceCaseModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:sentence_case]"); entry.setField("title", "An aweSOme Paper on JabRef"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("Awesomepaperjabref"), entry.getCiteKeyOptional()); } @Test @@ -271,7 +271,7 @@ public void generateKeyShorttitleCapitalizeModified() { bibtexKeyPattern.setDefaultValue("[shorttitle:capitalize]"); entry.setField("title", "An aweSOme Paper on JabRef"); new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry); - assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional()); + assertEquals(Optional.of("AwesomePaperJabref"), entry.getCiteKeyOptional()); } @Test diff --git a/src/test/java/org/jabref/logic/formatter/FormatterTest.java b/src/test/java/org/jabref/logic/formatter/FormatterTest.java index 404759a64e4..b662ccef1cf 100644 --- a/src/test/java/org/jabref/logic/formatter/FormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/FormatterTest.java @@ -1,34 +1,17 @@ package org.jabref.logic.formatter; import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.Stream; -import org.jabref.logic.formatter.bibtexfields.ClearFormatter; -import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; -import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; -import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; -import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; -import org.jabref.logic.formatter.bibtexfields.RegexFormatter; -import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter; -import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; -import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter; -import org.jabref.logic.formatter.casechanger.CapitalizeFormatter; -import org.jabref.logic.formatter.casechanger.LowerCaseFormatter; import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter; -import org.jabref.logic.formatter.casechanger.SentenceCaseFormatter; -import org.jabref.logic.formatter.casechanger.TitleCaseFormatter; -import org.jabref.logic.formatter.casechanger.UpperCaseFormatter; -import org.jabref.logic.formatter.minifier.MinifyNameListFormatter; -import org.jabref.logic.layout.format.LatexToUnicodeFormatter; import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.protectedterms.ProtectedTermsPreferences; import org.jabref.model.cleanup.Formatter; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -47,8 +30,22 @@ public static void setUp() { protectedTermsLoader = new ProtectedTermsLoader( new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); + } - + /** + * When a new formatter is added by copy and pasting another formatter, it may happen that the getKey() method is not adapted. This results in duplicate keys, which this test tests for. + */ + @Test + public void allFormatterKeysAreUnique() { + // idea for uniqueness checking by https://stackoverflow.com/a/44032568/873282 + assertEquals(Collections.emptyList(), + getFormatters().collect(Collectors.groupingBy( + formatter -> formatter.getKey(), + Collectors.counting())) + .entrySet().stream() + .filter(e -> e.getValue() > 1) + .map(Map.Entry::getKey) + .collect(Collectors.toList())); } @ParameterizedTest @@ -107,33 +104,16 @@ public void getExampleInputAlwaysNonEmpty(Formatter formatter) { public static Stream getFormatters() { // all classes implementing {@link net.sf.jabref.model.cleanup.Formatter} - // sorted alphabetically // Alternative: Use reflection - https://github.com/ronmamo/reflections // @formatter:off - return Stream.of( - new CapitalizeFormatter(), - new ClearFormatter(), - new HtmlToLatexFormatter(), - new HtmlToUnicodeFormatter(), - new IdentityFormatter(), - new LatexCleanupFormatter(), - new LatexToUnicodeFormatter(), - new LowerCaseFormatter(), - new MinifyNameListFormatter(), - new NormalizeDateFormatter(), - new NormalizeMonthFormatter(), - new NormalizeNamesFormatter(), - new NormalizePagesFormatter(), - new OrdinalsToSuperscriptFormatter(), - new ProtectTermsFormatter(protectedTermsLoader), - new RegexFormatter(), - new RemoveBracesFormatter(), - new SentenceCaseFormatter(), - new TitleCaseFormatter(), - new UnicodeToLatexFormatter(), - new UnitsToLatexFormatter(), - new UpperCaseFormatter()); - + return Stream.concat( + Formatters.getAll().stream(), + // following formatters are not contained in the list of all formatters, because + // - the IdentityFormatter is not offered to the user, + // - the ProtectTermsFormatter needs more configuration + Stream.of( + new IdentityFormatter(), + new ProtectTermsFormatter(protectedTermsLoader))); // @formatter:on } } diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java new file mode 100644 index 00000000000..7bb7788e462 --- /dev/null +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java @@ -0,0 +1,76 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} + */ +class AddBracesFormatterTest { + + private AddBracesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new AddBracesFormatter(); + } + + @Test + public void formatAddsSingleEnclosingBraces() { + assertEquals("{test}", formatter.format("test")); + } + + @Test + public void formatKeepsUnmatchedBracesAtBeginning() { + assertEquals("{test", formatter.format("{test")); + } + + @Test + public void formatKeepsUnmatchedBracesAtEnd() { + assertEquals("test}", formatter.format("test}")); + } + + @Test + public void formatKeepsShortString() { + assertEquals("t", formatter.format("t")); + } + + @Test + public void formatKeepsEmptyString() { + assertEquals("", formatter.format("")); + } + + @Test + public void formatKeepsDoubleEnclosingBraces() { + assertEquals("{{test}}", formatter.format("{{test}}")); + } + + @Test + public void formatKeepsTripleEnclosingBraces() { + assertEquals("{{{test}}}", formatter.format("{{{test}}}")); + } + + @Test + public void formatKeepsNonMatchingBraces() { + assertEquals("{A} and {B}", formatter.format("{A} and {B}")); + } + + @Test + public void formatKeepsOnlyMatchingBraces() { + assertEquals("{{A} and {B}}", formatter.format("{{A} and {B}}")); + } + + @Test + public void formatDoesNotRemoveBracesInBrokenString() { + // We opt here for a conservative approach although one could argue that "A} and {B}" is also a valid return + assertEquals("{A} and {B}}", formatter.format("{A} and {B}}")); + } + + @Test + public void formatExample() { + assertEquals("{In CDMA}", formatter.format(formatter.getExampleInput())); + } + +} diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java new file mode 100644 index 00000000000..ace49c02398 --- /dev/null +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java @@ -0,0 +1,54 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} + */ +public class NormalizeEnDashesFormatterTest { + + private NormalizeEnDashesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeEnDashesFormatter(); + } + + @Test + public void formatExample() { + assertEquals("Winery -- A Modeling Tool for TOSCA-based Cloud Applications", formatter.format(formatter.getExampleInput())); + } + + @Test + public void formatExampleOfChangelog() { + assertEquals("Example -- illustrative", formatter.format("Example - illustrative")); + } + + @Test + public void dashesWithinWordsAreKept() { + assertEquals("Example-illustrative", formatter.format("Example-illustrative")); + } + + @Test + public void dashesPreceededByASpaceAreKept() { + assertEquals("Example -illustrative", formatter.format("Example -illustrative")); + } + + @Test + public void dashesFollowedByASpaceAreKept() { + assertEquals("Example- illustrative", formatter.format("Example- illustrative")); + } + + @Test + public void dashAtTheBeginningIsKept() { + assertEquals("- illustrative", formatter.format("- illustrative")); + } + + @Test + public void dashAtTheEndIsKept() { + assertEquals("Example-", formatter.format("Example-")); + } +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index a79142ffc34..3a438659b31 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -168,6 +168,11 @@ public void searchEntryByIdWith4DigitsAndPrefix() throws Exception { assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("arXiv:1405.2249")); } + @Test + public void searchEntryByIdWith4DigitsAndPrefixAndNotTrimmed() throws Exception { + assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("arXiv : 1405. 2249")); + } + @Test public void searchEntryByIdWith5Digits() throws Exception { assertEquals(Optional.of( @@ -186,4 +191,5 @@ public void searchIdentifierForSlicePaper() throws Exception { assertEquals(ArXivIdentifier.parse("1405.2249v1"), finder.findIdentifier(sliceTheoremPaper)); } + } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index d268730212b..177d48b7123 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -48,6 +48,7 @@ public void setUp() { bibEntryDecker2007.setField("doi", "10.1109/icws.2007.59"); } + @Test public void testGetName() { assertEquals("DOI", fetcher.getName()); @@ -80,4 +81,10 @@ public void testPerformSearchInvalidDOI() { assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } + + @Test + public void testPerformSearchNonTrimmedDOI() throws FetcherException { + Optional fetchedEntry = fetcher.performSearchById("http s://doi.org/ 10.1109 /ICWS .2007.59 "); + assertEquals(Optional.of(bibEntryDecker2007), fetchedEntry); + } } diff --git a/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java b/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java new file mode 100644 index 00000000000..21cf8306ef4 --- /dev/null +++ b/src/test/java/org/jabref/logic/integrity/DateCheckerTest.java @@ -0,0 +1,28 @@ +package org.jabref.logic.integrity; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class DateCheckerTest { + + private DateChecker checker; + + @BeforeEach + void setUp() { + checker = new DateChecker(); + } + + @Test + void complainsAboutInvalidIsoLikeDate() { + assertEquals(Optional.of("incorrect format"), checker.checkValue("2018-04-21TZ")); + } + + @Test + void acceptsValidIsoDate() { + assertEquals(Optional.empty(), checker.checkValue("2018-04-21")); + } +} diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationBundleForTEst.java b/src/test/java/org/jabref/logic/l10n/LocalizationBundleForTest.java similarity index 100% rename from src/test/java/org/jabref/logic/l10n/LocalizationBundleForTEst.java rename to src/test/java/org/jabref/logic/l10n/LocalizationBundleForTest.java diff --git a/src/test/java/org/jabref/model/entry/DateTest.java b/src/test/java/org/jabref/model/entry/DateTest.java index 3234ea84280..3e8ba6127e7 100644 --- a/src/test/java/org/jabref/model/entry/DateTest.java +++ b/src/test/java/org/jabref/model/entry/DateTest.java @@ -1,6 +1,8 @@ package org.jabref.model.entry; import java.time.LocalDate; +import java.time.Year; +import java.time.YearMonth; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -8,15 +10,34 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -public class DateTest { +class DateTest { @Test - public void parseCorrectlyDayMonthYearDate() throws Exception { + void parseCorrectlyDayMonthYearDate() throws Exception { Date expected = new Date(LocalDate.of(2014, 6, 19)); assertEquals(Optional.of(expected), Date.parse("19-06-2014")); } - public void parseDateNull() { - assertThrows(NullPointerException.class, () -> assertEquals(Optional.empty(), Date.parse(null))); + @Test + void parseCorrectlyMonthYearDate() throws Exception { + Date expected = new Date(YearMonth.of(2014, 6)); + assertEquals(Optional.of(expected), Date.parse("06-2014")); + } + + @Test + void parseCorrectlyYearMonthDate() throws Exception { + Date expected = new Date(YearMonth.of(2014, 6)); + assertEquals(Optional.of(expected), Date.parse("2014-06")); + } + + @Test + void parseCorrectlyYearDate() throws Exception { + Date expected = new Date(Year.of(2014)); + assertEquals(Optional.of(expected), Date.parse("2014")); + } + + @Test + void parseDateNull() { + assertThrows(NullPointerException.class, () -> Date.parse(null)); } } diff --git a/src/test/java/org/jabref/model/entry/identifier/DOITest.java b/src/test/java/org/jabref/model/entry/identifier/DOITest.java index 457b779ff75..e1e8636c1f1 100644 --- a/src/test/java/org/jabref/model/entry/identifier/DOITest.java +++ b/src/test/java/org/jabref/model/entry/identifier/DOITest.java @@ -143,4 +143,12 @@ public void findDoiInsideArbitraryText() { public void noDOIFoundInsideArbitraryText() { assertEquals(Optional.empty(), DOI.findInText("text without 28282 a doi")); } + + @Test + public void parseDOIWithWhiteSpace() { + String doiWithSpace = "https : / / doi.org / 10 .1109 /V LHCC.20 04.20"; + assertEquals("https://doi.org/10.1109/VLHCC.2004.20", DOI.parse(doiWithSpace).get().getURIAsASCIIString()); + + } + }