Top Description Fields Constructors Methods
de.undercouch.citeproc.csl.internal

public Class RenderContext

extends Object
Class Inheritance
Imports
de.undercouch.citeproc.AbbreviationProvider, de.undercouch.citeproc.bibtex.PageParser, de.undercouch.citeproc.csl.CSLCitation, .CSLCitationItem, .CSLCitationItemBuilder, .CSLDate, .CSLItemData, .CSLName, de.undercouch.citeproc.csl.internal.locale.LLocale, .LTerm, de.undercouch.citeproc.csl.internal.rendering.SLabel, .SNameInheritableAttributes, de.undercouch.citeproc.csl.internal.token.TextToken, .Token, java.util.HashSet, .LinkedHashSet, .List, .Locale, .Map, .Set, java.util.concurrent.atomic.AtomicReference

Contains information necessary to render citations and bibliographies. This includes citation items, variables, and terms. The render context also provides methods to emit rendered text to a TokenBuffer. This buffer is available through the getResult() method.
Author
Michel Kraemer

Field Summary

Modifier and TypeField and Description
private final AbbreviationProvider
abbreviationProvider

An optional abbreviation provider (may be null)

private final CSLCitation
citation

The citation to render.

private final CSLCitationItem
citationItem

The citation item to render

private final List<GeneratedCitation>
generatedCitations

All citations generated so far.

private final SNameInheritableAttributes
inheritedNameAttributes

Attributes for name elements inherited from the style, bibliography, or citation

private final CSLItemData
itemData

The citation item data to render

private final AtomicReference<SLabel>
lastLabelRendered

The last label rendered.

private final LLocale
locale

Localization data

private final TokenBuffer
result

A token buffer collecting the rendered text

private final SStyle
style

The style used to render citation items and bibliographies

private final Set<String>
suppressedVariables

