Skip to content

Commit

Permalink
Remove DOI lookup from PdfContentImporter (#7963)
Browse files Browse the repository at this point in the history
  • Loading branch information
btut authored Aug 8, 2021
1 parent 3a44c69 commit 8d6b4fd
Showing 1 changed file with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.StandardFileType;
Expand All @@ -25,7 +23,6 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.strings.StringUtil;
Expand Down Expand Up @@ -206,21 +203,11 @@ public ParserResult importDatabase(Path filePath, Charset defaultEncoding) {
final ArrayList<BibEntry> result = new ArrayList<>(1);
try (PDDocument document = XmpUtilReader.loadWithAutomaticDecryption(filePath)) {
String firstPageContents = getFirstPageContents(document);

Optional<DOI> doi = DOI.findInText(firstPageContents);
if (doi.isPresent()) {
ParserResult parserResult = new ParserResult(result);
Optional<BibEntry> entry = new DoiFetcher(importFormatPreferences).performSearchById(doi.get().getDOI());
entry.ifPresent(parserResult.getDatabase()::insertEntry);
entry.ifPresent(bibEntry -> bibEntry.addFile(new LinkedFile("", filePath.toAbsolutePath(), "PDF")));
return parserResult;
}

Optional<BibEntry> entry = getEntryFromPDFContent(firstPageContents, OS.NEWLINE);
entry.ifPresent(result::add);
} catch (EncryptedPdfsNotSupportedException e) {
return ParserResult.fromErrorMessage(Localization.lang("Decryption not supported."));
} catch (IOException | FetcherException exception) {
} catch (IOException exception) {
return ParserResult.fromError(exception);
}

Expand Down

0 comments on commit 8d6b4fd

Please sign in to comment.