Search in sources :

Example 1 with TokenMgrException

use of org.jbibtex.TokenMgrException in project jabref by JabRef.

the class CitationStyleGenerator method generateCitations.

/**
     * WARNING: the citation is generated using JavaScript which may take some time, better call it from outside the main Thread
     * Generates the citation for multiple entries at once. This is useful when the Citation Style has an increasing number
     */
public static List<String> generateCitations(List<BibEntry> bibEntries, String style, CitationStyleOutputFormat outputFormat) {
    try {
        CSLItemData[] cslItemData = new CSLItemData[bibEntries.size()];
        for (int i = 0; i < bibEntries.size(); i++) {
            cslItemData[i] = bibEntryToCSLItemData(bibEntries.get(i));
        }
        Bibliography bibliography = CSL.makeAdhocBibliography(style, outputFormat.getFormat(), cslItemData);
        return Arrays.asList(bibliography.getEntries());
    } catch (IOException | ArrayIndexOutOfBoundsException e) {
        LOGGER.error("Could not generate BibEntry citation", e);
        return Collections.singletonList(Localization.lang("Cannot generate preview based on selected citation style."));
    } catch (TokenMgrException e) {
        LOGGER.error("Bad character inside BibEntry", e);
        // sadly one cannot easily retrieve the bad char from the TokenMgrError
        return Collections.singletonList(new StringBuilder().append(Localization.lang("Cannot generate preview based on selected citation style.")).append(outputFormat.getLineSeparator()).append(Localization.lang("Bad character inside entry")).append(outputFormat.getLineSeparator()).append(e.getLocalizedMessage()).toString());
    }
}
Also used : CSLItemData(de.undercouch.citeproc.csl.CSLItemData) TokenMgrException(org.jbibtex.TokenMgrException) IOException(java.io.IOException) Bibliography(de.undercouch.citeproc.output.Bibliography)

Aggregations

CSLItemData (de.undercouch.citeproc.csl.CSLItemData)1 Bibliography (de.undercouch.citeproc.output.Bibliography)1 IOException (java.io.IOException)1 TokenMgrException (org.jbibtex.TokenMgrException)1