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

public abstract Class BibDatabaseWriter

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.logic.exporter.BibtexDatabaseWriter
Imports
java.io.IOException, java.nio.charset.Charset, .StandardCharsets, java.util.ArrayList, .Collections, .Comparator, .HashMap, .List, .Map, .Objects, .Optional, .SortedSet, .TreeSet, java.util.regex.Matcher, .Pattern, org.jabref.logic.bibtex.FieldPreferences, org.jabref.logic.bibtex.comparator.BibtexStringComparator, .CrossRefEntryComparator, .FieldComparator, .FieldComparatorStack, .IdComparator, org.jabref.logic.citationkeypattern.CitationKeyGenerator, .CitationKeyPatternPreferences, .GlobalCitationKeyPatterns, org.jabref.logic.cleanup.FieldFormatterCleanup, .FieldFormatterCleanups, .NormalizeWhitespacesCleanup, org.jabref.logic.formatter.bibtexfields.TrimWhitespaceFormatter, 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.jabref.model.strings.StringUtil, org.jooq.lambda.Unchecked

A generic writer for our database. This is independent of the concrete serialization format. For instance, we could also write out YAML or XML by subclassing this class.

Currently, BibtexDatabaseWriter is the only subclass of this class (and that class writes a .bib file)

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
protected final BibWriter
protected final BibEntryTypesManager
protected final FieldPreferences
protected final CitationKeyPatternPreferences
private static final Pattern
protected final List<FieldChange>
protected final SelfContainedSaveConfiguration

Constructor Summary

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

Method Summary

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

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

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

Generate keys for all entries that are lacking keys.

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

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

public void
saveDatabase(BibDatabaseContext bibDatabaseContext)

Saves the complete database.

public void
savePartOfDatabase(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 abstract void
writeDatabaseID(String sharedDatabaseID)

protected abstract void
protected abstract void
protected void
protected abstract void
protected void
writeMetaData(MetaData metaData, GlobalCitationKeyPatterns globalCiteKeyPattern)

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

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

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

protected abstract 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
entryTypesManagerback to summary
protected final BibEntryTypesManager entryTypesManager
fieldPreferencesback to summary
protected final FieldPreferences fieldPreferences
keyPatternPreferencesback to summary
protected final CitationKeyPatternPreferences keyPatternPreferences
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

Constructor Detail

BibDatabaseWriterback to summary
public BibDatabaseWriter(BibWriter bibWriter, SelfContainedSaveConfiguration saveConfiguration, FieldPreferences fieldPreferences, CitationKeyPatternPreferences keyPatternPreferences, BibEntryTypesManager entryTypesManager)

Method Detail

applySaveActionsback to summary
private static List<FieldChange> applySaveActions(List<BibEntry> toChange, MetaData metaData, FieldPreferences fieldPreferences)
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)

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(List<BibEntry> entriesToSort, 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.

saveDatabaseback to summary
public void saveDatabase(BibDatabaseContext bibDatabaseContext) throws IOException

Saves the complete database.

savePartOfDatabaseback to summary
public void savePartOfDatabase(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

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

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

writeMetaDataItemback to summary
protected abstract void writeMetaDataItem(Map.Entry<String, String> metaItem) throws IOException
writePreambleback to summary
protected abstract void writePreamble(String preamble) throws IOException
writePrologback to summary
protected abstract 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 abstract 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()