A set of variables that should not be rendered any more for the rest of the output (i.e. where the context should pretend the variable's value is null).

private final Set<VariableListener>
variableListeners

A set of listeners to call whenever a variable value is fetched from the context

Constructor Summary

AccessConstructor and Description
public
RenderContext(SStyle
the style used to render citation items and bibliographies
style
,
LLocale
localization data
locale
,
CSLItemData
the citation item to render
itemData
,
AbbreviationProvider
an optional abbreviation provider (may be null)
abbreviationProvider
)

Creates a new render context

public
RenderContext(SStyle
the style used to render citation items and bibliographies
style
,
LLocale
localization data
locale
,
CSLItemData
the citation item to render
itemData
,
AbbreviationProvider
an optional abbreviation provider (may be null)
abbreviationProvider
,
CSLCitation
the citation to render
citation
,
List<GeneratedCitation>
all citations generated so far
generatedCitations
)

Creates a new render context

public
RenderContext(RenderContext
the parent context
parent
)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer.

public
RenderContext(RenderContext
the parent context
parent
,
SNameInheritableAttributes
the new inherited name attributes
inheritedNameAttributes
)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and different inherited name attributes.

public
RenderContext(RenderContext
the parent context
parent
,
CSLCitationItem
the citation item to render
citationItem
)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and a different citation item.

private
RenderContext(RenderContext
the parent context
parent
,
CSLItemData
the citation item data to render
itemData
,
CSLCitation
the citation to render
citation
,
List<GeneratedCitation>
all citations generated so far
generatedCitations
,
CSLCitationItem
the citation item to render
citationItem
,
SNameInheritableAttributes
inherited name attributes
inheritedNameAttributes
)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and a different citation item.

Method Summary

Modifier and TypeMethod and Description
public void
addVariableListener(VariableListener
the variable listener to register
listener
)

Adds a variable listener to this context

public RenderContext

Returns:

this render context
emit
(String
the text token
text
)

Emit a text token

public RenderContext

Returns:

this render context
emit
(String
the text token
text
,
int
the token's formatting attributes
formattingAttributes
)

Emit a text token with the given formatting attributes

public RenderContext

Returns:

this render context
emit
(String
the token's text
text
,
TextToken.Type
the token's type
type
)

Emit a text token of a given type

public RenderContext

Returns:

this render context
emit
(String
the token's text
text
,
TextToken.Type
the token's type
type
,
int
the token's formatting attributes
formattingAttributes
)

Emit a text token of a given type and with the specified formatting attributes

public RenderContext

Returns:

this render context
emit
(Token
the token
token
)

Emit a token

public RenderContext

Returns:

this render context
emit
(TokenBuffer
the token buffer
buffer
)

Emit all tokens from the given token buffer

public RenderContext

Returns:

this render context
emit
(TokenBuffer
the token buffer
buffer
,
int
the formatting attributes to append
formattingAttributes
)

Emit all tokens from the given token buffer and wrap the given formatting attributes around them (unless the are 0)

public CSLCitation

Returns:

the citation
getCitation
()

Get the citation currently being rendered.

public CSLCitationItem

Returns:

the citation item
getCitationItem
()

Get the citation item currently being rendered

public CSLDate

Returns:

the variable's value or null if the value is not set
getDateVariable
(String
the variable's name
name
)

Get the value of the date variable with the given name

public CSLDate

Returns:

the variable's value or null if the value is not set
getDateVariable
(String
the variable's name
name
,
boolean
true if VariableListeners should not be notified about this call.
ignoreListeners
)

Get the value of the date variable with the given name

public List<GeneratedCitation>

Returns:

all citations generated so far
getGeneratedCitations
()

Get all citations generated so far.

public SNameInheritableAttributes

Returns:

the attributes
getInheritedNameAttributes
()

Get attributes that can be inherited to name elements

public CSLItemData

Returns:

the citation item data
getItemData
()

Get the citation item data currently being rendered

public Locale

Returns:

the locale
getItemLocale
()

Get the Locale that is valid for the current item to render

public SLabel

Returns:

the label (may be null)
getLastLabelRendered
()

Get the last label rendered

public LLocale

Returns:

the localization data
getLocale
()

Get the localization data

public SMacro

Returns:

the macro (never null)
getMacro
(String
the macro's name
name
)

Get the macro with the given name

public CSLName[]
public CSLName[]
getNameVariable(String name, boolean ignoreListeners)

public TokenBuffer

Returns:

the token buffer
getResult
()

Get a token buffer containing all emitted tokens

public String

Returns:

the variable's value or null if the value is not set
getStringVariable
(String
the variable's name
name
)

Get the value of the string variable with the given name

public String

Returns:

the variable's value or null if the value is not set
getStringVariable
(String
the variable's name
name
,
boolean
true if VariableListeners should not be notified about this call.
ignoreListeners
)

Get the value of the string variable with the given name

public String

Returns:

the variable's value or null if the value is not set
getStringVariable
(String
the variable's name
name
,
VariableForm
the variable form to get
form
)

Get the value of the string variable with the given name

public String

Returns:

the variable's value or null if the value is not set
getStringVariable
(String
the variable's name
name
,
VariableForm
the variable form to get
form
,
boolean
true if VariableListeners should not be notified about this call.
ignoreListeners
)

Get the value of the string variable with the given name

public SStyle

Returns:

the style
getStyle
()

Get the style used to render citation items and bibliographies

public String

Returns:

the term's value (never null)
getTerm
(String
the term's name
name
)

Get the singular long form of a term

public String

Returns:

the term's value (never null)
getTerm
(String
the term's name
name
,
boolean
true if the plural form should be retrieved, false for the singular form
plural
)

Get the long form of a term

public String

Returns:

the term's value (never null)
getTerm
(String
the term's name
name
,
LTerm.Form
the form to retrieve
form
)

Get the singular form of a term

public String

Returns:

the term's value (or null if the term is unknown)
getTerm
(String
the term's name
name
,
LTerm.Form
the form to retrieve
form
,
boolean
true if the plural form should be retrieved, false for the singular form
plural
)

Get a term

public Object

Returns:

the variable's value or null if the value is not set
getVariable
(String
the variable's name
name
)

Get the value of a string, date, or name variable

public Object

Returns:

the variable's value or null if the value is not set
getVariable
(String
the variable's name
name
,
boolean
true if VariableListeners should not be notified about this call.
ignoreListeners
)

Get the value of a string, date, or name variable

public Set<VariableListener>

Returns:

the set
getVariableListeners
()

Get the set of variable listeners

public void
removeVariableListener(VariableListener
the variable listener to remove
listener
)

Removes a variable listener from this context

public void
reset()

Reset the render context so it can be used to render another citation

public void
setLastLabelRendered(SLabel
the label (may be null)
label
)

Save the last label rendered

public void
suppressVariable(String
the variable's name
name
)

Add a variable to the set of suppressed variables.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

abbreviationProviderback to summary
private final AbbreviationProvider abbreviationProvider

An optional abbreviation provider (may be null)

citationback to summary
private final CSLCitation citation

The citation to render. Will be null if a bibliography should be rendered.

citationItemback to summary
private final CSLCitationItem citationItem

The citation item to render

generatedCitationsback to summary
private final List<GeneratedCitation> generatedCitations

All citations generated so far. Will be null if we are currently rendering a bibliography.

inheritedNameAttributesback to summary
private final SNameInheritableAttributes inheritedNameAttributes

Attributes for name elements inherited from the style, bibliography, or citation

itemDataback to summary
private final CSLItemData itemData

The citation item data to render

lastLabelRenderedback to summary
private final AtomicReference<SLabel> lastLabelRendered

The last label rendered. This field is an AtomicReference so child contexts can alter its value.

localeback to summary
private final LLocale locale

Localization data

resultback to summary
private final TokenBuffer result

A token buffer collecting the rendered text

styleback to summary
private final SStyle style

The style used to render citation items and bibliographies

suppressedVariablesback to summary
private final Set<String> suppressedVariables

A set of variables that should not be rendered any more for the rest of the output (i.e. where the context should pretend the variable's value is null).

variableListenersback to summary
private final Set<VariableListener> variableListeners

A set of listeners to call whenever a variable value is fetched from the context

Constructor Detail

RenderContextback to summary
public RenderContext(SStyle style, LLocale locale, CSLItemData itemData, AbbreviationProvider abbreviationProvider)

Creates a new render context

Parameters
style:SStyle

the style used to render citation items and bibliographies

locale:LLocale

localization data

itemData:CSLItemData

the citation item to render

abbreviationProvider:AbbreviationProvider

an optional abbreviation provider (may be null)

RenderContextback to summary
public RenderContext(SStyle style, LLocale locale, CSLItemData itemData, AbbreviationProvider abbreviationProvider, CSLCitation citation, List<GeneratedCitation> generatedCitations)

Creates a new render context

Parameters
style:SStyle

the style used to render citation items and bibliographies

locale:LLocale

localization data

itemData:CSLItemData

the citation item to render

abbreviationProvider:AbbreviationProvider

an optional abbreviation provider (may be null)

citation:CSLCitation

the citation to render

generatedCitations:List<GeneratedCitation>

all citations generated so far

RenderContextback to summary
public RenderContext(RenderContext parent)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer. Changes to any of the properties (except for the token buffer) will reflect in the parent context.

Parameters
parent:RenderContext

the parent context

RenderContextback to summary
public RenderContext(RenderContext parent, SNameInheritableAttributes inheritedNameAttributes)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and different inherited name attributes. Changes to any of the properties (except for the token buffer) will reflect in the parent context.

Parameters
parent:RenderContext

the parent context

inheritedNameAttributes:SNameInheritableAttributes

the new inherited name attributes

RenderContextback to summary
public RenderContext(RenderContext parent, CSLCitationItem citationItem)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and a different citation item. Changes to any of the properties (except for the token buffer) will reflect in the parent context.

Parameters
parent:RenderContext

the parent context

citationItem:CSLCitationItem

the citation item to render

RenderContextback to summary
private RenderContext(RenderContext parent, CSLItemData itemData, CSLCitation citation, List<GeneratedCitation> generatedCitations, CSLCitationItem citationItem, SNameInheritableAttributes inheritedNameAttributes)

Creates a new render context that has the same attributes as the given parent context but with an empty token buffer and a different citation item. Changes to any of the properties (except for the token buffer) will reflect in the parent context.

Parameters
parent:RenderContext

the parent context

itemData:CSLItemData

the citation item data to render

citation:CSLCitation

the citation to render

generatedCitations:List<GeneratedCitation>

all citations generated so far

citationItem:CSLCitationItem

the citation item to render

inheritedNameAttributes:SNameInheritableAttributes

inherited name attributes

Method Detail

addVariableListenerback to summary
public void addVariableListener(VariableListener listener)

Adds a variable listener to this context

Parameters
listener:VariableListener

the variable listener to register

emitback to summary
public RenderContext emit(String text)

Emit a text token

Parameters
text:String

the text token

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(String text, int formattingAttributes)

Emit a text token with the given formatting attributes

Parameters
text:String

the text token

formattingAttributes:int

the token's formatting attributes

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(String text, TextToken.Type type)

Emit a text token of a given type

Parameters
text:String

the token's text

type:TextToken.Type

the token's type

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(String text, TextToken.Type type, int formattingAttributes)

Emit a text token of a given type and with the specified formatting attributes

Parameters
text:String

the token's text

type:TextToken.Type

the token's type

formattingAttributes:int

the token's formatting attributes

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(Token token)

Emit a token

Parameters
token:Token

the token

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(TokenBuffer buffer)

Emit all tokens from the given token buffer

Parameters
buffer:TokenBuffer

the token buffer

Returns:RenderContext

this render context

emitback to summary
public RenderContext emit(TokenBuffer buffer, int formattingAttributes)

Emit all tokens from the given token buffer and wrap the given formatting attributes around them (unless the are 0)

Parameters
buffer:TokenBuffer

the token buffer

formattingAttributes:int

the formatting attributes to append

Returns:RenderContext

this render context

getCitationback to summary
public CSLCitation getCitation()

Get the citation currently being rendered. Will return null if we are currently rendering a bibliography and not a citation.

Returns:CSLCitation

the citation

getCitationItemback to summary
public CSLCitationItem getCitationItem()

Get the citation item currently being rendered

Returns:CSLCitationItem

the citation item

getDateVariableback to summary
public CSLDate getDateVariable(String name)

Get the value of the date variable with the given name

Parameters
name:String

the variable's name

Returns:CSLDate

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the date variable is unknown
getDateVariableback to summary
public CSLDate getDateVariable(String name, boolean ignoreListeners)

Get the value of the date variable with the given name

Parameters
name:String

the variable's name

ignoreListeners:boolean

true if VariableListeners should not be notified about this call.

Returns:CSLDate

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the date variable is unknown
getGeneratedCitationsback to summary
public List<GeneratedCitation> getGeneratedCitations()

Get all citations generated so far. Will return null if we are currently rendering a bibliography and not a citation.

Returns:List<GeneratedCitation>

all citations generated so far

getInheritedNameAttributesback to summary
public SNameInheritableAttributes getInheritedNameAttributes()

Get attributes that can be inherited to name elements

Returns:SNameInheritableAttributes

the attributes

getItemDataback to summary
public CSLItemData getItemData()

Get the citation item data currently being rendered

Returns:CSLItemData

the citation item data

getItemLocaleback to summary
public Locale getItemLocale()

Get the Locale that is valid for the current item to render

Returns:Locale

the locale

getLastLabelRenderedback to summary
public SLabel getLastLabelRendered()

Get the last label rendered

Returns:SLabel

the label (may be null)

getLocaleback to summary
public LLocale getLocale()

Get the localization data

Returns:LLocale

the localization data

getMacroback to summary
public SMacro getMacro(String name)

Get the macro with the given name

Parameters
name:String

the macro's name

Returns:SMacro

the macro (never null)

getNameVariableback to summary
public CSLName[] getNameVariable(String name)
getNameVariableback to summary
public CSLName[] getNameVariable(String name, boolean ignoreListeners)
getResultback to summary
public TokenBuffer getResult()

Get a token buffer containing all emitted tokens

Returns:TokenBuffer

the token buffer

getStringVariableback to summary
public String getStringVariable(String name)

Get the value of the string variable with the given name

Parameters
name:String

the variable's name

Returns:String

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getStringVariableback to summary
public String getStringVariable(String name, boolean ignoreListeners)

Get the value of the string variable with the given name

Parameters
name:String

the variable's name

ignoreListeners:boolean

true if VariableListeners should not be notified about this call.

Returns:String

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getStringVariableback to summary
public String getStringVariable(String name, VariableForm form)

Get the value of the string variable with the given name

Parameters
name:String

the variable's name

form:VariableForm

the variable form to get

Returns:String

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getStringVariableback to summary
public String getStringVariable(String name, VariableForm form, boolean ignoreListeners)

Get the value of the string variable with the given name

Parameters
name:String

the variable's name

form:VariableForm

the variable form to get

ignoreListeners:boolean

true if VariableListeners should not be notified about this call.

Returns:String

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getStyleback to summary
public SStyle getStyle()

Get the style used to render citation items and bibliographies

Returns:SStyle

the style

getTermback to summary
public String getTerm(String name)

Get the singular long form of a term

Parameters
name:String

the term's name

Returns:String

the term's value (never null)

getTermback to summary
public String getTerm(String name, boolean plural)

Get the long form of a term

Parameters
name:String

the term's name

plural:boolean

true if the plural form should be retrieved, false for the singular form

Returns:String

the term's value (never null)

getTermback to summary
public String getTerm(String name, LTerm.Form form)

Get the singular form of a term

Parameters
name:String

the term's name

form:LTerm.Form

the form to retrieve

Returns:String

the term's value (never null)

getTermback to summary
public String getTerm(String name, LTerm.Form form, boolean plural)

Get a term

Parameters
name:String

the term's name

form:LTerm.Form

the form to retrieve

plural:boolean

true if the plural form should be retrieved, false for the singular form

Returns:String

the term's value (or null if the term is unknown)

getVariableback to summary
public Object getVariable(String name)

Get the value of a string, date, or name variable

Parameters
name:String

the variable's name

Returns:Object

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getVariableback to summary
public Object getVariable(String name, boolean ignoreListeners)

Get the value of a string, date, or name variable

Parameters
name:String

the variable's name

ignoreListeners:boolean

true if VariableListeners should not be notified about this call.

Returns:Object

the variable's value or null if the value is not set

Exceptions
IllegalArgumentException:
if the variable is unknown
getVariableListenersback to summary
public Set<VariableListener> getVariableListeners()

Get the set of variable listeners

Returns:Set<VariableListener>

the set

removeVariableListenerback to summary
public void removeVariableListener(VariableListener listener)

Removes a variable listener from this context

Parameters
listener:VariableListener

the variable listener to remove

resetback to summary
public void reset()

Reset the render context so it can be used to render another citation

setLastLabelRenderedback to summary
public void setLastLabelRendered(SLabel label)

Save the last label rendered

Parameters
label:SLabel

the label (may be null)

suppressVariableback to summary
public void suppressVariable(String name)

Add a variable to the set of suppressed variables. Suppressed variables should not be rendered any more for the rest of the output. The context will pretend the variable's value is null).

Parameters
name:String

the variable's name