private void doContentImport(String fileName, List<BibEntry> res) { PdfContentImporter contentImporter = new PdfContentImporter(Globals.prefs.getImportFormatPreferences()); Path filePath = Paths.get(fileName); ParserResult result = contentImporter.importDatabase(filePath, Globals.prefs.getDefaultEncoding()); if (result.hasWarnings()) { frame.showMessage(result.getErrorMessage()); } if (!result.getDatabase().hasEntries()) { // import failed -> generate default entry createNewBlankEntry(fileName).ifPresent(res::add); return; } // only one entry is imported BibEntry entry = result.getDatabase().getEntries().get(0); // insert entry to database and link file panel.getDatabase().insertEntry(entry); panel.markBaseChanged(); BibtexKeyPatternUtil.makeLabel( panel .getBibDatabaseContext() .getMetaData() .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), panel.getDatabase(), entry, Globals.prefs.getBibtexKeyPatternPreferences()); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entry); panel.highlightEntry(entry); if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_OPEN_FORM)) { EntryEditor editor = panel.getEntryEditor(entry); panel.showEntryEditor(editor); } res.add(entry); }
private void doXMPImport(String fileName, List<BibEntry> res) { List<BibEntry> localRes = new ArrayList<>(); PdfXmpImporter importer = new PdfXmpImporter(Globals.prefs.getXMPPreferences()); Path filePath = Paths.get(fileName); ParserResult result = importer.importDatabase(filePath, Globals.prefs.getDefaultEncoding()); if (result.hasWarnings()) { frame.showMessage(result.getErrorMessage()); } localRes.addAll(result.getDatabase().getEntries()); BibEntry entry; if (localRes.isEmpty()) { // import failed -> generate default entry LOGGER.info("Import failed"); createNewBlankEntry(fileName).ifPresent(res::add); return; } // only one entry is imported entry = localRes.get(0); // insert entry to database and link file panel.getDatabase().insertEntry(entry); panel.markBaseChanged(); FileListTableModel tm = new FileListTableModel(); File toLink = new File(fileName); // Get a list of file directories: List<String> dirsS = panel.getBibDatabaseContext().getFileDirectory(Globals.prefs.getFileDirectoryPreferences()); tm.addEntry( 0, new FileListEntry( toLink.getName(), FileUtil.shortenFileName(toLink, dirsS).getPath(), ExternalFileTypes.getInstance().getExternalFileTypeByName("PDF"))); entry.setField(FieldName.FILE, tm.getStringRepresentation()); res.add(entry); }