use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class PdfImporter method doXMPImport.
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();
Path toLink = Paths.get(fileName);
// Get a list of file directories:
List<Path> dirsS = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
tm.addEntry(0, new FileListEntry(toLink.getFileName().toString(), FileUtil.shortenFileName(toLink, dirsS).toString(), ExternalFileTypes.getInstance().getExternalFileTypeByName("PDF")));
entry.setField(FieldName.FILE, tm.getStringRepresentation());
res.add(entry);
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class PdfImporter method createNewBlankEntry.
private Optional<BibEntry> createNewBlankEntry(String fileName) {
Optional<BibEntry> newEntry = createNewEntry();
newEntry.ifPresent(bibEntry -> {
DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
dfh.linkPdfToEntry(fileName, bibEntry);
});
return newEntry;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class PdfImporter method importPdfFilesInternal.
/**
* @param fileNames - PDF files to import
* @return true if the import succeeded, false otherwise
*/
private List<BibEntry> importPdfFilesInternal(List<String> fileNames) {
if (panel == null) {
return Collections.emptyList();
}
ImportDialog importDialog = null;
boolean doNotShowAgain = false;
boolean neverShow = Globals.prefs.getBoolean(JabRefPreferences.IMPORT_ALWAYSUSE);
int globalChoice = Globals.prefs.getInt(JabRefPreferences.IMPORT_DEFAULT_PDF_IMPORT_STYLE);
List<BibEntry> res = new ArrayList<>();
for (String fileName : fileNames) {
if (!neverShow && !doNotShowAgain) {
importDialog = new ImportDialog(dropRow >= 0, fileName);
if (!XMPUtil.hasMetadata(Paths.get(fileName), Globals.prefs.getXMPPreferences())) {
importDialog.disableXMPChoice();
}
importDialog.setLocationRelativeTo(frame);
importDialog.showDialog();
doNotShowAgain = importDialog.isDoNotShowAgain();
}
if (neverShow || (importDialog.getResult() == JOptionPane.OK_OPTION)) {
int choice = neverShow ? globalChoice : importDialog.getChoice();
switch(choice) {
case ImportDialog.XMP:
doXMPImport(fileName, res);
break;
case ImportDialog.CONTENT:
doContentImport(fileName, res);
break;
case ImportDialog.NOMETA:
createNewBlankEntry(fileName).ifPresent(res::add);
break;
case ImportDialog.ONLYATTACH:
DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
if (dropRow >= 0) {
dfh.linkPdfToEntry(fileName, entryTable, dropRow);
} else {
dfh.linkPdfToEntry(fileName, entryTable, entryTable.getSelectedRow());
}
break;
default:
break;
}
}
}
return res;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class WordKeywordGroup method add.
@Override
public List<FieldChange> add(List<BibEntry> entriesToAdd) {
Objects.requireNonNull(entriesToAdd);
List<FieldChange> changes = new ArrayList<>();
for (BibEntry entry : entriesToAdd) {
if (!contains(entry)) {
String oldContent = entry.getField(searchField).orElse("");
KeywordList wordlist = KeywordList.parse(oldContent, keywordSeparator);
wordlist.add(searchExpression);
String newContent = wordlist.getAsString(keywordSeparator);
entry.setField(searchField, newContent).ifPresent(changes::add);
}
}
return changes;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class GroupTreeNode method getMatchingGroups.
public List<GroupTreeNode> getMatchingGroups(List<BibEntry> entries) {
List<GroupTreeNode> groups = new ArrayList<>();
// Add myself if I contain the entries
SearchMatcher matcher = getSearchMatcher();
for (BibEntry entry : entries) {
if (matcher.isMatch(entry)) {
groups.add(this);
break;
}
}
// Traverse children
for (GroupTreeNode child : getChildren()) {
groups.addAll(child.getMatchingGroups(entries));
}
return groups;
}
Aggregations