Top Description Fields Constructors Methods
org.jabref.logic.importer.fileformat

public Class PdfContentImporter

extends Importer
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .StringWriter, java.nio.file.Path, java.util.ArrayList, .List, .Locale, .Objects, .Optional, java.util.regex.Matcher, .Pattern, org.jabref.logic.importer.Importer, .ParserResult, org.jabref.logic.l10n.Localization, org.jabref.logic.util.OS, .StandardFileType, org.jabref.logic.xmp.EncryptedPdfsNotSupportedException, .XmpUtilReader, org.jabref.model.entry.BibEntry, .LinkedFile, org.jabref.model.entry.field.StandardField, org.jabref.model.entry.types.EntryType, .StandardEntryType, org.jabref.model.strings.StringUtil, com.google.common.base.Strings, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.text.PDFTextStripper

PdfContentImporter parses data of the first page of the PDF and creates a BibTeX entry.

Currently, Springer, and IEEE formats are supported.

Field Summary

Modifier and TypeField and Description
private String
private int
private String[]
private String
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
extractYear()

Extract the year out of curString (if it is not yet defined)

private void
fillCurStringWithNonEmptyLines()

Fill curString with lines until "" is found No trailing space is added i is advanced to the next non-empty line (ignoring white space)

Lines containing only white spaces are ignored, but NOT considered as ""

Uses GLOBAL variables lines, curLine, i

public String
getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

pack-priv Optional<BibEntry>
getEntryFromPDFContent(String firstpageContents, String lineSeparator)

public StandardFileType
getFileType()

Implements abstract org.jabref.logic.importer.Importer.getFileType.

Returns the type of files that this importer can read

private String
getFirstPageContents(org.apache.pdfbox.pdmodel.PDDocument document)

public String
getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Returns the name of this import format.

public ParserResult
importDatabase(BufferedReader
the input to read from
reader
)

Implements abstract org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the source.

public ParserResult
importDatabase(Path
the path to the file which should be imported
filePath
)

Overrides org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the specified file.

public boolean
isRecognizedFormat(BufferedReader input)

Implements abstract org.jabref.logic.importer.Importer.isRecognizedFormat.

Check whether the source is in the correct format for this importer.

private void
proceedToNextNonEmptyLine()

PDFTextStripper normally does NOT produce multiple empty lines (besides at strange PDFs).

private void
readLastBlock()

resets curString curString now contains the last block (until "" reached) Trailing space is added

invariant before/after: i points to line before the last handled block

private String
removeNonLettersAtEnd(String input)

Removes all non-letter characters at the end

EXCEPTION: a closing bracket is NOT removed

Todo

Additionally replace multiple subsequent spaces by one space, which will cause a rename of this method

private String
private String
Inherited from org.jabref.logic.importer.Importer:
compareToequalsgetCharsetgetIdgetReadergetReaderhashCodeimportDatabaseisRecognizedFormatisRecognizedFormattoString

Field Detail

curStringback to summary
private String curString
lineIndexback to summary
private int lineIndex
linesback to summary
private String[] lines
yearback to summary
private String year
YEAR_EXTRACT_PATTERNback to summary
private static final Pattern YEAR_EXTRACT_PATTERN

Constructor Detail

PdfContentImporterback to summary
public PdfContentImporter()

Method Detail

extractYearback to summary
private void extractYear()

Extract the year out of curString (if it is not yet defined)

fillCurStringWithNonEmptyLinesback to summary
private void fillCurStringWithNonEmptyLines()

Fill curString with lines until "" is found No trailing space is added i is advanced to the next non-empty line (ignoring white space)

Lines containing only white spaces are ignored, but NOT considered as ""

Uses GLOBAL variables lines, curLine, i

getDescriptionback to summary
public String getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Doc from org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

The description should specify

  • what kind of entries from what sources and based on what specification it is able to import
  • by what criteria it recognizes an import format
Returns:String

description of the import format

Annotations
@Override
getEntryFromPDFContentback to summary
pack-priv Optional<BibEntry> getEntryFromPDFContent(String firstpageContents, String lineSeparator)
getFileTypeback to summary
public StandardFileType getFileType()

Implements abstract org.jabref.logic.importer.Importer.getFileType.

Doc from org.jabref.logic.importer.Importer.getFileType.

Returns the type of files that this importer can read

Returns:StandardFileType

FileType corresponding to the importer

Annotations
@Override
getFirstPageContentsback to summary
private String getFirstPageContents(org.apache.pdfbox.pdmodel.PDDocument document) throws IOException
getNameback to summary
public String getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Doc from org.jabref.logic.importer.Importer.getName.

Returns the name of this import format.

The name must be unique.

Returns:String

format name, must be unique and not null

Annotations
@Override
importDatabaseback to summary
public ParserResult importDatabase(BufferedReader reader) throws IOException

Implements abstract org.jabref.logic.importer.Importer.importDatabase.

Doc from org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the source.

This method can be called in two different contexts - either when importing in a specified format, or when importing in unknown format. In the latter case, JabRef cycles through all available import formats. No error messages or feedback is displayed from individual import formats in this case.

If importing in a specified format and an empty library is returned, JabRef reports that no entries were found.

This method should never return null.

Parameters
reader:BufferedReader

the input to read from

Annotations
@Override
importDatabaseback to summary
public ParserResult importDatabase(Path filePath)

Overrides org.jabref.logic.importer.Importer.importDatabase.

Doc from org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the specified file.

Parameters
filePath:Path

the path to the file which should be imported

Annotations
@Override
isRecognizedFormatback to summary
public boolean isRecognizedFormat(BufferedReader input) throws IOException

Implements abstract org.jabref.logic.importer.Importer.isRecognizedFormat.

Doc from org.jabref.logic.importer.Importer.isRecognizedFormat.

Check whether the source is in the correct format for this importer.

The effect of this method is primarily to avoid unnecessary processing of files when searching for a suitable import format. If this method returns false, the import routine will move on to the next import format.

Thus, the correct behaviour is to return false if it is certain that the file is not of the suitable type, and true otherwise. Returning true is the safe choice if not certain.

Annotations
@Override
proceedToNextNonEmptyLineback to summary
private void proceedToNextNonEmptyLine()

PDFTextStripper normally does NOT produce multiple empty lines (besides at strange PDFs). These strange PDFs are handled here: proceed to next non-empty line

readLastBlockback to summary
private void readLastBlock()

resets curString curString now contains the last block (until "" reached) Trailing space is added

invariant before/after: i points to line before the last handled block

removeNonLettersAtEndback to summary
private String removeNonLettersAtEnd(String input)

Removes all non-letter characters at the end

EXCEPTION: a closing bracket is NOT removed

Todo

Additionally replace multiple subsequent spaces by one space, which will cause a rename of this method

streamlineNamesback to summary
private String streamlineNames(String names)
streamlineTitleback to summary
private String streamlineTitle(String title)