-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/org/jabref/gui/externalfiles/PdfMergeDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.jabref.gui.externalfiles; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.function.Supplier; | ||
|
||
import org.jabref.gui.mergeentries.MultiMergeEntriesView; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.importer.Importer; | ||
import org.jabref.logic.importer.ParserResult; | ||
import org.jabref.logic.importer.fileformat.pdf.PdfEmbeddedBibExtractor; | ||
import org.jabref.logic.importer.fileformat.pdf.PdfFirstPageBibExtractor; | ||
import org.jabref.logic.importer.fileformat.pdf.PdfGrobidBibExtractor; | ||
import org.jabref.logic.importer.fileformat.pdf.PdfVerbatimBibExtractor; | ||
import org.jabref.logic.importer.fileformat.pdf.PdfXmpBibExtractor; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.util.TaskExecutor; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
public class PdfMergeDialog { | ||
/** | ||
* Constructs a merge dialog for a PDF file. This dialog merges results from various {@link org.jabref.logic.importer.fileformat.pdf.PdfBibExtractor}s. | ||
* <p> | ||
* {@link org.jabref.logic.importer.fileformat.pdf.PdfBibExtractor}s try to extract a {@link BibEntry} out of a PDF file, | ||
* but it does not perform this 100% perfectly, it is only a set of heuristics that in some cases might work, in others not. | ||
* Thus, JabRef provides this merge dialog that collects the results of all {@link org.jabref.logic.importer.fileformat.pdf.PdfBibExtractor}s | ||
* and gives user a choice between field values. | ||
*/ | ||
public static MultiMergeEntriesView make(BibEntry entry, Path filePath, GuiPreferences preferences, TaskExecutor taskExecutor) { | ||
MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor); | ||
|
||
dialog.setTitle(Localization.lang("Merge PDF metadata")); | ||
|
||
dialog.addSource(Localization.lang("Entry"), entry); | ||
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibExtractor(preferences.getImportFormatPreferences()), filePath)); | ||
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibExtractor(preferences.getImportFormatPreferences()), filePath)); | ||
|
||
if (preferences.getGrobidPreferences().isGrobidEnabled()) { | ||
dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidBibExtractor(preferences.getImportFormatPreferences()), filePath)); | ||
} | ||
|
||
dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpBibExtractor(preferences.getXmpPreferences()), filePath)); | ||
dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfFirstPageBibExtractor(), filePath)); | ||
|
||
return dialog; | ||
} | ||
|
||
private static Supplier<BibEntry> wrapImporterToSupplier(Importer importer, Path filePath) { | ||
return () -> { | ||
try { | ||
ParserResult parserResult = importer.importDatabase(filePath); | ||
if (parserResult.isInvalid() || parserResult.isEmpty() || !parserResult.getDatabase().hasEntries()) { | ||
return null; | ||
} | ||
return parserResult.getDatabase().getEntries().getFirst(); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters