diff --git a/CHANGELOG.md b/CHANGELOG.md index 39e94d1044e..c44f2a61591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - The CSL preview styles now also support displaying data from cross references entries that are linked via the `crossref` field [#7378](https://github.com/JabRef/jabref/issues/7378) - We made the Search button in Web Search wider. We also skewed the panel titles to the left [#8397](https://github.com/JabRef/jabref/issues/8397) - We introduced a preference to disable fulltext indexing [#8468](https://github.com/JabRef/jabref/issues/8468) +- When exporting entries, the encoding is always UTF-8 +- When embedding BibTeX data into a PDF, the encoding is always UTF-8 ### Fixed @@ -25,12 +27,14 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where an exception could occur when saving the preferences [#7614](https://github.com/JabRef/jabref/issues/7614) - We fixed an issue where "Copy DOI url" in the right-click menu of the Entry List would just copy the DOI and not the DOI url. [#8389](https://github.com/JabRef/jabref/issues/8389) - We fixed an issue where opening the console from the drop-down menu would cause an exception. [#8466](https://github.com/JabRef/jabref/issues/8466) +- We fixed an issue when reading non-UTF-8 encoded. When no encoding header is present, the encoding is now detected from the file content (and the preference option is disregarded) [#8417](https://github.com/JabRef/jabref/issues/8417) - We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448) - We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513) ### Removed - We removed the option to copy CSL Citation styles data as `XSL_FO`, `ASCIIDOC`, and `RTF` as these have not been working since a long time and are no longer supported in the external library used for processing the styles [#7378](https://github.com/JabRef/jabref/issues/7378) +- We removed the option to configure the default encoding. The default encoding is now hard-coded to the modern UTF-8 encoding. diff --git a/build.gradle b/build.gradle index dbb0780350b..89df4fbbacb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,8 @@ -import groovy.json.JsonSlurper import org.gradle.internal.os.OperatingSystem import org.jabref.build.JournalAbbreviationConverter import org.jabref.build.xjc.XjcPlugin import org.jabref.build.xjc.XjcTask -// to update the gradle wrapper, execute -// ./gradlew wrapper --gradle-version=6.0 --distribution-type=bin - plugins { id 'application' @@ -122,6 +118,7 @@ dependencies { implementation 'com.h2database:h2-mvstore:2.1.210' implementation group: 'org.apache.tika', name: 'tika-core', version: '2.3.0' + implementation 'com.ibm.icu:icu4j-charset:70.1' // required for reading write-protected PDFs - see https://github.com/JabRef/jabref/pull/942#issuecomment-209252635 implementation 'org.bouncycastle:bcprov-jdk15on:1.70' diff --git a/crowdin.yml b/crowdin.yml index 1ec4fb7a69c..90c30e89519 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -4,6 +4,5 @@ files: languages_mapping: two_letters_code: pt-BR: pt_BR - id: in zh-CN: zh_CN zh-TW: zh_TW diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 39910a08fac..043d325694c 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -91,6 +91,7 @@ requires org.apache.tika.core; requires pdfbox; requires xmpbox; + requires com.ibm.icu; requires flexmark; requires flexmark.ext.gfm.strikethrough; @@ -104,5 +105,4 @@ requires com.fasterxml.jackson.dataformat.yaml; requires com.fasterxml.jackson.datatype.jsr310; requires net.harawata.appdirs; - } diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index adbf9be7f42..681b9155a30 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -1,7 +1,7 @@ package org.jabref.cli; import java.io.IOException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -236,7 +236,6 @@ private List processArguments() { if (!loaded.isEmpty()) { writeMetadatatoPdf(loaded, cli.getWriteMetadatatoPdf(), - preferencesService.getGeneralPreferences().getDefaultEncoding(), preferencesService.getXmpPreferences(), preferencesService.getFilePreferences(), preferencesService.getGeneralPreferences().getDefaultBibDatabaseMode(), @@ -271,7 +270,7 @@ private List processArguments() { return loaded; } - private void writeMetadatatoPdf(List loaded, String filesAndCitekeys, Charset encoding, XmpPreferences xmpPreferences, FilePreferences filePreferences, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldWriterPreferences fieldWriterPreferences, boolean writeXMP, boolean embeddBibfile) { + private void writeMetadatatoPdf(List loaded, String filesAndCitekeys, XmpPreferences xmpPreferences, FilePreferences filePreferences, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldWriterPreferences fieldWriterPreferences, boolean writeXMP, boolean embeddBibfile) { if (loaded.isEmpty()) { LOGGER.error("The write xmp option depends on a valid import option."); return; @@ -285,7 +284,7 @@ private void writeMetadatatoPdf(List loaded, String filesAndCiteke if ("all".equals(filesAndCitekeys)) { for (BibEntry entry : dataBase.getEntries()) { - writeMetadatatoPDFsOfEntry(databaseContext, entry.getCitationKey().orElse(""), entry, encoding, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); + writeMetadatatoPDFsOfEntry(databaseContext, entry.getCitationKey().orElse(""), entry, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); } return; } @@ -300,22 +299,22 @@ private void writeMetadatatoPdf(List loaded, String filesAndCiteke } } - writeMetadatatoPdfByCitekey(databaseContext, dataBase, citeKeys, encoding, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); - writeMetadatatoPdfByFileNames(databaseContext, dataBase, pdfs, encoding, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); + writeMetadatatoPdfByCitekey(databaseContext, dataBase, citeKeys, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); + writeMetadatatoPdfByFileNames(databaseContext, dataBase, pdfs, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); } - private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, String citeKey, BibEntry entry, Charset encoding, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { + private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, String citeKey, BibEntry entry, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { try { if (writeXMP) { - if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { + if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, filePreferences, entry, List.of(entry))) { System.out.printf("Successfully written XMP metadata on at least one linked file of %s%n", citeKey); } else { System.err.printf("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); } } if (embeddBibfile) { - if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { + if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, filePreferences, entry, List.of(entry))) { System.out.printf("Successfully embedded metadata on at least one linked file of %s%n", citeKey); } else { System.out.printf("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); @@ -326,7 +325,7 @@ private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, Stri } } - private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, BibDatabase dataBase, Vector citeKeys, Charset encoding, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { + private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, BibDatabase dataBase, Vector citeKeys, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { for (String citeKey : citeKeys) { List bibEntryList = dataBase.getEntriesByCitationKey(citeKey); if (bibEntryList.isEmpty()) { @@ -334,12 +333,12 @@ private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, Bib continue; } for (BibEntry entry : bibEntryList) { - writeMetadatatoPDFsOfEntry(databaseContext, citeKey, entry, encoding, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); + writeMetadatatoPDFsOfEntry(databaseContext, citeKey, entry, filePreferences, xmpPdfExporter, embeddedBibFilePdfExporter, writeXMP, embeddBibfile); } } } - private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, BibDatabase dataBase, Vector fileNames, Charset encoding, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { + private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, BibDatabase dataBase, Vector fileNames, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) { for (String fileName : fileNames) { Path filePath = Path.of(fileName); if (!filePath.isAbsolute()) { @@ -348,14 +347,14 @@ private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, B if (Files.exists(filePath)) { try { if (writeXMP) { - if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { + if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, filePreferences, filePath)) { System.out.printf("Successfully written XMP metadata of at least one entry to %s%n", fileName); } else { System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } if (embeddBibfile) { - if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { + if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, filePreferences, filePath)) { System.out.printf("Successfully embedded XMP metadata of at least one entry to %s%n", fileName); } else { System.out.printf("File %s is not linked to any entry in database.%n", fileName); @@ -410,9 +409,7 @@ private boolean exportMatches(List loaded) { // We have an TemplateExporter instance: try { System.out.println(Localization.lang("Exporting") + ": " + data[1]); - exporter.get().export(databaseContext, Path.of(data[1]), - databaseContext.getMetaData().getEncoding().orElse(preferencesService.getGeneralPreferences().getDefaultEncoding()), - matches); + exporter.get().export(databaseContext, Path.of(data[1]), matches); } catch (Exception ex) { System.err.println(Localization.lang("Could not export file") + " '" + data[1] + "': " + Throwables.getStackTraceAsString(ex)); @@ -455,7 +452,6 @@ private List importAndOpenFiles() { try { pr = OpenDatabase.loadDatabase( Path.of(aLeftOver), - preferencesService.getGeneralPreferences(), preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); } catch (IOException ex) { @@ -530,7 +526,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { System.out.println(Localization.lang("Saving") + ": " + subName); GeneralPreferences generalPreferences = preferencesService.getGeneralPreferences(); SavePreferences savePreferences = preferencesService.getSavePreferences(); - AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), generalPreferences.getDefaultEncoding()); + AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), StandardCharsets.UTF_8); BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE); BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(bibWriter, generalPreferences, savePreferences, Globals.entryTypesManager); databaseWriter.saveDatabase(new BibDatabaseContext(newBase)); @@ -538,10 +534,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { // Show just a warning message if encoding did not work for all characters: if (fileWriter.hasEncodingProblems()) { System.err.println(Localization.lang("Warning") + ": " - + Localization.lang( - "The chosen encoding '%0' could not encode the following characters:", - generalPreferences.getDefaultEncoding().displayName()) - + " " + fileWriter.getEncodingProblems()); + + Localization.lang("UTF-8 could not be used to encode the following characters: %0", fileWriter.getEncodingProblems())); } } catch (IOException ex) { System.err.println(Localization.lang("Could not save file.") + "\n" + ex.getLocalizedMessage()); @@ -581,8 +574,6 @@ private void exportFile(List loaded, String[] data) { // We have an exporter: try { exporter.get().export(pr.getDatabaseContext(), Path.of(data[0]), - pr.getDatabaseContext().getMetaData().getEncoding() - .orElse(preferencesService.getGeneralPreferences().getDefaultEncoding()), pr.getDatabaseContext().getDatabase().getEntries()); } catch (Exception ex) { System.err.println(Localization.lang("Could not export file") + " '" + data[0] + "': " diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 4d6d09ab0f7..3d774c3eab1 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -826,7 +826,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, prefs.getGeneralPreferences().getDefaultBibDatabaseMode(), Globals.entryTypesManager, prefs.getFieldWriterPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences(), prefs.getGeneralPreferences().getDefaultEncoding())), + factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, prefs.getGeneralPreferences().getDefaultBibDatabaseMode(), Globals.entryTypesManager, prefs.getFieldWriterPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences())), factory.createMenuItem(StandardActions.COPY_LINKED_FILES, new CopyFilesAction(dialogService, prefs, stateManager)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index c4d82316ae0..b6ec8fd0b49 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -279,7 +279,6 @@ private void openLastEditedDatabases() { try { parsedDatabase = OpenDatabase.loadDatabase( dbFile, - preferencesService.getGeneralPreferences(), preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); } catch (IOException ex) { diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index cf76d3b7c41..f19f406e18f 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -55,7 +55,7 @@ public List scanForChanges() { // Important: apply all post-load actions ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences(); GeneralPreferences generalPreferences = preferencesService.getGeneralPreferences(); - ParserResult result = OpenDatabase.loadDatabase(database.getDatabasePath().get(), generalPreferences, importFormatPreferences, new DummyFileUpdateMonitor()); + ParserResult result = OpenDatabase.loadDatabase(database.getDatabasePath().get(), importFormatPreferences, new DummyFileUpdateMonitor()); BibDatabaseContext databaseOnDisk = result.getDatabaseContext(); // Start looking at changes. diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 1b8cd4b4846..187328a02cd 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -370,8 +370,7 @@ private void setupToolBar() { preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), - databaseContext, - preferencesService.getGeneralPreferences().getDefaultEncoding()); + databaseContext); for (EntryBasedFetcher fetcher : entryBasedFetchers) { MenuItem fetcherMenuItem = new MenuItem(fetcher.getName()); if (fetcher instanceof PdfMergeMetadataImporter.EntryBasedFetcherWrapper) { @@ -383,8 +382,7 @@ private void setupToolBar() { preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), - databaseContext, - preferencesService.getGeneralPreferences().getDefaultEncoding()); + databaseContext); fetchAndMerge(pdfMergeMetadataImporter); }); } else { diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 4511c7107ac..9d49e62652e 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -118,10 +118,6 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt .wrap(() -> { format.export(stateManager.getActiveDatabase().get(), file, - stateManager.getActiveDatabase().get() - .getMetaData() - .getEncoding() - .orElse(preferences.getGeneralPreferences().getDefaultEncoding()), finEntries); return null; // can not use BackgroundTask.wrap(Runnable) because Runnable.run() can't throw Exceptions }) diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index 80247e2c335..3407c25c153 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -1,14 +1,11 @@ package org.jabref.gui.exporter; -import java.io.BufferedReader; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -26,7 +23,6 @@ import org.jabref.logic.exporter.ExporterFactory; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.FileType; -import org.jabref.logic.util.OS; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.PreferencesService; @@ -124,14 +120,10 @@ private ExportResult exportToClipboard(Exporter exporter) throws Exception { // Write to file: exporter.export(stateManager.getActiveDatabase().get(), tmp, - stateManager.getActiveDatabase().get() - .getMetaData() - .getEncoding() - .orElse(preferences.getGeneralPreferences().getDefaultEncoding()), entries); // Read the file and put the contents on the clipboard: - return new ExportResult(readFileToString(tmp), exporter.getFileType()); + return new ExportResult(Files.readString(tmp), exporter.getFileType()); } finally { // Clean up: if ((tmp != null) && Files.exists(tmp)) { @@ -160,18 +152,6 @@ private void setContentToClipboard(ExportResult result) { dialogService.notify(Localization.lang("Entries exported to clipboard") + ": " + entries.size()); } - private String readFileToString(Path tmp) throws IOException { - Charset defaultEncoding = Objects.requireNonNull(preferences.getGeneralPreferences().getDefaultEncoding()); - try (BufferedReader reader = Files.newBufferedReader(tmp, stateManager.getActiveDatabase() - .map(db -> db.getMetaData() - .getEncoding() - .orElse(defaultEncoding)) - .orElse(defaultEncoding))) { - return reader.lines().collect(Collectors.joining(OS.NEWLINE)); - } - } - private record ExportResult(String content, FileType fileType) { - } } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 8dcc142e81f..5197bf64d30 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.nio.file.Files; import java.nio.file.Path; @@ -92,7 +93,7 @@ public boolean saveAs(Path file) { public void saveSelectedAsPlain() { askForSavePath().ifPresent(path -> { try { - saveDatabase(path, true, preferences.getGeneralPreferences().getDefaultEncoding(), SavePreferences.DatabaseSaveType.PLAIN_BIBTEX); + saveDatabase(path, true, StandardCharsets.UTF_8, SavePreferences.DatabaseSaveType.PLAIN_BIBTEX); frame.getFileHistory().newFile(path); dialogService.notify(Localization.lang("Saved selected to '%0'.", path.toString())); } catch (SaveException ex) { @@ -203,7 +204,7 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { Charset encoding = libraryTab.getBibDatabaseContext() .getMetaData() .getEncoding() - .orElse(preferences.getGeneralPreferences().getDefaultEncoding()); + .orElse(StandardCharsets.UTF_8); // Make sure to remember which encoding we used. libraryTab.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT); diff --git a/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java b/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java index 2e72706e0ba..4043dde2b46 100644 --- a/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java +++ b/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java @@ -1,6 +1,5 @@ package org.jabref.gui.exporter; -import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; @@ -50,7 +49,6 @@ public class WriteMetadataToPdfAction extends SimpleCommand { private final FilePreferences filePreferences; private final XmpPreferences xmpPreferences; private final EmbeddedBibFilePdfExporter embeddedBibExporter; - private final Charset encoding; private OptionsDialog optionsDialog; @@ -62,13 +60,12 @@ public class WriteMetadataToPdfAction extends SimpleCommand { private int entriesChanged; private int errors; - public WriteMetadataToPdfAction(StateManager stateManager, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldWriterPreferences fieldWriterPreferences, DialogService dialogService, TaskExecutor taskExecutor, FilePreferences filePreferences, XmpPreferences xmpPreferences, Charset encoding) { + public WriteMetadataToPdfAction(StateManager stateManager, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldWriterPreferences fieldWriterPreferences, DialogService dialogService, TaskExecutor taskExecutor, FilePreferences filePreferences, XmpPreferences xmpPreferences) { this.stateManager = stateManager; this.dialogService = dialogService; this.taskExecutor = taskExecutor; this.filePreferences = filePreferences; this.xmpPreferences = xmpPreferences; - this.encoding = encoding; this.embeddedBibExporter = new EmbeddedBibFilePdfExporter(databaseMode, entryTypesManager, fieldWriterPreferences); this.executable.bind(needsDatabase(stateManager)); @@ -191,12 +188,12 @@ private void writeMetadata() { String.valueOf(entriesChanged), String.valueOf(skipped), String.valueOf(errors))); } + /** + * This writes both XMP data and embeddeds the .bib file + */ private void writeMetadataToFile(Path file, BibEntry entry, BibDatabaseContext databaseContext, BibDatabase database) throws Exception { - // XMP XmpUtilWriter.writeXmp(file, entry, database, xmpPreferences); - - // Embedded Bib File - embeddedBibExporter.exportToFileByPath(databaseContext, database, encoding, filePreferences, file); + embeddedBibExporter.exportToFileByPath(databaseContext, database, filePreferences, file); } class OptionsDialog extends FXDialog { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 50f27f6bb5e..63523c76d9b 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -428,7 +428,7 @@ public void writeMetadataToPdf() { XmpUtilWriter.writeXmp(file.get(), entry, databaseContext.getDatabase(), preferences.getXmpPreferences()); EmbeddedBibFilePdfExporter embeddedBibExporter = new EmbeddedBibFilePdfExporter(preferences.getGeneralPreferences().getDefaultBibDatabaseMode(), Globals.entryTypesManager, preferences.getFieldWriterPreferences()); - embeddedBibExporter.exportToFileByPath(databaseContext, databaseContext.getDatabase(), preferences.getGeneralPreferences().getDefaultEncoding(), preferences.getFilePreferences(), file.get()); + embeddedBibExporter.exportToFileByPath(databaseContext, databaseContext.getDatabase(), preferences.getFilePreferences(), file.get()); } catch (IOException | TransformerException ex) { // TODO: Print error message // Localization.lang("Error while writing") + " '" + file.toString() + "': " + ex; @@ -584,7 +584,7 @@ public void parsePdfMetadataAndShowMergeDialog() { private Supplier wrapImporterToSupplier(Importer importer, Path filePath) { return () -> { try { - ParserResult parserResult = importer.importDatabase(filePath, preferences.getGeneralPreferences().getDefaultEncoding()); + ParserResult parserResult = importer.importDatabase(filePath); if (parserResult.isInvalid() || parserResult.isEmpty() || !parserResult.getDatabase().hasEntries()) { return null; } diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index a4eeea9e99a..aa63222685e 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -132,7 +132,7 @@ private List doImport(List files) frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "..."); }); // Specific importer: - ParserResult pr = importer.get().importDatabase(filename, prefs.getGeneralPreferences().getDefaultEncoding()); + ParserResult pr = importer.get().importDatabase(filename); imports.add(new ImportFormatReader.UnknownFormatImport(importer.get().getName(), pr)); } } catch (ImportException | IOException e) { diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index c79bc929950..c4336bd6374 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -41,7 +41,8 @@ // The action concerned with opening an existing database. public class OpenDatabaseAction extends SimpleCommand { - public static final Logger LOGGER = LoggerFactory.getLogger(OpenDatabaseAction.class); + private static final Logger LOGGER = LoggerFactory.getLogger(OpenDatabaseAction.class); + // List of actions that may need to be called after opening the file. Such as // upgrade actions etc. that may depend on the JabRef version that wrote the file: private static final List POST_OPEN_ACTIONS = Arrays.asList( @@ -198,7 +199,6 @@ private ParserResult loadDatabase(Path file) throws Exception { ParserResult result; try { result = OpenDatabase.loadDatabase(fileToLoad, - preferencesService.getGeneralPreferences(), preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); } catch (IOException e) { diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java index e0bda0f8d33..809a2020c78 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java @@ -42,7 +42,6 @@ public void execute() { IntegrityCheck check = new IntegrityCheck(database, Globals.prefs.getFilePreferences(), Globals.prefs.getCitationKeyPatternPreferences(), - Globals.prefs.getGeneralPreferences().getDefaultEncoding(), Globals.journalAbbreviationRepository, Globals.prefs.getEntryEditorPreferences().shouldAllowIntegerEditionBibtex()); diff --git a/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java index 9fbdf98c565..65dc1d0b9ef 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/general/GeneralPropertiesViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.libraryproperties.general; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import javax.swing.undo.UndoManager; @@ -62,7 +63,7 @@ public void setValues() { boolean isShared = (databaseContext.getLocation() == DatabaseLocation.SHARED); encodingDisableProperty.setValue(isShared); // the encoding of shared database is always UTF-8 - selectedEncodingProperty.setValue(metaData.getEncoding().orElse(preferencesService.getGeneralPreferences().getDefaultEncoding())); + selectedEncodingProperty.setValue(metaData.getEncoding().orElse(StandardCharsets.UTF_8)); selectedDatabaseModeProperty.setValue(metaData.getMode().orElse(BibDatabaseMode.BIBLATEX)); generalFileDirectoryProperty.setValue(metaData.getDefaultFileDirectory().orElse("").trim()); userSpecificFileDirectoryProperty.setValue(metaData.getUserFileDirectory(preferencesService.getFilePreferences().getUser()).orElse("").trim()); diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 681e16ad424..662a4aac69e 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -142,8 +142,7 @@ public OpenOfficePanel(PreferencesService preferencesService, update.setMaxWidth(Double.MAX_VALUE); loader = new StyleLoader(ooPrefs, - preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository), - preferencesService.getGeneralPreferences().getDefaultEncoding()); + preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)); initPanel(); } diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml index 0fe621f75c2..73a010b459a 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml @@ -27,8 +27,6 @@