Verified Owner
Top Inners Fields Constructors Methods
org.jabref.logic.importer

public Class ImportFormatReader

extends Object
Class Inheritance
Annotations
@NullMarked
Imports
java.io.BufferedWriter, .IOException, .Reader, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, java.util.ArrayList, .List, .Optional, .SortedSet, .TreeSet, org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences, org.jabref.logic.importer.fileformat.BiblioscapeImporter, .BibtexImporter, .CffImporter, .CitaviXmlImporter, .CopacImporter, .EndnoteImporter, .EndnoteXmlImporter, .HayagrivaImporter, .InspecImporter, .IsiImporter, .MedlineImporter, .MedlinePlainImporter, .ModsImporter, .MsBibImporter, .OvidImporter, .ReferImporter, .RepecNepImporter, .RisImporter, org.jabref.logic.importer.fileformat.pdf.PdfContentImporter, .PdfEmbeddedBibFileImporter, .PdfGrobidImporter, .PdfMergeMetadataImporter, .PdfVerbatimBibtexImporter, .PdfXmpImporter, org.jabref.logic.l10n.Localization, org.jabref.logic.util.io.FileUtil, org.jabref.model.database.BibDatabases, org.jabref.model.entry.BibEntry, org.jabref.model.util.FileUpdateMonitor, org.jspecify.annotations.NonNull, .NullMarked, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
public static interface
public static record

Field Summary

Modifier and TypeField and Description
public static final String
private BibtexImporter
private final CitationKeyPatternPreferences
private final FileUpdateMonitor
private final ImporterPreferences
private final List<Importer>
importers

All import formats.

private final ImportFormatPreferences
private static final Logger

Constructor Summary

AccessConstructor and Description
public
ImportFormatReader(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences, CitationKeyPatternPreferences citationKeyPatternPreferences, FileUpdateMonitor fileUpdateMonitor)

Method Summary

Modifier and TypeMethod and Description
private Optional<Importer>

Returns:

Import Format or null if none matches
getByCliId
(String
CLI-Id
cliId
)

Format for a given CLI-ID.

Will return the first format according to the default-order of format that matches the given ID.

public SortedSet<Importer>
getImporters()

Returns: All importers, elements are sorted by name

public boolean
hasImporterForFile(Path filePath)

Checks whether at least one registered importer supports the file extension.

public ParserResult
importFromFile(String format, Path file)

public ImportFormatReader.ImportResult
importWithAutoDetection(Path filePath)

Tries to import a file by iterating through the available import filters, and keeping the import that seems most promising.

public ImportFormatReader.ImportResult
importWithAutoDetection(Reader reader)

Tries to import a stream by iterating through the available import filters, and keeping the import that seems most promising.

public ImportFormatReader.ImportResult

Returns:

an UnknownFormatImport with the imported entries and metadata
importWithAutoDetection
(@NonNull String
the string to import
data
)

Tries to import a String by iterating through the available import filters, and keeping the import that seems the most promising

private ImportFormatReader.ImportResult

Returns:

an UnknownFormatImport with the imported entries and metadata
importWithAutoDetection
(ImportFormatReader.CheckedFunction<Importer, ParserResult>
the function to import the entries with a formatter
importDatabase
,
ImportFormatReader.CheckedFunction<Importer, Boolean>
the function to check whether the source is in the correct format for an importer
isRecognizedFormat
,
ImportFormatReader.CheckedSupplier<ParserResult>
used as fallback when the importers did not match
importUsingBibtex
)

Tries to import entries by iterating through the available import filters, and keeping the import that seems the most promising

The implementation idea is to be independent of BufferedInputStream vs. File.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIBTEX_FORMATback to summary
public static final String BIBTEX_FORMAT
bibtexImporterback to summary
private BibtexImporter bibtexImporter
citationKeyPatternPreferencesback to summary
private final CitationKeyPatternPreferences citationKeyPatternPreferences
fileUpdateMonitorback to summary
private final FileUpdateMonitor fileUpdateMonitor
importerPreferencesback to summary
private final ImporterPreferences importerPreferences
importersback to summary
private final List<Importer> importers

All import formats. Sorted accordingly to Importer#compareTo, which defaults to alphabetically by the name

importFormatPreferencesback to summary
private final ImportFormatPreferences importFormatPreferences
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

ImportFormatReaderback to summary
public ImportFormatReader(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences, CitationKeyPatternPreferences citationKeyPatternPreferences, FileUpdateMonitor fileUpdateMonitor)

