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

public Class FieldWriter

extends Object
Class Inheritance
Imports
java.util.ArrayDeque, .ArrayList, .Deque, .List, org.jabref.logic.l10n.Localization, org.jabref.model.entry.field.Field, .InternalField, org.slf4j.Logger, .LoggerFactory

Converts JabRef's internal BibTeX representation of a BibTeX field to BibTeX text representation

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
public static final char
private static final char
private static final char
private static final Logger
private final FieldPreferences

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static List<String>

Returns:

list of balancing errors
checkBalancedBraces
(String text)

Checks text for balanced braces and returns a list of unbalanced

private String
formatAndResolveStrings(String content)

This method handles # in the field content to get valid bibtex strings

For instance, #jan# - #feb# gets jan #{ - } # feb (see @link{org.jabref.logic.bibtex.LatexFieldFormatterTests#makeHashEnclosedWordsRealStringsInMonthField()})

private String
private static String
getContextSnippet(String text, int index)

private static int
getFirstOccurrenceOfStartEndSymbol(String content, int pivot)

Finds the first occurrence of # from the pivot point

public static boolean

Returns:

true if the character at the specified index is escaped, false otherwise
isEscaped
(String
the input string to check for escaped characters
text
,
int
the index of the character in the text to check for escaping
index
)

Checks if the character at the specified index in the given text is escaped.

public static String

Returns:

sanitized text
sanitizeUnbalancedBraces
(String
the text to sanitize
text
)

Escapes the last unbalanced curly brace in the given text.

private boolean
public String

Returns:

a formatted string suitable for output
write
(Field
the name of the field - used to trigger different serializations, e.g., turning off resolution for some strings
field
,
String
the content of the field
content
)

Formats the content of a field.

private void
writeStringLabel(StringBuilder
the StringBuilder to append the text to
stringBuilder
,
String
the text use as basis to get the text to append
text
,
int
the position in text where the text to add starts
startPos
,
int
the position in text where the text to add ends
endPos
,
boolean
true if the label to write is the first one to write
isFirst
,
boolean
true if the label to write is the last one to write
isLast
)

private void
writeText(StringBuilder
the StringBuilder to append the text to
stringBuilder
,
String
the text to append
text
,
int startPos, int endPos)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIBTEX_STRING_START_END_SYMBOLback to summary
public static final char BIBTEX_STRING_START_END_SYMBOL
FIELD_ENDback to summary
private static final char FIELD_END
FIELD_STARTback to summary
private static final char FIELD_START
LOGGERback to summary
private static final Logger LOGGER
preferencesback to summary
private final FieldPreferences preferences

Constructor Detail

FieldWriterback to summary
public FieldWriter(FieldPreferences preferences)

Method Detail

checkBalancedBracesback to summary
public static List<String> checkBalancedBraces(String text)

Checks text for balanced braces and returns a list of unbalanced

Returns:List<String>

list of balancing errors

formatAndResolveStringsback to summary
private String formatAndResolveStrings(String content)

This method handles # in the field content to get valid bibtex strings

For instance, #jan# - #feb# gets jan #{ - } # feb (see @link{org.jabref.logic.bibtex.LatexFieldFormatterTests#makeHashEnclosedWordsRealStringsInMonthField()})

formatWithoutResolvingStringsback to summary
private String formatWithoutResolvingStrings(String content)
getContextSnippetback to summary
private static String getContextSnippet(String text, int index)
getFirstOccurrenceOfStartEndSymbolback to summary
private static int getFirstOccurrenceOfStartEndSymbol(String content, int pivot)

Finds the first occurrence of # from the pivot point

isEscapedback to summary
public static boolean isEscaped(String text, int index)

Checks if the character at the specified index in the given text is escaped. A character is considered escaped if it is preceded by an odd number of backslashes ().

Parameters
text:String

the input string to check for escaped characters

index:int

the index of the character in the text to check for escaping

Returns:boolean

true if the character at the specified index is escaped, false otherwise

sanitizeUnbalancedBracesback to summary
public static String sanitizeUnbalancedBraces(String text)

Escapes the last unbalanced curly brace in the given text.

Parameters
text:String

the text to sanitize

Returns:String

sanitized text

shouldResolveStringsback to summary
private boolean shouldResolveStrings(Field field)
writeback to summary
public String write(Field field, String content)

Formats the content of a field.

Parameters
field:Field

the name of the field - used to trigger different serializations, e.g., turning off resolution for some strings

content:String

the content of the field

Returns:String

a formatted string suitable for output

writeStringLabelback to summary
private void writeStringLabel(StringBuilder stringBuilder, String text, int startPos, int endPos, boolean isFirst, boolean isLast)
Parameters
stringBuilder:StringBuilder

the StringBuilder to append the text to

text:String

the text use as basis to get the text to append

startPos:int

the position in text where the text to add starts

endPos:int

the position in text where the text to add ends

isFirst:boolean

true if the label to write is the first one to write

isLast:boolean

true if the label to write is the last one to write

writeTextback to summary
private void writeText(StringBuilder stringBuilder, String text, int startPos, int endPos)
Parameters
stringBuilder:StringBuilder

the StringBuilder to append the text to

text:String

the text to append

org.jabref.logic.bibtex back to summary

private final Record FieldWriter.BracePosition

extends Record
Class Inheritance
Record Components
index:int 
line:int 
column:int 

Field Summary

Modifier and TypeField and Description
private final int
column

Record Component accessed by column().

private final int
index

Record Component accessed by index().

private final int
line

Record Component accessed by line().

Constructor Summary

AccessConstructor and Description
private
BracePosition(int index, int line, int column)

Method Summary

Modifier and TypeMethod and Description
public int
column()

Record Component getter of column.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

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

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public int
index()

Record Component getter of index.

public int
line()

Record Component getter of line.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

columnback to summary
private final int column

Record Component accessed by column().

indexback to summary
private final int index

Record Component accessed by index().

lineback to summary
private final int line

Record Component accessed by line().

Constructor Detail

BracePositionback to summary
private BracePosition(int index, int line, int column)

Method Detail

columnback to summary
public int column()

Record Component getter of column.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

indexback to summary
public int index()

Record Component getter of index.

lineback to summary
public int line()

Record Component getter of line.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.