Top Description Fields Constructors Methods
org.jabref.logic.bibtex

public Class FieldWriter

extends Object
Class Inheritance
Imports
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

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 boolean
private final FieldPreferences

Constructor Summary

AccessConstructor and Description
public
private
FieldWriter(boolean neverFailOnHashes, FieldPreferences preferences)

Method Summary

Modifier and TypeMethod and Description
public static FieldWriter
private static void
private String
formatAndResolveStrings(String content, Field field)

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 int
getFirstOccurrenceOfStartEndSymbol(String content, int pivot)

Finds the first occurrence of # from the pivot point

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
neverFailOnHashesback to summary
private final boolean neverFailOnHashes
preferencesback to summary
private final FieldPreferences preferences

Constructor Detail

FieldWriterback to summary
public FieldWriter(FieldPreferences preferences)
FieldWriterback to summary
private FieldWriter(boolean neverFailOnHashes, FieldPreferences preferences)

Method Detail

buildIgnoreHashesback to summary
public static FieldWriter buildIgnoreHashes(FieldPreferences prefs)
checkBracesback to summary
private static void checkBraces(String text) throws InvalidFieldValueException
formatAndResolveStringsback to summary
private String formatAndResolveStrings(String content, Field field) throws InvalidFieldValueException

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, Field field) throws InvalidFieldValueException
getFirstOccurrenceOfStartEndSymbolback to summary
private static int getFirstOccurrenceOfStartEndSymbol(String content, int pivot)

Finds the first occurrence of # from the pivot point

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

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

Exceptions
InvalidFieldValueException:
if content is not a correct bibtex string, e.g., because of improperly balanced braces or using # not paired
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