Method Detail

getByCliIdback to summary
private Optional<Importer> getByCliId(String cliId)

Format for a given CLI-ID.

Will return the first format according to the default-order of format that matches the given ID.

Parameters
cliId:String

CLI-Id

Returns:Optional<Importer>

Import Format or null if none matches

getImportersback to summary
public SortedSet<Importer> getImporters()
Returns:SortedSet<Importer>

All importers, elements are sorted by name

hasImporterForFileback to summary
public boolean hasImporterForFile(Path filePath)

Checks whether at least one registered importer supports the file extension.

importFromFileback to summary
public ParserResult importFromFile(String format, Path file) throws ImportException
importWithAutoDetectionback to summary
public ImportFormatReader.ImportResult importWithAutoDetection(Path filePath) throws ImportException

Tries to import a file by iterating through the available import filters, and keeping the import that seems most promising.

This method last attempts to read this file as bibtex.

Exceptions
ImportException:
if the import fails (for example, if no suitable importer is found)
importWithAutoDetectionback to summary
public ImportFormatReader.ImportResult importWithAutoDetection(Reader reader) throws ImportException

Tries to import a stream by iterating through the available import filters, and keeping the import that seems most promising.

Exceptions
ImportException:
if the import fails (for example, if no suitable importer is found)
importWithAutoDetectionback to summary
public ImportFormatReader.ImportResult importWithAutoDetection(@NonNull String data) throws ImportException

Tries to import a String by iterating through the available import filters, and keeping the import that seems the most promising

Parameters
data:@NonNull String

the string to import

Returns:ImportFormatReader.ImportResult

an UnknownFormatImport with the imported entries and metadata

Exceptions
ImportException:
if the import fails (for example, if no suitable importer is found)
importWithAutoDetectionback to summary
private ImportFormatReader.ImportResult importWithAutoDetection(ImportFormatReader.CheckedFunction<Importer, ParserResult> importDatabase, ImportFormatReader.CheckedFunction<Importer, Boolean> isRecognizedFormat, ImportFormatReader.CheckedSupplier<ParserResult> importUsingBibtex) throws ImportException

Tries to import entries by iterating through the available import filters, and keeping the import that seems the most promising

The implementation idea is to be independent of BufferedInputStream vs. File. Therefore, functions are passed.

Parameters
importDatabase:ImportFormatReader.CheckedFunction<Importer, ParserResult>

the function to import the entries with a formatter

isRecognizedFormat:ImportFormatReader.CheckedFunction<Importer, Boolean>

the function to check whether the source is in the correct format for an importer

importUsingBibtex:ImportFormatReader.CheckedSupplier<ParserResult>

used as fallback when the importers did not match

Returns:ImportFormatReader.ImportResult

an UnknownFormatImport with the imported entries and metadata

Exceptions
ImportException:
if the import fails (for example, if no suitable importer is found)
resetback to summary
public void reset()
org.jabref.logic.importer back to summary

public Interface ImportFormatReader.CheckedFunction<T, R>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public R
apply(T t)

Method Detail

applyback to summary
public R apply(T t) throws IOException
org.jabref.logic.importer back to summary

public Interface ImportFormatReader.CheckedSupplier<R>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public R

Method Detail

applyback to summary
public R apply() throws IOException
org.jabref.logic.importer back to summary

public final Record ImportFormatReader.ImportResult

extends Record
Class Inheritance
Record Components
format:String
The name of the format used
parserResult:ParserResult
The resulting data

Field Summary

Modifier and TypeField and Description
private final String
format

Record Component accessed by format().

The name of the format used
private final ParserResult
parserResult

Record Component accessed by parserResult().

The resulting data

Constructor Summary

AccessConstructor and Description
public
ImportResult(String format, ParserResult parserResult)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public String
format()

Record Component getter of format.

Record Component The name of the format used

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public ParserResult
parserResult()

Record Component getter of parserResult.

Record Component The resulting data

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

formatback to summary
private final String format

Record Component accessed by format().

The name of the format used

parserResultback to summary
private final ParserResult parserResult

Record Component accessed by parserResult().

The resulting data

Constructor Detail

ImportResultback to summary
public ImportResult(String format, ParserResult parserResult)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
formatback to summary
public String format()

Record Component getter of format.

Record Component
The name of the format used
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

parserResultback to summary
public ParserResult parserResult()

Record Component getter of parserResult.

Record Component
The resulting data
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.