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

public Class TemplateExporter

extends Exporter
Class Inheritance
Annotations
@NullMarked
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .Reader, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .Path, java.util.ArrayList, .HashMap, .List, .Map, org.jabref.logic.journals.JournalAbbreviationLoader, .JournalAbbreviationRepository, org.jabref.logic.layout.Layout, .LayoutFormatterPreferences, .LayoutHelper, org.jabref.logic.layout.format.Number, org.jabref.logic.os.OS, org.jabref.logic.util.FileType, .StandardFileType, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, org.jabref.model.entry.types.EntryType, org.jabref.model.metadata.SaveOrder, .SelfContainedSaveOrder, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Base class for export formats based on templates.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private final BlankLineBehaviour
private boolean
private final String
private static final String
private static final String
pack-priv static final String
pack-priv static final String
private final LayoutFormatterPreferences
private final String
private static final Logger
private final SelfContainedSaveOrder

Constructor Summary

AccessConstructor and Description
public
TemplateExporter(String
to display to the user and to call this format in the console.
name
,
String
Name of the main layout file.
lfFileName
,
String
May or may not contain the . (for instance .txt).
extension
,
LayoutFormatterPreferences layoutPreferences, SelfContainedSaveOrder saveOrder)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

public
TemplateExporter(String
Name to display to the user.
displayName
,
String
Name to call this format in the console.
consoleName
,
String
Name of the main layout file.
lfFileName
,
String
Directory in which to find the layout file (a blank string can be passed).
directory
,
FileType
Should contain the . (for instance .txt).
extension
,
LayoutFormatterPreferences layoutPreferences, SelfContainedSaveOrder saveOrder)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

public
TemplateExporter(String
Name to display to the user.
displayName
,
String
Name to call this format in the console.
consoleName
,
String
Name of the main layout file.
lfFileName
,
String
Directory in which to find the layout file (a blank string can be passed).
directory
,
FileType
Should contain the . (for instance .txt).
extension
,
LayoutFormatterPreferences
Preferences for layout
layoutPreferences
,
@Nullable SelfContainedSaveOrder saveOrder, BlankLineBehaviour
how to behave regarding blank lines.
blankLineBehaviour
)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

Method Summary

Modifier and TypeMethod and Description
public void
export(BibDatabaseContext databaseContext, Path file, List<BibEntry> entries)

public void
export(final BibDatabaseContext databaseContext, final Path file, List<BibEntry> entries, List<Path> fileDirForDatabase, JournalAbbreviationRepository abbreviationRepository)

Overrides org.jabref.logic.exporter.Exporter.export.

public String
public String
private Reader

Returns:

a newly created reader
getReader
(String
the filename
filename
)

This method should return a reader from which the given layout file can be read.

private void
readFormatterFile()

See if there is a name formatter file bundled with this export format.

public void
setCustomExport(boolean
true to indicate a custom export format.
custom
)

Indicate whether this is a custom export.

Inherited from org.jabref.logic.exporter.Exporter:
exportexportToAllFilesOfEntryexportToFileByPathgetFileTypegetIdgetNametoString

Field Detail

BEGIN_INFIXback to summary
private static final String BEGIN_INFIX
BLANK_LINE_PATTERNback to summary
private static final String BLANK_LINE_PATTERN
blankLineBehaviourback to summary
private final BlankLineBehaviour blankLineBehaviour
customExportback to summary
private boolean customExport
directoryback to summary
private final String directory
END_INFIXback to summary
private static final String END_INFIX
FORMATTERS_EXTENSIONback to summary
private static final String FORMATTERS_EXTENSION
LAYOUT_EXTENSIONback to summary
pack-priv static final String LAYOUT_EXTENSION
LAYOUT_PREFIXback to summary
pack-priv static final String LAYOUT_PREFIX
layoutPreferencesback to summary
private final LayoutFormatterPreferences layoutPreferences
lfFileNameback to summary
private final String lfFileName
LOGGERback to summary
private static final Logger LOGGER
saveOrderback to summary
private final SelfContainedSaveOrder saveOrder

Constructor Detail

TemplateExporterback to summary
public TemplateExporter(String name, String lfFileName, String extension, LayoutFormatterPreferences layoutPreferences, SelfContainedSaveOrder saveOrder)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

Parameters
name:String

to display to the user and to call this format in the console.

lfFileName:String

Name of the main layout file.

extension:String

May or may not contain the . (for instance .txt).

TemplateExporterback to summary
public TemplateExporter(String displayName, String consoleName, String lfFileName, String directory, FileType extension, LayoutFormatterPreferences layoutPreferences, SelfContainedSaveOrder saveOrder)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

Parameters
displayName:String

Name to display to the user.

consoleName:String

Name to call this format in the console.

lfFileName:String

Name of the main layout file.

directory:String

Directory in which to find the layout file (a blank string can be passed).

extension:FileType

Should contain the . (for instance .txt).

TemplateExporterback to summary
public TemplateExporter(String displayName, String consoleName, String lfFileName, String directory, FileType extension, LayoutFormatterPreferences layoutPreferences, @Nullable SelfContainedSaveOrder saveOrder, BlankLineBehaviour blankLineBehaviour)

Initialize another export format based on templates stored in dir with layoutFile lfFilename.

Parameters
displayName:String

Name to display to the user.

consoleName:String

Name to call this format in the console.

lfFileName:String

Name of the main layout file.

directory:String

Directory in which to find the layout file (a blank string can be passed).

extension:FileType

Should contain the . (for instance .txt).

layoutPreferences:LayoutFormatterPreferences

Preferences for layout

blankLineBehaviour:BlankLineBehaviour

how to behave regarding blank lines.

Method Detail

exportback to summary
public void export(BibDatabaseContext databaseContext, Path file, List<BibEntry> entries) throws IOException
Annotations
@Override
exportback to summary
public void export(final BibDatabaseContext databaseContext, final Path file, List<BibEntry> entries, List<Path> fileDirForDatabase, JournalAbbreviationRepository abbreviationRepository) throws IOException

Overrides org.jabref.logic.exporter.Exporter.export.

Annotations
@Override
getLayoutFileNameback to summary
public String getLayoutFileName()
getLayoutFileNameWithExtensionback to summary
public String getLayoutFileNameWithExtension()
getReaderback to summary
private Reader getReader(String filename) throws IOException

This method should return a reader from which the given layout file can be read.

Subclasses of TemplateExporter are free to override and provide their own implementation.

Parameters
filename:String

the filename

Returns:Reader

a newly created reader

Exceptions
IOException:
if the reader could not be created (e.g., file is not found)
readFormatterFileback to summary
private void readFormatterFile()

See if there is a name formatter file bundled with this export format. If so, read all the name formatters so they can be used by the filter layouts.

setCustomExportback to summary
public void setCustomExport(boolean custom)

Indicate whether this is a custom export. A custom export looks for its layout files using a normal file path, while a built-in export looks in the classpath.

Parameters
custom:boolean

true to indicate a custom export format.