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

public Class BibDatabaseWriter

extends Object
Class Inheritance
Imports
java.io.IOException, .Writer, java.nio.charset.Charset, .StandardCharsets, java.util.ArrayList, .Collections, .Comparator, .HashMap, .List, .Map, .Optional, .SortedSet, .TreeSet, java.util.function.Consumer, java.util.regex.Matcher, .Pattern, org.jabref.logic.bibtex.BibEntryWriter, .FieldPreferences, .FieldWriter, org.jabref.logic.bibtex.comparator.BibtexStringComparator, .CrossRefEntryComparator, .FieldComparator, .FieldComparatorStack, .IdComparator, org.jabref.logic.citationkeypattern.CitationKeyGenerator, .CitationKeyPatternPreferences, .GlobalCitationKeyPatterns, org.jabref.logic.cleanup.AbbreviateJournalCleanup, .FieldFormatterCleanup, .FieldFormatterCleanupActions, .NormalizeWhitespacesCleanup, org.jabref.logic.formatter.bibtexfields.TrimWhitespaceFormatter, org.jabref.logic.journals.JournalAbbreviationRepository, org.jabref.logic.preferences.CliPreferences, org.jabref.logic.util.strings.StringUtil, org.jabref.model.FieldChange, org.jabref.model.database.BibDatabase, .BibDatabaseContext, .BibDatabaseMode, org.jabref.model.entry.BibEntry, .BibEntryType, .BibEntryTypesManager, .BibtexString, org.jabref.model.entry.field.InternalField, org.jabref.model.metadata.MetaData, .SaveOrder, .SelfContainedSaveOrder, org.jooq.lambda.Unchecked, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

Writes a .bib file following the BibTeX / BibLaTeX format using the provided BibWriter

The opposite class is org.jabref.logic.importer.fileformat.BibtexImporter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
protected final BibWriter
private static final String
public static final String
protected final BibEntryTypesManager
protected final FieldPreferences
private @Nullable JournalAbbreviationRepository
protected final CitationKeyPatternPreferences
private static final Logger
private Consumer<Runnable>
private static final String
private static final Pattern
protected final List<FieldChange>
protected final SelfContainedSaveConfiguration
private static final String
private boolean

Constructor Summary

AccessConstructor and Description
public
BibDatabaseWriter(@NonNull BibWriter bibWriter, SelfContainedSaveConfiguration saveConfiguration, FieldPreferences fieldPreferences, CitationKeyPatternPreferences keyPatternPreferences, BibEntryTypesManager entryTypesManager)

public
BibDatabaseWriter(@NonNull Writer
the output to use
writer
,
@NonNull BibDatabaseContext
- used to get the newline
bibDatabaseContext
,
@NonNull CliPreferences
- used to read all the preferences
preferences
)

Convenience constructor.

Method Summary

Modifier and TypeMethod and Description
private static List<FieldChange>
applySaveActions(List<BibEntry> toChange, MetaData metaData, FieldPreferences fieldPreferences, Consumer<Runnable> mutationScheduler)

public static List<FieldChange>
applySaveActions(BibEntry entry, MetaData metaData, FieldPreferences fieldPreferences)

protected List<FieldChange>
generateCitationKeys(BibDatabaseContext databaseContext, List<BibEntry> entries, Consumer<Runnable> mutationScheduler)

Generate keys for all entries that are lacking keys.

public List<FieldChange>
private static List<Comparator<BibEntry>>
public static List<BibEntry>
getSortedEntries(@NonNull List<BibEntry> entriesToSort, @NonNull SelfContainedSaveOrder saveOrder)

We have begun to use getSortedEntries() for both database save operations and non-database save operations.

public BibDatabaseWriter
public BibDatabaseWriter
withMutationScheduler(Consumer<Runnable> mutationScheduler)

Routes BibEntry field mutations performed while saving to the correct thread.

public void
writeDatabase(@NonNull BibDatabaseContext bibDatabaseContext)

Saves the complete database.

protected void
writeDatabaseID(String sharedDatabaseID)

protected void
protected void
protected void
protected void
protected void
writeMetaData(@NonNull MetaData metaData, GlobalCitationKeyPatterns globalCiteKeyPattern)

Writes all data to the specified writer, using each object's toString() method.

protected void
public void
writePartOfDatabase(BibDatabaseContext bibDatabaseContext, List<BibEntry>
A list of entries to save. The list itself is not modified in this code
entries
)

Saves the database, including only the specified entries.

protected void
protected void
writeProlog(BibDatabaseContext bibDatabaseContext, Charset encoding)

protected void
writeString(BibtexString bibtexString, Map<String, BibtexString> remaining, int maxKeyLength)

protected void
writeString(BibtexString bibtexString, int maxKeyLength)

private void
writeStrings(BibDatabase
The database whose strings we should write.
database
)

Write all strings in alphabetical order, modified to produce a safe (for BibTeX) order of the strings if they reference each other.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bibWriterback to summary
protected final BibWriter bibWriter
COMMENT_PREFIXback to summary
private static final String COMMENT_PREFIX
DATABASE_ID_PREFIXback to summary
public static final String DATABASE_ID_PREFIX
entryTypesManagerback to summary
protected final BibEntryTypesManager entryTypesManager
fieldPreferencesback to summary
protected final FieldPreferences fieldPreferences
journalAbbreviationRepositoryback to summary
private @Nullable JournalAbbreviationRepository journalAbbreviationRepository
keyPatternPreferencesback to summary
protected final CitationKeyPatternPreferences keyPatternPreferences
LOGGERback to summary
private static final Logger LOGGER
mutationSchedulerback to summary
private Consumer<Runnable> mutationScheduler
PREAMBLE_PREFIXback to summary
private static final String PREAMBLE_PREFIX
REFERENCE_PATTERNback to summary
private static final Pattern REFERENCE_PATTERN
saveActionsFieldChangesback to summary
protected final List<FieldChange> saveActionsFieldChanges
saveConfigurationback to summary
protected final SelfContainedSaveConfiguration saveConfiguration
STRING_PREFIXback to summary
private static final String STRING_PREFIX
useFJournalFieldback to summary
private boolean useFJournalField

