Search in sources :

Example 96 with BibEntry

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);
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) ParserResult(org.jabref.logic.importer.ParserResult) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) ArrayList(java.util.ArrayList) FileListEntry(org.jabref.gui.filelist.FileListEntry) PdfXmpImporter(org.jabref.logic.importer.fileformat.PdfXmpImporter)

Example 97 with BibEntry

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;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) DroppedFileHandler(org.jabref.gui.externalfiles.DroppedFileHandler)

Example 98 with BibEntry

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;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) DroppedFileHandler(org.jabref.gui.externalfiles.DroppedFileHandler)

Example 99 with BibEntry

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;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Example 100 with BibEntry

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;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) SearchMatcher(org.jabref.model.search.SearchMatcher)

Aggregations

BibEntry (org.jabref.model.entry.BibEntry)716 Test (org.junit.Test)466 ParserResult (org.jabref.logic.importer.ParserResult)131 StringReader (java.io.StringReader)107 ArrayList (java.util.ArrayList)75 BibDatabase (org.jabref.model.database.BibDatabase)63 Path (java.nio.file.Path)52 IOException (java.io.IOException)43 HashMap (java.util.HashMap)37 Before (org.junit.Before)36 NamedCompound (org.jabref.gui.undo.NamedCompound)30 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)28 BibtexString (org.jabref.model.entry.BibtexString)28 List (java.util.List)23 File (java.io.File)21 StringWriter (java.io.StringWriter)19 Optional (java.util.Optional)19 BasePanel (org.jabref.gui.BasePanel)19 FieldChange (org.jabref.model.FieldChange)18 InputStream (java.io.InputStream)16