From c8ba83c712f3f945cdc8d30a5957dd8948a3d9c5 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 18 Jan 2020 12:01:50 +0100 Subject: [PATCH] Fix missing file extension for downloaded files. Fixes #5816 by falling back to PDF as default file type. --- CHANGELOG.md | 3 ++- .../jabref/gui/fieldeditors/LinkedFileViewModel.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9185ff1bb36..b9698796e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,9 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the Medline fetcher was only working when JabRef was running from source. [#5645](https://github.com/JabRef/jabref/issues/5645) - We fixed some visual issues in the dark theme. [#5764](https://github.com/JabRef/jabref/pull/5764) [#5753](https://github.com/JabRef/jabref/issues/5753) - We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779) -- We fixed an issue where the ampersand character wasn't rendering correctly on previews.[#3840](https://github.com/JabRef/jabref/issues/3840) +- We fixed an issue where the ampersand character wasn't rendering correctly on previews. [#3840](https://github.com/JabRef/jabref/issues/3840) - We fixed an issue where an erroneous "The library has been modified by another program" message was shown when saving. [#4877](https://github.com/JabRef/jabref/issues/4877) +- We fixed an issue where the file extension was missing after downloading a file (we now fall-back to pdf). [#5816](https://github.com/JabRef/jabref/issues/5816) ### Removed diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 2f76bc4e65e..103a352fd03 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -29,6 +29,7 @@ import org.jabref.gui.externalfiles.FileDownloadTask; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.externalfiletype.StandardExternalFileType; import org.jabref.gui.filelist.LinkedFileEditDialogView; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; @@ -85,7 +86,7 @@ public LinkedFileViewModel(LinkedFile linkedFile, this.taskExecutor = taskExecutor; this.externalFileTypes = externalFileTypes; this.xmpPreferences = xmpPreferences; - + downloadOngoing.bind(downloadProgress.greaterThanOrEqualTo(0).and(downloadProgress.lessThan(1))); canWriteXMPMetadata.setValue(!linkedFile.isOnlineLink() && linkedFile.getFileType().equalsIgnoreCase("pdf")); } @@ -397,7 +398,7 @@ public void download() { } try { Optional targetDirectory = databaseContext.getFirstExistingFileDir(filePreferences); - if (!targetDirectory.isPresent()) { + if (targetDirectory.isEmpty()) { dialogService.showErrorDialogAndWait(Localization.lang("Download file"), Localization.lang("File directory is not set or does not exist!")); return; } @@ -420,7 +421,7 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa BackgroundTask downloadTask = BackgroundTask .wrap(() -> { Optional suggestedType = inferFileType(urlDownload); - String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse(""); + String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName(); linkedFile.setFileType(suggestedTypeName); String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName); @@ -435,7 +436,7 @@ private Optional inferFileType(URLDownload urlDownload) { Optional suggestedType = inferFileTypeFromMimeType(urlDownload); // If we did not find a file type from the MIME type, try based on extension: - if (!suggestedType.isPresent()) { + if (suggestedType.isEmpty()) { suggestedType = inferFileTypeFromURL(urlDownload.getSource().toExternalForm()); } return suggestedType; @@ -454,7 +455,7 @@ private Optional inferFileTypeFromMimeType(URLDownload urlDown private Optional inferFileTypeFromURL(String url) { return URLUtil.getSuffix(url) - .flatMap(extension -> externalFileTypes.getExternalFileTypeByExt(extension)); + .flatMap(externalFileTypes::getExternalFileTypeByExt); } public LinkedFile getFile() {