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

public abstract Class Importer

extends Object
implements Comparable<Importer>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
org.jabref.logic.importer.fileformat.BiblioscapeImporter, org.jabref.logic.importer.fileformat.BibtexImporter, org.jabref.logic.importer.fileformat.CffImporter, org.jabref.logic.importer.fileformat.CitaviXmlImporter, org.jabref.logic.importer.fileformat.CopacImporter, org.jabref.logic.importer.fileformat.CustomImporter, org.jabref.logic.importer.fileformat.EndnoteImporter, org.jabref.logic.importer.fileformat.EndnoteXmlImporter, org.jabref.logic.importer.fileformat.HayagrivaImporter, org.jabref.logic.importer.fileformat.InspecImporter, org.jabref.logic.importer.fileformat.IsiImporter, org.jabref.logic.importer.fileformat.MedlineImporter, org.jabref.logic.importer.fileformat.MedlinePlainImporter, org.jabref.logic.importer.fileformat.ModsImporter, org.jabref.logic.importer.fileformat.MrDLibImporter, org.jabref.logic.importer.fileformat.MsBibImporter, org.jabref.logic.importer.fileformat.OvidImporter, org.jabref.logic.importer.fileformat.ReferImporter, org.jabref.logic.importer.fileformat.RepecNepImporter, org.jabref.logic.importer.fileformat.RisImporter, org.jabref.logic.importer.fileformat.pdf.PdfImporter
Annotations
@NullMarked
Imports
java.io.BufferedInputStream, .BufferedReader, .IOException, .InputStream, .InputStreamReader, .Reader, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .Path, .StandardOpenOption, java.util.Arrays, .Objects, org.jabref.logic.util.FileType, org.jabref.logic.util.io.FileUtil, org.jabref.model.database.BibDatabaseModeDetection, com.ibm.icu.text.CharsetDetector, .CharsetMatch, org.jspecify.annotations.NullMarked, org.slf4j.Logger, .LoggerFactory

Role of an importer for JabRef.

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Importer o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

protected static Charset
getCharset(BufferedInputStream bufferedInputStream)

public abstract String

Returns:

description of the import format
getDescription
()

Returns the description of the import format.

public abstract FileType

Returns:

FileType corresponding to the importer
getFileType
()

Returns the type of files that this importer can read

public abstract String

Returns:

ID, must be unique and not null
getId
()

Returns a slug, which identifies this importer.

public abstract String

Returns:

format name, must be unique and not null
getName
()

Returns the name of this import format.

public static BufferedReader
getReader(Path filePath)

public static BufferedReader
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public abstract ParserResult
importDatabase(BufferedReader
the input to read from - there is no reset done. "BufferedReader" is only a convenience for the implementation
input
)

Parse the database in the source.

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

Parse the database in the specified file.

public ParserResult

Returns:

the parsed result
importDatabase
(String
the string which should be imported
data
)

Parse the database in the specified string.

public boolean
isRecognizedFormat(BufferedReader input)

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

public boolean
isRecognizedFormat(Reader input)

#isRecognizedFormat(BufferedReader) without the requirement to reset

public boolean

Returns:

true, if the file is in a recognized format
isRecognizedFormat
(Path
the path of the file to check
filePath
)

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

public boolean

Returns:

true, if the data is in a recognized format
isRecognizedFormat
(String
the data to check
data
)

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

public boolean
supportsFileExtension(String
the extension to check, without leading dot
extension
)

Checks whether the file extension matches this importer.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

Importerback to summary
public Importer()

Method Detail

compareToback to summary
public int compareTo(Importer o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

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

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getCharsetback to summary
protected static Charset getCharset(BufferedInputStream bufferedInputStream)
getDescriptionback to summary
public abstract String 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 isRecognizedFormat(BufferedReader) recognizes an import format

Returns:String

description of the import format

getFileTypeback to summary
public abstract FileType getFileType()

Returns the type of files that this importer can read

Returns:FileType

FileType corresponding to the importer

getIdback to summary
public abstract String getId()

Returns a slug, which identifies this importer. Used, for example, to identify the importer in CLI.

Typically, this name should be short, in English, and should not contain special characters like #, %, etc.

Returns:String

ID, must be unique and not null

getNameback to summary
public abstract String getName()

Returns the name of this import format. Typically, this is a string that denotes file type or format. It can also be localized, like "XMP-annotated PDF".

Returns:String

format name, must be unique and not null

getReaderback to summary
public static BufferedReader getReader(Path filePath) throws IOException
getReaderback to summary
public static BufferedReader getReader(InputStream stream)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
importDatabaseback to summary
public abstract ParserResult importDatabase(BufferedReader input) throws IOException

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.

If your format is binary-based (PDF, ZIP-based, or others), then you should not solely override this method. For binary formats do this:

  1. Throw UnsupportedOperationException in this method.
  2. Override the method Importer#importDatabase(Path). Example of this workaround is in: org.jabref.logic.importer.fileformat.pdf.PdfImporter.
Parameters
input:BufferedReader

the input to read from - there is no reset done. "BufferedReader" is only a convenience for the implementation

importDatabaseback to summary
public ParserResult importDatabase(Path filePath) throws IOException

Parse the database in the specified file.

Parameters
filePath:Path

the path to the file which should be imported

importDatabaseback to summary
public ParserResult importDatabase(String data) throws IOException

Parse the database in the specified string.

Importer having the facilities to detect the correct encoding of a string should overwrite this method, determine the encoding and then call importDatabase(BufferedReader).

Parameters
data:String

the string which should be imported

Returns:ParserResult

the parsed result

Exceptions
IOException:
Signals that an I/O exception has occurred.
isRecognizedFormatback to summary
public boolean isRecognizedFormat(BufferedReader input) throws IOException

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

All implementations need to reset the input stream to the beginning again - to enable importing at subsequent calls.

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 behavior 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.

isRecognizedFormatback to summary
public boolean isRecognizedFormat(Reader input) throws IOException

#isRecognizedFormat(BufferedReader) without the requirement to reset

isRecognizedFormatback to summary
public boolean isRecognizedFormat(Path filePath) throws IOException

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

Parameters
filePath:Path

the path of the file to check

Returns:boolean

true, if the file is in a recognized format

Exceptions
IOException:
Signals that an I/O exception has occurred.
isRecognizedFormatback to summary
public boolean isRecognizedFormat(String data) throws IOException

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

Parameters
data:String

the data to check

Returns:boolean

true, if the data is in a recognized format

Exceptions
IOException:
Signals that an I/O exception has occurred.
supportsFileExtensionback to summary
public boolean supportsFileExtension(String extension)

Checks whether the file extension matches this importer.

Parameters
extension:String

the extension to check, without leading dot

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override