The citation processor.
In order to use the processor in your application you first have to
create an ItemDataProvider that provides citation item data. For
example, the following dummy provider returns always the same data:
public class MyItemProvider implements ItemDataProvider {
@Override
public CSLItemData retrieveItem(String id) {
return new CSLItemDataBuilder()
.id(id)
.type(CSLType.ARTICLE_JOURNAL)
.title("A dummy journal article")
.author("John", "Smith")
.issued(2013, 9, 6)
.containerTitle("Dummy journal")
.build();
}
@Override
public String[] getIds() {
String ids[] = {"ID-0", "ID-1", "ID-2"};
return ids;
}
}
Now you can instantiate the CSL processor.
CSL citeproc = new CSL(new MyItemProvider(), "ieee");
citeproc.setOutputFormat("html");
You may also use makeAdhocBibliography(String, CSLItemData. or
makeAdhocBibliography(String, String, CSLItemData. to create
ad-hoc bibliographies from CSL items.
CSLItemData item = new CSLItemDataBuilder()
.type(CSLType.WEBPAGE)
.title("citeproc-java: A Citation Style Language (CSL) processor for Java")
.author("Michel", "Kraemer")
.issued(2014, 7, 13)
.URL("http://michel-kraemer.github.io/citeproc-java/")
.accessed(2014, 7, 13)
.build();
String bibl = CSL.makeAdhocBibliography("ieee", item).makeString();
| Modifier and Type | Field and Description |
|---|---|
| private final AbbreviationProvider | abbreviationProvider
An object that provides abbreviations (may be |
| private boolean | convertLinks
|
| private List | generatedCitations
A list of generated citations sorted by their index |
| private final ItemDataProvider | itemDataProvider
An object that provides citation item data |
| private final LLocale | locale
The localization data used to render citations and bibliographies |
| private Format | outputFormat
The output format |
| private final Map | registeredItems
Citation items registered through |
| private final List | sortedItems
Contains the same items as |
| private final SStyle | style
The CSL style used to render citations and bibliographies |
| Access | Constructor and Description |
|---|---|
| public | CSL(ItemDataProvider
an object that provides citation item data itemDataProvider, String the citation style to use. May either be a serialized
XML representation of the style or a style's name such as style)ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)Constructs a new citation processor |
| public | CSL(ItemDataProvider
an object that provides citation item data itemDataProvider, String the citation style to use. May either be a serialized
XML representation of the style or a style's name such as style, String ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)an RFC 4646 identifier for the citation locale (e.g. lang)en-US)Constructs a new citation processor |
| public | CSL(ItemDataProvider
an object that provides citation item data itemDataProvider, LocaleProvider an object that provides CSL locales localeProvider, AbbreviationProvider an object that provides abbreviations
(may be abbreviationProvider, String null)the citation style to use. May either be a serialized
XML representation of the style or a style name such as style, String ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)an RFC 4646 identifier for the citation locale (e.g.
lang)en-US). If this argument is null, the default locale of
the citation style will be used. If the citation style does not define
a default locale, the method falls back to en-US.Constructs a new citation processor |
| Modifier and Type | Method and Description |
|---|---|
| private static boolean | Returns: true if the style can be used to format bibliographiesthe style style)Determines whether the given citation style contains instructions to format bibliographies. |
| public static boolean | Returns: true if the style can be used to format bibliographiesthe citation style. May either be a serialized XML
representation of the style or a style name such as style)ieee.
In the latter case, the style is loaded from the classpath (e.g.
/ieee.csl)Determines whether the given citation style contains instructions to format bibliographies |
| private static Set | |
| public static String | Returns: the link to the parent style ornull if the link
could not be foundthe dependent style style)Parse a string representing a dependent parent style and get link to its independent parent style |
| public Collection | Returns: the registered citation itemsGet an unmodifiable collection of all citation items that have been registered with the processor so far |
| public static Set | |
| public static List | |
| public static Set | |
| private static boolean | Returns: true if the string is a dependent style, false otherwisethe style style)Test if the given string represents a dependent style |
| private static boolean | |
| private static boolean | Returns: true if the match succeedsthe first object a, CSLItemData the object to match against b)Test if any of the attributes of |
| private static LLocale | |
| private static SStyle | |
| public static Bibliography | Returns: the bibliographythe citation style to use. May either be a serialized
XML representation of the style or a style's name such as style, CSLItemData... ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)the citation items to add to the bibliography items)Creates an ad hoc bibliography from the given citation items using the
|
| public static Bibliography | Returns: the bibliographythe citation style to use. May either be a serialized
XML representation of the style or a style's name such as style, String ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)the processor's output format (one of
outputFormat, CSLItemData... "html", "text", "asciidoc",
"fo", "markdown", or "markdown-pure")the citation items to add to the bibliography items)Creates an ad hoc bibliography from the given citation items. |
| public static List | Returns: a list of generated citations strings that can be inserted into the textthe citation style to use. May either be a serialized
XML representation of the style or a style's name such as style, CSLItemData... ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)the citation items items)Creates an ad hoc citation from the given citation items using the
|
| public static List | Returns: a list of generated citations strings that can be inserted into the textthe citation style to use. May either be a serialized
XML representation of the style or a style's name such as style, String ieee.
In the latter case, the processor loads the style from the classpath (e.g.
/ieee.csl)the processor's output format (one of
outputFormat, CSLItemData... "html", "text", "asciidoc",
"fo", "markdown", or "markdown-pure")the citation items items)Creates an ad hoc citation from the given citation items. |
| public Bibliography | |
| public Bibliography | Returns: the bibliographythe selection mode mode, CSLItemData... the example item data objects that contain
the fields and field values to match selection)Generates a bibliography for the registered citations. |
| public Bibliography | Returns: the bibliographythe selection mode mode, CSLItemData[] the example item data objects that contain
the fields and field values to match selection, CSLItemData[] regardless of the item data in quash)selection
skip items if all fields/values from this list matchGenerates a bibliography for the registered citations. |
| public Bibliography | Returns: the bibliographya function to apply to each registered citation item to
determine if it should be included in the bibliography or not (may
be filter)null if all items should be included)Generates a bibliography for registered citations |
| public List | Returns: citations strings that can be inserted into the textIDs of citation items for which strings should be generated ids)Generates citation strings that can be inserted into the text. |
| public List | Returns: citations strings that can be inserted into the textIDs of citation items for which strings should be generated ids)Generates citation strings that can be inserted into the text. |
| public List | Returns: citations strings that can be inserted into the texta set of citation items for which strings should be generated citation)Generates citation strings that can be inserted into the text. |
| private CSLCitation | Returns: the prepared citationthe citation to render citation, Set<CSLItemData> an empty set that will be filled with citation
items that had to be updated while rendering the given one (may be
updatedItems)null)Perform steps to prepare the given citation for rendering. |
| public void | registerCitationItems(String...
the IDs to register ids)Introduces the given citation IDs to the processor. |
| public void | registerCitationItems(String[]
the IDs to register ids, boolean true if items should not be sorted in the bibliography unsorted)Introduces the given citation IDs to the processor. |
| public void | registerCitationItems(Collection<String>
the IDs to register ids)Introduces the given citation IDs to the processor. |
| public void | registerCitationItems(Collection<String>
the IDs to register ids, boolean true if items should not be sorted in the bibliography unsorted)Introduces the given citation IDs to the processor. |
| private List | Returns: a list of registered citation item datathe IDs of the citation items to register ids, Set<CSLItemData> an empty set that will be filled with the citation
items the method had to update (may be updatedItems, boolean null)true if any sorting specified in the style
should be ignoredFetches the item data for the given citation items and adds it to
|
| private String | Returns: the rendered stringthe citation to render. The citation must have
been prepared by preparedCitation)preRenderCitation(CSLCitation, Set)Render the given prepared citation |
| public void | |
| private static String | Returns: the serialized XML representation of the stylethe style's name styleName)Retrieves a CSL style from the classpath. |
| public void | setConvertLinks(boolean
true if URLs and DOIs should be converted to links convert)Specifies if the processor should convert URLs and DOIs in the output to links. |
| public void | setOutputFormat(String
the format (one of format)"asciidoc", "fo",
"html", "markdown", "markdown-pure",
or "text").Sets the processor's output format |
| public void | |
| public static boolean | Returns: true if the style is supported, false otherwisethe citation style's name style)Checks if a given citation style is supported |
| abbreviationProvider | back to summary |
|---|---|
| private final AbbreviationProvider abbreviationProvider An object that provides abbreviations (may be | |
| convertLinks | back to summary |
|---|---|
| private boolean convertLinks
| |
| generatedCitations | back to summary |
|---|---|
| private List<GeneratedCitation> generatedCitations A list of generated citations sorted by their index | |
| itemDataProvider | back to summary |
|---|---|
| private final ItemDataProvider itemDataProvider An object that provides citation item data | |
| locale | back to summary |
|---|---|
| private final LLocale locale The localization data used to render citations and bibliographies | |
| outputFormat | back to summary |
|---|---|
| private Format outputFormat The output format | |
| registeredItems | back to summary |
|---|---|
| private final Map<String, CSLItemData> registeredItems Citation items registered through | |
| sortedItems | back to summary |
|---|---|
| private final List<CSLItemData> sortedItems Contains the same items as | |
| style | back to summary |
|---|---|
| private final SStyle style The CSL style used to render citations and bibliographies | |
| CSL | back to summary |
|---|---|
| public CSL(ItemDataProvider itemDataProvider, String style) throws IOException Constructs a new citation processor
| |
| CSL | back to summary |
|---|---|
| public CSL(ItemDataProvider itemDataProvider, String style, String lang) throws IOException Constructs a new citation processor
| |
| CSL | back to summary |
|---|---|
| public CSL(ItemDataProvider itemDataProvider, LocaleProvider localeProvider, AbbreviationProvider abbreviationProvider, String style, String lang) throws IOException Constructs a new citation processor
| |
| canFormatBibliographies | back to summary |
|---|---|
| private static boolean canFormatBibliographies(SStyle style) Determines whether the given citation style contains instructions to format bibliographies.
| |
| canFormatBibliographies | back to summary |
|---|---|
| public static boolean canFormatBibliographies(String style) throws IOException Determines whether the given citation style contains instructions to format bibliographies
| |
| getAvailableFiles | back to summary |
|---|---|
| private static Set | |
| getIndependentParentLink | back to summary |
|---|---|
| public static String getIndependentParentLink(String style) throws ParserConfigurationException, IOException, SAXException Parse a string representing a dependent parent style and get link to its independent parent style
| |
| getRegisteredItems | back to summary |
|---|---|
| public Collection Get an unmodifiable collection of all citation items that have been registered with the processor so far
| |
| getSupportedLocales | back to summary |
|---|---|
| public static Set Calculates a list of available citation locales
| |
| getSupportedOutputFormats | back to summary |
|---|---|
| public static List Get a list of supported output formats | |
| getSupportedStyles | back to summary |
|---|---|
| public static Set Calculates a list of available citation styles
| |
| isDependent | back to summary |
|---|---|
| private static boolean isDependent(String style) Test if the given string represents a dependent style
| |
| isStyle | back to summary |
|---|---|
| private static boolean isStyle(String style) Checks if the given String contains the serialized XML representation of a style
| |
| itemDataEqualsAny | back to summary |
|---|---|
| private static boolean itemDataEqualsAny(CSLItemData a, CSLItemData b) Test if any of the attributes of Note This method will be deprecated in the next release
| |
| loadLocale | back to summary |
|---|---|
| private static LLocale loadLocale(String strLocale) throws IOException | |
| loadStyle | back to summary |
|---|---|
| private static SStyle loadStyle(String style) throws IOException | |
| makeAdhocBibliography | back to summary |
|---|---|
| public static Bibliography makeAdhocBibliography(String style, CSLItemData... items) throws IOException Creates an ad hoc bibliography from the given citation items using the
| |
| makeAdhocBibliography | back to summary |
|---|---|
| public static Bibliography makeAdhocBibliography(String style, String outputFormat, CSLItemData... items) throws IOException Creates an ad hoc bibliography from the given citation items.
| |
| makeAdhocCitation | back to summary |
|---|---|
| public static List Creates an ad hoc citation from the given citation items using the
| |
| makeAdhocCitation | back to summary |
|---|---|
| public static List Creates an ad hoc citation from the given citation items.
| |
| makeBibliography | back to summary |
|---|---|
| public Bibliography makeBibliography() Generates a bibliography for the registered citations
| |
| makeBibliography | back to summary |
|---|---|
| public Bibliography makeBibliography(SelectionMode mode, CSLItemData... selection) Generates a bibliography for the registered citations. Depending on the selection mode selects, includes, or excludes bibliography items whose fields and field values match the fields and field values from the given example item data objects.
| |
| makeBibliography | back to summary |
|---|---|
| public Bibliography makeBibliography(SelectionMode mode, CSLItemData[] selection, CSLItemData[] quash) Generates a bibliography for the registered citations. Depending on the selection mode selects, includes, or excludes bibliography items whose fields and field values match the fields and field values from the given example item data objects. Note This method will be deprecated in the next release.
| |
| makeBibliography | back to summary |
|---|---|
| public Bibliography makeBibliography(Predicate<CSLItemData> filter) Generates a bibliography for registered citations
| |
| makeCitation | back to summary |
|---|---|
| public List Generates citation strings that can be inserted into the text. The
method calls
| |
| makeCitation | back to summary |
|---|---|
| public List Generates citation strings that can be inserted into the text. The
method calls
| |
| makeCitation | back to summary |
|---|---|
| public List Generates citation strings that can be inserted into the text. The
method calls
| |
| preRenderCitation | back to summary |
|---|---|
| private CSLCitation preRenderCitation(CSLCitation citation, Set<CSLItemData> updatedItems) Perform steps to prepare the given citation for rendering. Register
citation items and sort them. Return a prepared citation that can be
passed to
| |
| registerCitationItems | back to summary |
|---|---|
| public void registerCitationItems(String... ids) Introduces the given citation IDs to the processor. The processor will
call
| |
| registerCitationItems | back to summary |
|---|---|
| public void registerCitationItems(String[] ids, boolean unsorted) Introduces the given citation IDs to the processor. The processor will
call
| |
| registerCitationItems | back to summary |
|---|---|
| public void registerCitationItems(Collection<String> ids) Introduces the given citation IDs to the processor. The processor will
call
| |
| registerCitationItems | back to summary |
|---|---|
| public void registerCitationItems(Collection<String> ids, boolean unsorted) Introduces the given citation IDs to the processor. The processor will
call
| |
| registerItems | back to summary |
|---|---|
| private List Fetches the item data for the given citation items and adds it to
| |
| renderCitation | back to summary |
|---|---|
| private String renderCitation(CSLCitation preparedCitation) Render the given prepared citation
| |
| reset | back to summary |
|---|---|
| public void reset() Resets the processor's state | |
| retrieveStyle | back to summary |
|---|---|
| private static String retrieveStyle(String styleName) throws IOException Retrieves a CSL style from the classpath. For example, if the given name
is
| |
| setConvertLinks | back to summary |
|---|---|
| public void setConvertLinks(boolean convert) Specifies if the processor should convert URLs and DOIs in the output
to links. How links are created depends on the output format that has
been set with
| |
| setOutputFormat | back to summary |
|---|---|
| public void setOutputFormat(String format) Sets the processor's output format
| |
| setOutputFormat | back to summary |
|---|---|
| public void setOutputFormat(Format outputFormat) Sets the processor's output format
| |
| supportsStyle | back to summary |
|---|---|
| public static boolean supportsStyle(String style) Checks if a given citation style is supported
| |