diff --git a/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java b/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java
index 677e2090a68..2ccf1492940 100644
--- a/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java
+++ b/jabgui/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java
@@ -26,8 +26,8 @@
import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.logic.bibtex.InvalidFieldValueException;
import org.jabref.logic.exporter.AtomicFileWriter;
+import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.logic.util.BackupFileType;
@@ -281,7 +281,7 @@ void performBackup(Path backupPath) {
// This MUST NOT create a broken backup file that then jabref wants to "restore" from?
try (Writer writer = new AtomicFileWriter(backupPath, encoding, false)) {
BibWriter bibWriter = new BibWriter(writer, bibDatabaseContext.getDatabase().getNewLineSeparator());
- new BibtexDatabaseWriter(
+ new BibDatabaseWriter(
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
diff --git a/jabgui/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/jabgui/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
index 223d1efdcb0..bfb39ee2e45 100644
--- a/jabgui/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
+++ b/jabgui/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
@@ -30,7 +30,6 @@
import org.jabref.logic.exporter.AtomicFileWriter;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.l10n.Encodings;
@@ -263,7 +262,7 @@ private boolean saveDatabase(Path file, boolean selectedOnly, Charset encoding,
synchronized (bibDatabaseContext) {
try (AtomicFileWriter fileWriter = new AtomicFileWriter(file, encoding, saveConfiguration.shouldMakeBackup())) {
BibWriter bibWriter = new BibWriter(fileWriter, bibDatabaseContext.getDatabase().getNewLineSeparator());
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
diff --git a/jabgui/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java b/jabgui/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java
index 2f47b10d957..497c0aa7d39 100644
--- a/jabgui/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java
+++ b/jabgui/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java
@@ -10,7 +10,6 @@
import org.jabref.logic.exporter.AtomicFileWriter;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.model.database.BibDatabase;
@@ -66,7 +65,7 @@ void setup(@TempDir Path tempDir) throws IOException {
private void saveDatabase() throws IOException {
try (Writer writer = new AtomicFileWriter(testBib, StandardCharsets.UTF_8, false)) {
BibWriter bibWriter = new BibWriter(writer, bibDatabaseContext.getDatabase().getNewLineSeparator());
- new BibtexDatabaseWriter(
+ new BibDatabaseWriter(
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
diff --git a/jabkit/src/main/java/org/jabref/cli/ArgumentProcessor.java b/jabkit/src/main/java/org/jabref/cli/ArgumentProcessor.java
index 040b06f6237..780a33e4e08 100644
--- a/jabkit/src/main/java/org/jabref/cli/ArgumentProcessor.java
+++ b/jabkit/src/main/java/org/jabref/cli/ArgumentProcessor.java
@@ -12,7 +12,6 @@
import org.jabref.logic.exporter.AtomicFileWriter;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.importer.FetcherException;
@@ -156,7 +155,7 @@ protected static void saveDatabase(CliPreferences cliPreferences,
BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE);
SelfContainedSaveConfiguration saveConfiguration = (SelfContainedSaveConfiguration) new SelfContainedSaveConfiguration()
.withReformatOnSave(cliPreferences.getLibraryPreferences().shouldAlwaysReformatOnSave());
- BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
cliPreferences.getFieldPreferences(),
diff --git a/jablib/src/jmh/java/org/jabref/benchmarks/Benchmarks.java b/jablib/src/jmh/java/org/jabref/benchmarks/Benchmarks.java
index 59ded0d226f..97a379b4e6f 100644
--- a/jablib/src/jmh/java/org/jabref/benchmarks/Benchmarks.java
+++ b/jablib/src/jmh/java/org/jabref/benchmarks/Benchmarks.java
@@ -10,7 +10,6 @@
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import org.jabref.logic.importer.ParserResult;
@@ -83,7 +82,7 @@ private StringWriter getOutputWriter() throws IOException {
FieldPreferences fieldPreferences = new FieldPreferences(true, List.of(), List.of());
CitationKeyPatternPreferences citationKeyPatternPreferences = mock(CitationKeyPatternPreferences.class, Answers.RETURNS_DEEP_STUBS);
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
diff --git a/jablib/src/main/java/org/jabref/logic/crawler/StudyRepository.java b/jablib/src/main/java/org/jabref/logic/crawler/StudyRepository.java
index 0978b6b7f7f..fc1e694bb56 100644
--- a/jablib/src/main/java/org/jabref/logic/crawler/StudyRepository.java
+++ b/jablib/src/main/java/org/jabref/logic/crawler/StudyRepository.java
@@ -14,8 +14,8 @@
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.database.DatabaseMerger;
import org.jabref.logic.exporter.AtomicFileWriter;
+import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SaveException;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.git.SlrGitHandler;
@@ -431,7 +431,7 @@ private void writeResultToFile(Path pathToFile, BibDatabaseContext context) thro
.withSaveOrder(context.getMetaData().getSaveOrder().map(SelfContainedSaveOrder::of).orElse(SaveOrder.getDefaultSaveOrder()))
.withReformatOnSave(preferences.getLibraryPreferences().shouldAlwaysReformatOnSave());
BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE);
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
preferences.getFieldPreferences(),
diff --git a/jablib/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java b/jablib/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java
index 6f3e5e88c94..089d54001b1 100644
--- a/jablib/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java
+++ b/jablib/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java
@@ -1,6 +1,7 @@
package org.jabref.logic.exporter;
import java.io.IOException;
+import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -16,7 +17,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldPreferences;
+import org.jabref.logic.bibtex.FieldWriter;
+import org.jabref.logic.bibtex.InvalidFieldValueException;
import org.jabref.logic.bibtex.comparator.BibtexStringComparator;
import org.jabref.logic.bibtex.comparator.CrossRefEntryComparator;
import org.jabref.logic.bibtex.comparator.FieldComparator;
@@ -44,20 +48,25 @@
import org.jabref.model.strings.StringUtil;
import org.jooq.lambda.Unchecked;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * 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.
+ * Writes a .bib file following the BibTeX / BibLaTeX format using the provided {@link BibWriter}
*
- * Currently, {@link BibtexDatabaseWriter} is the only subclass of this class (and that class writes a .bib file)
- *
- * The opposite class is {@link org.jabref.logic.importer.fileformat.BibtexParser}
+ * The opposite class is {@link org.jabref.logic.importer.fileformat.BibtexImporter}
*/
-public abstract class BibDatabaseWriter {
-
+public class BibDatabaseWriter {
public enum SaveType { WITH_JABREF_META_DATA, PLAIN_BIBTEX }
+ public static final String DATABASE_ID_PREFIX = "DBID:";
+ private static final Logger LOGGER = LoggerFactory.getLogger(BibDatabaseWriter.class);
private static final Pattern REFERENCE_PATTERN = Pattern.compile("(#[A-Za-z]+#)"); // Used to detect string references in strings
+ private static final String COMMENT_PREFIX = "@Comment";
+ private static final String PREAMBLE_PREFIX = "@Preamble";
+
+ private static final String STRING_PREFIX = "@String";
+
protected final BibWriter bibWriter;
protected final SelfContainedSaveConfiguration saveConfiguration;
protected final CitationKeyPatternPreferences keyPatternPreferences;
@@ -78,6 +87,19 @@ public BibDatabaseWriter(BibWriter bibWriter,
assert saveConfiguration.getSaveOrder().getOrderType() != SaveOrder.OrderType.TABLE;
}
+ public BibDatabaseWriter(Writer writer,
+ String newline,
+ SelfContainedSaveConfiguration saveConfiguration,
+ FieldPreferences fieldPreferences,
+ CitationKeyPatternPreferences citationKeyPatternPreferences,
+ BibEntryTypesManager entryTypesManager) {
+ this(new BibWriter(writer, newline),
+ saveConfiguration,
+ fieldPreferences,
+ citationKeyPatternPreferences,
+ entryTypesManager);
+ }
+
private static List applySaveActions(List toChange, MetaData metaData, FieldPreferences fieldPreferences) {
List changes = new ArrayList<>();
@@ -224,11 +246,31 @@ public void savePartOfDatabase(BibDatabaseContext bibDatabaseContext, List metaItem) throws IOException;
+ protected void writeMetaDataItem(Map.Entry metaItem) throws IOException {
+ bibWriter.write(COMMENT_PREFIX + "{");
+ bibWriter.write(MetaData.META_FLAG);
+ bibWriter.write(metaItem.getKey());
+ bibWriter.write(":");
+ bibWriter.write(metaItem.getValue());
+ bibWriter.write("}");
+ bibWriter.finishBlock();
+ }
- protected abstract void writePreamble(String preamble) throws IOException;
+ protected void writePreamble(String preamble) throws IOException {
+ if (!StringUtil.isNullOrEmpty(preamble)) {
+ bibWriter.write(PREAMBLE_PREFIX + "{");
+ bibWriter.write(preamble);
+ bibWriter.writeLine("}");
+ bibWriter.finishBlock();
+ }
+ }
- protected abstract void writeDatabaseID(String sharedDatabaseID) throws IOException;
+ protected void writeDatabaseID(String sharedDatabaseID) throws IOException {
+ bibWriter.write("% ");
+ bibWriter.write(DATABASE_ID_PREFIX);
+ bibWriter.write(" ");
+ bibWriter.writeLine(sharedDatabaseID);
+ }
/**
* Write all strings in alphabetical order, modified to produce a safe (for BibTeX) order of the strings if they
@@ -307,8 +369,36 @@ protected void writeString(BibtexString bibtexString, Map
writeString(bibtexString, maxKeyLength);
}
- protected abstract void writeString(BibtexString bibtexString, int maxKeyLength)
- throws IOException;
+ protected void writeString(BibtexString bibtexString, int maxKeyLength) throws IOException {
+ // If the string has not been modified, write it back as it was
+ if (!saveConfiguration.shouldReformatFile() && !bibtexString.hasChanged()) {
+ LOGGER.debug("Writing parsed serialization {}.", bibtexString.getParsedSerialization());
+ bibWriter.write(bibtexString.getParsedSerialization());
+ return;
+ }
+
+ // Write user comments
+ String userComments = bibtexString.getUserComments();
+ if (!userComments.isEmpty()) {
+ bibWriter.writeLine(userComments);
+ }
+
+ bibWriter.write(STRING_PREFIX + "{" + bibtexString.getName() + StringUtil
+ .repeatSpaces(maxKeyLength - bibtexString.getName().length()) + " = ");
+ if (bibtexString.getContent().isEmpty()) {
+ bibWriter.write("{}");
+ } else {
+ try {
+ String formatted = new FieldWriter(fieldPreferences)
+ .write(InternalField.BIBTEX_STRING, bibtexString.getContent());
+ bibWriter.write(formatted);
+ } catch (InvalidFieldValueException ex) {
+ throw new IOException(ex);
+ }
+ }
+
+ bibWriter.writeLine("}");
+ }
protected void writeEntryTypeDefinitions(SortedSet types) throws IOException {
for (BibEntryType type : types) {
@@ -316,7 +406,12 @@ protected void writeEntryTypeDefinitions(SortedSet types) throws I
}
}
- protected abstract void writeEntryTypeDefinition(BibEntryType customType) throws IOException;
+ protected void writeEntryTypeDefinition(BibEntryType customType) throws IOException {
+ bibWriter.write(COMMENT_PREFIX + "{");
+ bibWriter.write(MetaDataSerializer.serializeCustomEntryTypes(customType));
+ bibWriter.writeLine("}");
+ bibWriter.finishBlock();
+ }
/**
* Generate keys for all entries that are lacking keys.
diff --git a/jablib/src/main/java/org/jabref/logic/exporter/BibWriter.java b/jablib/src/main/java/org/jabref/logic/exporter/BibWriter.java
index 86422e9adf4..ad968e2ac90 100644
--- a/jablib/src/main/java/org/jabref/logic/exporter/BibWriter.java
+++ b/jablib/src/main/java/org/jabref/logic/exporter/BibWriter.java
@@ -6,7 +6,7 @@
import org.jabref.model.strings.StringUtil;
/**
- * Class to write to a .bib file. Used by {@link BibtexDatabaseWriter}
+ * Class to write to a .bib file. Used by {@link BibDatabaseWriter}
*/
public class BibWriter {
diff --git a/jablib/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java b/jablib/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java
deleted file mode 100644
index 2c1a1533083..00000000000
--- a/jablib/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package org.jabref.logic.exporter;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-
-import org.jabref.logic.bibtex.BibEntryWriter;
-import org.jabref.logic.bibtex.FieldPreferences;
-import org.jabref.logic.bibtex.FieldWriter;
-import org.jabref.logic.bibtex.InvalidFieldValueException;
-import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
-import org.jabref.model.database.BibDatabaseContext;
-import org.jabref.model.database.BibDatabaseMode;
-import org.jabref.model.entry.BibEntry;
-import org.jabref.model.entry.BibEntryType;
-import org.jabref.model.entry.BibEntryTypesManager;
-import org.jabref.model.entry.BibtexString;
-import org.jabref.model.entry.field.InternalField;
-import org.jabref.model.metadata.MetaData;
-import org.jabref.model.strings.StringUtil;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Writes a .bib file following the BibTeX / BibLaTeX format using the provided {@link BibWriter}.
- * Reading is done by {@link org.jabref.logic.importer.fileformat.BibtexImporter}.
- */
-public class BibtexDatabaseWriter extends BibDatabaseWriter {
-
- public static final String DATABASE_ID_PREFIX = "DBID:";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(BibtexDatabaseWriter.class);
-
- private static final String COMMENT_PREFIX = "@Comment";
- private static final String PREAMBLE_PREFIX = "@Preamble";
- private static final String STRING_PREFIX = "@String";
-
- public BibtexDatabaseWriter(BibWriter bibWriter,
- SelfContainedSaveConfiguration saveConfiguration,
- FieldPreferences fieldPreferences,
- CitationKeyPatternPreferences citationKeyPatternPreferences,
- BibEntryTypesManager entryTypesManager) {
- super(bibWriter,
- saveConfiguration,
- fieldPreferences,
- citationKeyPatternPreferences,
- entryTypesManager);
- }
-
- public BibtexDatabaseWriter(Writer writer,
- String newline,
- SelfContainedSaveConfiguration saveConfiguration,
- FieldPreferences fieldPreferences,
- CitationKeyPatternPreferences citationKeyPatternPreferences,
- BibEntryTypesManager entryTypesManager) {
- super(new BibWriter(writer, newline),
- saveConfiguration,
- fieldPreferences,
- citationKeyPatternPreferences,
- entryTypesManager);
- }
-
- @Override
- protected void writeEpilogue(String epilogue) throws IOException {
- if (!StringUtil.isNullOrEmpty(epilogue)) {
- bibWriter.write(epilogue);
- bibWriter.finishBlock();
- }
- }
-
- @Override
- protected void writeMetaDataItem(Map.Entry metaItem) throws IOException {
- bibWriter.write(COMMENT_PREFIX + "{");
- bibWriter.write(MetaData.META_FLAG);
- bibWriter.write(metaItem.getKey());
- bibWriter.write(":");
- bibWriter.write(metaItem.getValue());
- bibWriter.write("}");
- bibWriter.finishBlock();
- }
-
- @Override
- protected void writePreamble(String preamble) throws IOException {
- if (!StringUtil.isNullOrEmpty(preamble)) {
- bibWriter.write(PREAMBLE_PREFIX + "{");
- bibWriter.write(preamble);
- bibWriter.writeLine("}");
- bibWriter.finishBlock();
- }
- }
-
- @Override
- protected void writeString(BibtexString bibtexString, int maxKeyLength) throws IOException {
- // If the string has not been modified, write it back as it was
- if (!saveConfiguration.shouldReformatFile() && !bibtexString.hasChanged()) {
- LOGGER.debug("Writing parsed serialization {}.", bibtexString.getParsedSerialization());
- bibWriter.write(bibtexString.getParsedSerialization());
- return;
- }
-
- // Write user comments
- String userComments = bibtexString.getUserComments();
- if (!userComments.isEmpty()) {
- bibWriter.writeLine(userComments);
- }
-
- bibWriter.write(STRING_PREFIX + "{" + bibtexString.getName() + StringUtil
- .repeatSpaces(maxKeyLength - bibtexString.getName().length()) + " = ");
- if (bibtexString.getContent().isEmpty()) {
- bibWriter.write("{}");
- } else {
- try {
- String formatted = new FieldWriter(fieldPreferences)
- .write(InternalField.BIBTEX_STRING, bibtexString.getContent());
- bibWriter.write(formatted);
- } catch (InvalidFieldValueException ex) {
- throw new IOException(ex);
- }
- }
-
- bibWriter.writeLine("}");
- }
-
- @Override
- protected void writeEntryTypeDefinition(BibEntryType customType) throws IOException {
- bibWriter.write(COMMENT_PREFIX + "{");
- bibWriter.write(MetaDataSerializer.serializeCustomEntryTypes(customType));
- bibWriter.writeLine("}");
- bibWriter.finishBlock();
- }
-
- @Override
- protected void writeProlog(BibDatabaseContext bibDatabaseContext, Charset encoding) throws IOException {
- // We write the encoding if
- // - it is provided (!= null)
- // - explicitly set in the .bib file OR not equal to UTF_8
- // Otherwise, we do not write anything and return
- if ((encoding == null) || (!bibDatabaseContext.getMetaData().getEncodingExplicitlySupplied() && (encoding.equals(StandardCharsets.UTF_8)))) {
- return;
- }
-
- // Writes the file encoding information.
- bibWriter.write("% ");
- bibWriter.writeLine(SaveConfiguration.ENCODING_PREFIX + encoding);
- }
-
- @Override
- protected void writeDatabaseID(String sharedDatabaseID) throws IOException {
- bibWriter.write("% ");
- bibWriter.write(DATABASE_ID_PREFIX);
- bibWriter.write(" ");
- bibWriter.writeLine(sharedDatabaseID);
- }
-
- @Override
- protected void writeEntry(BibEntry entry, BibDatabaseMode mode) throws IOException {
- BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(fieldPreferences), entryTypesManager);
- bibtexEntryWriter.write(entry, bibWriter, mode, saveConfiguration.shouldReformatFile());
- }
-}
diff --git a/jablib/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java b/jablib/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java
index da0f76998dd..15bb0f2be02 100644
--- a/jablib/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java
+++ b/jablib/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java
@@ -26,7 +26,7 @@
import javax.xml.parsers.ParserConfigurationException;
import org.jabref.logic.bibtex.FieldWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
+import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.SaveConfiguration;
import org.jabref.logic.groups.DefaultGroupsFactory;
import org.jabref.logic.importer.ImportFormatPreferences;
@@ -214,7 +214,7 @@ private void parseDatabaseID() throws IOException {
skipWhitespace();
String label = parseTextToken().trim();
- if (BibtexDatabaseWriter.DATABASE_ID_PREFIX.equals(label)) {
+ if (BibDatabaseWriter.DATABASE_ID_PREFIX.equals(label)) {
skipWhitespace();
database.setSharedDatabaseID(parseTextToken().trim());
}
@@ -471,8 +471,8 @@ private String dumpTextReadSoFarToString() {
// if there is no entry found, simply return the content (necessary to parse text remaining after the last entry)
if (indexOfAt == -1) {
return purgeEOFCharacters(result);
- } else if (result.contains(BibtexDatabaseWriter.DATABASE_ID_PREFIX)) {
- return purge(result, BibtexDatabaseWriter.DATABASE_ID_PREFIX);
+ } else if (result.contains(BibDatabaseWriter.DATABASE_ID_PREFIX)) {
+ return purge(result, BibDatabaseWriter.DATABASE_ID_PREFIX);
} else if (result.contains(SaveConfiguration.ENCODING_PREFIX)) {
return purge(result, SaveConfiguration.ENCODING_PREFIX);
} else {
diff --git a/jablib/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/jablib/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java
index ef383fafab0..07d721ce54b 100644
--- a/jablib/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java
+++ b/jablib/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java
@@ -64,9 +64,9 @@
/**
* Tests for reading can be found at {@link org.jabref.logic.importer.fileformat.BibtexImporterTest}
*/
-class BibtexDatabaseWriterTest {
+class BibDatabaseWriterTest {
- private BibtexDatabaseWriter databaseWriter;
+ private BibDatabaseWriter databaseWriter;
private BibDatabase database;
private MetaData metaData;
private BibDatabaseContext bibtexContext;
@@ -95,7 +95,7 @@ void setUp() {
}
private void initializeDatabaseWriter() {
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -461,7 +461,7 @@ void roundtripUtf8EncodingHeaderRemoved() throws IOException {
@Test
void roundtripWin1252HeaderKept(@TempDir Path bibFolder) throws IOException, URISyntaxException {
- Path testFile = Path.of(BibtexDatabaseWriterTest.class.getResource("encoding-windows-1252-with-header.bib").toURI());
+ Path testFile = Path.of(BibDatabaseWriterTest.class.getResource("encoding-windows-1252-with-header.bib").toURI());
ParserResult result = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()).importDatabase(testFile);
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData());
@@ -471,7 +471,7 @@ void roundtripWin1252HeaderKept(@TempDir Path bibFolder) throws IOException, URI
try (BufferedWriter fileWriter = Files.newBufferedWriter(file, charset)) {
BibWriter bibWriter = new BibWriter(fileWriter, context.getDatabase().getNewLineSeparator());
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -485,7 +485,7 @@ void roundtripWin1252HeaderKept(@TempDir Path bibFolder) throws IOException, URI
@Test
void roundtripUtf8HeaderKept(@TempDir Path bibFolder) throws URISyntaxException, IOException {
- Path testFile = Path.of(BibtexDatabaseWriterTest.class.getResource("encoding-utf-8-with-header-with-databasetypecomment.bib").toURI());
+ Path testFile = Path.of(BibDatabaseWriterTest.class.getResource("encoding-utf-8-with-header-with-databasetypecomment.bib").toURI());
ParserResult result = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()).importDatabase(testFile);
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData());
@@ -495,7 +495,7 @@ void roundtripUtf8HeaderKept(@TempDir Path bibFolder) throws URISyntaxException,
try (BufferedWriter fileWriter = Files.newBufferedWriter(file, charset)) {
BibWriter bibWriter = new BibWriter(fileWriter, context.getDatabase().getNewLineSeparator());
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -509,7 +509,7 @@ void roundtripUtf8HeaderKept(@TempDir Path bibFolder) throws URISyntaxException,
@Test
void roundtripNotExplicitUtf8HeaderNotInsertedDuringWrite(@TempDir Path bibFolder) throws URISyntaxException, IOException {
- Path testFile = Path.of(BibtexDatabaseWriterTest.class.getResource("encoding-utf-8-without-header-with-databasetypecomment.bib").toURI());
+ Path testFile = Path.of(BibDatabaseWriterTest.class.getResource("encoding-utf-8-without-header-with-databasetypecomment.bib").toURI());
ParserResult result = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()).importDatabase(testFile);
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData());
@@ -519,7 +519,7 @@ void roundtripNotExplicitUtf8HeaderNotInsertedDuringWrite(@TempDir Path bibFolde
try (BufferedWriter fileWriter = Files.newBufferedWriter(file, charset)) {
BibWriter bibWriter = new BibWriter(fileWriter, context.getDatabase().getNewLineSeparator());
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -540,7 +540,7 @@ void roundtripWithComplexBib() throws IOException {
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData());
BibWriter bibWriter = new BibWriter(stringWriter, context.getDatabase().getNewLineSeparator());
- BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
+ BibDatabaseWriter databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -587,7 +587,7 @@ void roundtripWithOneUserCommentAndEntryChange() throws IOException {
// we need a new writer because "\n" instead of "OS.NEWLINE"
bibWriter = new BibWriter(stringWriter, "\n");
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -620,7 +620,7 @@ void roundtripWithTwoEntriesAndOneUserCommentAndEntryChange() throws IOException
// we need a new writer because "\n" instead of "OS.NEWLINE"
bibWriter = new BibWriter(stringWriter, "\n");
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -1001,7 +1001,7 @@ void saveAlsoSavesSecondModification() throws IOException {
// write a second time
stringWriter = new StringWriter();
bibWriter = new BibWriter(stringWriter, OS.NEWLINE);
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
@@ -1080,7 +1080,7 @@ void saveReturnsToOriginalEntryWhenEntryIsFlaggedUnchangedEvenInThePresenceOfSav
// write a second time
stringWriter = new StringWriter();
bibWriter = new BibWriter(stringWriter, OS.NEWLINE);
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,
diff --git a/jablib/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java b/jablib/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java
index a4f3bedda03..6ea6a833752 100644
--- a/jablib/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java
+++ b/jablib/src/test/java/org/jabref/logic/importer/fileformat/BibtexImporterTest.java
@@ -34,7 +34,7 @@
/**
* This class tests the BibtexImporter.
*
- * Tests for writing can be found at {@link org.jabref.logic.exporter.BibtexDatabaseWriterTest}.
+ * Tests for writing can be found at {@link org.jabref.logic.exporter.BibDatabaseWriterTest}.
* Tests for parsing single entry BibTeX can be found at {@link BibtexParserTest}
*/
class BibtexImporterTest {
diff --git a/jablib/src/test/java/org/jabref/logic/pseudonymization/PseudonymizationTest.java b/jablib/src/test/java/org/jabref/logic/pseudonymization/PseudonymizationTest.java
index 9a70905f1f3..ad6beaf2602 100644
--- a/jablib/src/test/java/org/jabref/logic/pseudonymization/PseudonymizationTest.java
+++ b/jablib/src/test/java/org/jabref/logic/pseudonymization/PseudonymizationTest.java
@@ -12,7 +12,6 @@
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.exporter.BibDatabaseWriter;
import org.jabref.logic.exporter.BibWriter;
-import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SelfContainedSaveConfiguration;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.fileformat.BibtexImporter;
@@ -38,7 +37,7 @@ class PseudonymizationTest {
private BibtexImporter importer;
- private BibtexDatabaseWriter databaseWriter;
+ private BibDatabaseWriter databaseWriter;
private StringWriter stringWriter;
private BibWriter bibWriter;
private SelfContainedSaveConfiguration saveConfiguration;
@@ -57,7 +56,7 @@ void setUp() {
citationKeyPatternPreferences = mock(CitationKeyPatternPreferences.class, Answers.RETURNS_DEEP_STUBS);
entryTypesManager = new BibEntryTypesManager();
- databaseWriter = new BibtexDatabaseWriter(
+ databaseWriter = new BibDatabaseWriter(
bibWriter,
saveConfiguration,
fieldPreferences,