Constructor Detail

BibDatabaseWriterback to summary
public BibDatabaseWriter(@NonNull BibWriter bibWriter, SelfContainedSaveConfiguration saveConfiguration, FieldPreferences fieldPreferences, CitationKeyPatternPreferences keyPatternPreferences, BibEntryTypesManager entryTypesManager)
BibDatabaseWriterback to summary
public BibDatabaseWriter(@NonNull Writer writer, @NonNull BibDatabaseContext bibDatabaseContext, @NonNull CliPreferences preferences)

Convenience constructor. One can directly call writeDatabase(BibDatabaseContext) afterward.

Parameters
writer:@NonNull Writer

the output to use

bibDatabaseContext:@NonNull BibDatabaseContext

- used to get the newline

preferences:@NonNull CliPreferences

- used to read all the preferences

Method Detail

applySaveActionsback to summary
private static List<FieldChange> applySaveActions(List<BibEntry> toChange, MetaData metaData, FieldPreferences fieldPreferences, Consumer<Runnable> mutationScheduler)
applySaveActionsback to summary
public static List<FieldChange> applySaveActions(BibEntry entry, MetaData metaData, FieldPreferences fieldPreferences)
generateCitationKeysback to summary
protected List<FieldChange> generateCitationKeys(BibDatabaseContext databaseContext, List<BibEntry> entries, Consumer<Runnable> mutationScheduler)

Generate keys for all entries that are lacking keys.

getSaveActionsFieldChangesback to summary
public List<FieldChange> getSaveActionsFieldChanges()
getSaveComparatorsback to summary
private static List<Comparator<BibEntry>> getSaveComparators(SaveOrder saveOrder)
getSortedEntriesback to summary
public static List<BibEntry> getSortedEntries(@NonNull List<BibEntry> entriesToSort, @NonNull SelfContainedSaveOrder saveOrder)

We have begun to use getSortedEntries() for both database save operations and non-database save operations. In a non-database save operation (such as the exportDatabase call), we do not wish to use the global preference of saving in standard order.

withJournalAbbreviationRepositoryback to summary
public BibDatabaseWriter withJournalAbbreviationRepository(@NonNull JournalAbbreviationRepository repository, boolean useFJournalField)
withMutationSchedulerback to summary
public BibDatabaseWriter withMutationScheduler(Consumer<Runnable> mutationScheduler)

Routes BibEntry field mutations performed while saving to the correct thread. The scheduler must execute each mutation synchronously so the written file contains it.

writeDatabaseback to summary
public void writeDatabase(@NonNull BibDatabaseContext bibDatabaseContext) throws IOException

Saves the complete database.

writeDatabaseIDback to summary
protected void writeDatabaseID(String sharedDatabaseID) throws IOException
writeEntryback to summary
protected void writeEntry(BibEntry entry, BibDatabaseMode mode) throws IOException
writeEntryTypeDefinitionback to summary
protected void writeEntryTypeDefinition(BibEntryType customType) throws IOException
writeEntryTypeDefinitionsback to summary
protected void writeEntryTypeDefinitions(SortedSet<BibEntryType> types) throws IOException
writeEpilogueback to summary
protected void writeEpilogue(String epilogue) throws IOException
writeMetaDataback to summary
protected void writeMetaData(@NonNull MetaData metaData, GlobalCitationKeyPatterns globalCiteKeyPattern) throws IOException

Writes all data to the specified writer, using each object's toString() method.

writeMetaDataItemback to summary
protected void writeMetaDataItem(Map.Entry<String, String> metaItem) throws IOException
writePartOfDatabaseback to summary
public void writePartOfDatabase(BibDatabaseContext bibDatabaseContext, List<BibEntry> entries) throws IOException

Saves the database, including only the specified entries.

Parameters
entries:List<BibEntry>

A list of entries to save. The list itself is not modified in this code

writePreambleback to summary
protected void writePreamble(String preamble) throws IOException
writePrologback to summary
protected void writeProlog(BibDatabaseContext bibDatabaseContext, Charset encoding) throws IOException
writeStringback to summary
protected void writeString(BibtexString bibtexString, Map<String, BibtexString> remaining, int maxKeyLength) throws IOException
writeStringback to summary
protected void writeString(BibtexString bibtexString, int maxKeyLength) throws IOException
writeStringsback to summary
private void writeStrings(BibDatabase database) throws IOException

Write all strings in alphabetical order, modified to produce a safe (for BibTeX) order of the strings if they reference each other.

Parameters
database:BibDatabase

The database whose strings we should write.

org.jabref.logic.exporter back to summary

public final Enum BibDatabaseWriter.SaveType

extends Enum<BibDatabaseWriter.SaveType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final BibDatabaseWriter.SaveType
public static final BibDatabaseWriter.SaveType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BibDatabaseWriter.SaveType
public static BibDatabaseWriter.SaveType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

PLAIN_BIBTEXback to summary
public static final BibDatabaseWriter.SaveType PLAIN_BIBTEX
WITH_JABREF_META_DATAback to summary
public static final BibDatabaseWriter.SaveType WITH_JABREF_META_DATA

Constructor Detail

SaveTypeback to summary
private SaveType()

Method Detail

valueOfback to summary
public static BibDatabaseWriter.SaveType valueOf(String name)
valuesback to summary
public static BibDatabaseWriter.SaveType[] values()