From fbf8e3dc35d64210028d37ce2f4d45820660eba1 Mon Sep 17 00:00:00 2001 From: Michel Kraemer Date: Tue, 2 Feb 2021 13:52:41 +0100 Subject: [PATCH] Remove variable wrapper This is a concept from citeproc.js. If necessary, we will provide a new interface for that purpose in citeproc-java --- .../src/main/groovy/SourceGenerator.groovy | 3 -- .../main/java/de/undercouch/citeproc/CSL.java | 10 ++-- .../de/undercouch/citeproc/CSLBuilder.java | 14 +---- .../undercouch/citeproc/VariableWrapper.java | 23 -------- .../java/de/undercouch/citeproc/CSLTest.java | 26 ---------- citeproc-java/templates/Context.json | 10 ---- .../templates/VariableWrapperParams.json | 52 ------------------- 7 files changed, 5 insertions(+), 133 deletions(-) delete mode 100644 citeproc-java/src/main/java/de/undercouch/citeproc/VariableWrapper.java delete mode 100644 citeproc-java/templates/Context.json delete mode 100644 citeproc-java/templates/VariableWrapperParams.json diff --git a/buildSrc/src/main/groovy/SourceGenerator.groovy b/buildSrc/src/main/groovy/SourceGenerator.groovy index 70f5ce8f..fff43b6d 100644 --- a/buildSrc/src/main/groovy/SourceGenerator.groovy +++ b/buildSrc/src/main/groovy/SourceGenerator.groovy @@ -184,7 +184,6 @@ class SourceGenerator { def dst = new File(project.projectDir, 'src-gen/main/java') dst.mkdirs() - renderTemplatesInternal('Context', dst, true) renderTemplatesInternal('CSLType', dst, true) renderTemplatesInternal('CSLLabel', dst, true) renderTemplatesInternal('SecondFieldAlign', dst, true) @@ -205,8 +204,6 @@ class SourceGenerator { renderTemplatesInternal('Bibliography', dst) renderTemplatesInternal('Citation', dst) - renderTemplatesInternal('VariableWrapperParams', dst) - renderParserTemplate('EndNoteParser', dst) renderParserTemplate('RISParser', dst) } diff --git a/citeproc-java/src/main/java/de/undercouch/citeproc/CSL.java b/citeproc-java/src/main/java/de/undercouch/citeproc/CSL.java index a1d4936b..1ab09830 100644 --- a/citeproc-java/src/main/java/de/undercouch/citeproc/CSL.java +++ b/citeproc-java/src/main/java/de/undercouch/citeproc/CSL.java @@ -159,7 +159,7 @@ public class CSL { */ public CSL(ItemDataProvider itemDataProvider, String style) throws IOException { this(itemDataProvider, new DefaultLocaleProvider(), - new DefaultAbbreviationProvider(), null, style, "en-US"); + new DefaultAbbreviationProvider(), style, "en-US"); } /** @@ -174,7 +174,7 @@ public CSL(ItemDataProvider itemDataProvider, String style) throws IOException { */ public CSL(ItemDataProvider itemDataProvider, String style, String lang) throws IOException { this(itemDataProvider, new DefaultLocaleProvider(), - new DefaultAbbreviationProvider(), null, style, lang); + new DefaultAbbreviationProvider(), style, lang); } /** @@ -182,8 +182,6 @@ public CSL(ItemDataProvider itemDataProvider, String style, String lang) throws * @param itemDataProvider an object that provides citation item data * @param localeProvider an object that provides CSL locales * @param abbreviationProvider an object that provides abbreviations - * @param variableWrapper an optional object that can affect how items - * are rendered in citations and bibliographies * @param style the citation style to use. May either be a serialized * XML representation of the style or a style's name such as ieee. * In the latter case, the processor loads the style from the classpath (e.g. @@ -192,8 +190,8 @@ public CSL(ItemDataProvider itemDataProvider, String style, String lang) throws * @throws IOException if the CSL style could not be loaded */ public CSL(ItemDataProvider itemDataProvider, LocaleProvider localeProvider, - AbbreviationProvider abbreviationProvider, VariableWrapper variableWrapper, - String style, String lang) throws IOException { + AbbreviationProvider abbreviationProvider, String style, + String lang) throws IOException { // load style if needed if (!isStyle(style)) { style = loadStyle(style); diff --git a/citeproc-java/src/main/java/de/undercouch/citeproc/CSLBuilder.java b/citeproc-java/src/main/java/de/undercouch/citeproc/CSLBuilder.java index d76dbb44..0dcb9035 100644 --- a/citeproc-java/src/main/java/de/undercouch/citeproc/CSLBuilder.java +++ b/citeproc-java/src/main/java/de/undercouch/citeproc/CSLBuilder.java @@ -16,7 +16,6 @@ public class CSLBuilder { private ItemDataProvider itemDataProvider; private LocaleProvider localeProvider = new DefaultLocaleProvider(); private AbbreviationProvider abbreviationProvider = new DefaultAbbreviationProvider(); - private VariableWrapper variableWrapper; private String style; private String lang = "en-US"; @@ -50,16 +49,6 @@ public CSLBuilder abbreviationProvider(AbbreviationProvider abbreviationProvider return this; } - /** - * Set an optional variable wrapper - * @param variableWrapper an object that decorates rendered items - * @return {@code this} builder - */ - public CSLBuilder variableWrapper(VariableWrapper variableWrapper) { - this.variableWrapper = variableWrapper; - return this; - } - /** * Set the citation style to use. This may either be a serialized XML * representation of the style or a style's name such as ieee. @@ -89,7 +78,6 @@ public CSLBuilder lang(String lang) { * @throws IOException if the CSL style could not be loaded */ public CSL build() throws IOException { - return new CSL(itemDataProvider, localeProvider, abbreviationProvider, - variableWrapper, style, lang); + return new CSL(itemDataProvider, localeProvider, abbreviationProvider, style, lang); } } diff --git a/citeproc-java/src/main/java/de/undercouch/citeproc/VariableWrapper.java b/citeproc-java/src/main/java/de/undercouch/citeproc/VariableWrapper.java deleted file mode 100644 index d24a8535..00000000 --- a/citeproc-java/src/main/java/de/undercouch/citeproc/VariableWrapper.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.undercouch.citeproc; - -/** - * Decorates individual items in citations and bibliographies - * @author Michel Kraemer - */ -public interface VariableWrapper { - /** - * This method will be called by the citation processor when an item in a - * citation or bibliography is about to be rendered. The method may change - * the way the item is rendered, for example, by prepending or appending - * strings, or by completely replacing the item. The default implementation - * of this method always returns prePunct + str + postPunct. - * @param params a number of parameters that specify the context in which - * rendering happens, the citation item that is currently being rendered, - * and additional information. - * @param prePunct the text that precedes the item to render - * @param str the item to render - * @param postPunct the text that follows the item to render - * @return the string to be rendered - */ - String wrap(VariableWrapperParams params, String prePunct, String str, String postPunct); -} diff --git a/citeproc-java/src/test/java/de/undercouch/citeproc/CSLTest.java b/citeproc-java/src/test/java/de/undercouch/citeproc/CSLTest.java index 0e56e64e..e8325f37 100644 --- a/citeproc-java/src/test/java/de/undercouch/citeproc/CSLTest.java +++ b/citeproc-java/src/test/java/de/undercouch/citeproc/CSLTest.java @@ -394,32 +394,6 @@ public void abbreviations() throws Exception { assertEquals("Johnson and Kernighan, \u201cB.\u201d", a.get(0).getText()); } - /** - * Tests if output can be decorated - * @throws Exception if something goes wrong - */ - @Test - public void variableWrapper() throws Exception { - VariableWrapper wrapper = (params, prePunct, str, postPunct) -> { - if (params.getContext() == Context.CITATION && - Arrays.asList(params.getVariableNames()).contains("author")) { - return prePunct + "" + str + "" + postPunct; - } - return prePunct + str + postPunct; - }; - - CSL citeproc = new CSLBuilder() - .itemDataProvider(new ListItemDataProvider(items)) - .variableWrapper(wrapper) - .style("chicago-note-bibliography") - .build(); - List a = citeproc.makeCitation(items[0].getId()); - assertEquals(0, a.get(0).getIndex()); - assertEquals("Johnson and Kernighan, " - + "\u201cThe Programming Language B.\u201d", - a.get(0).getText()); - } - /** * Tests if citation items can be registered unsorted * @throws Exception if something goes wrong diff --git a/citeproc-java/templates/Context.json b/citeproc-java/templates/Context.json deleted file mode 100644 index 2c6138fb..00000000 --- a/citeproc-java/templates/Context.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Context", - "pkg": "de.undercouch.citeproc", - "description": "A context in which rendering happens", - - "types": [ - "citation", - "bibliography" - ] -} diff --git a/citeproc-java/templates/VariableWrapperParams.json b/citeproc-java/templates/VariableWrapperParams.json deleted file mode 100644 index af430baf..00000000 --- a/citeproc-java/templates/VariableWrapperParams.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "VariableWrapperParams", - "pkg": "de.undercouch.citeproc", - "description": "Parameters for a {@link de.undercouch.citeproc.VariableWrapper}", - - "additionalImports": [ - "de.undercouch.citeproc.csl.CSLItemData" - ], - - "props": [ - { - "type": "CSLItemData", - "name": "itemData" - }, - { - "type": "String[]", - "name": "variableNames" - }, - { - "type": "Context", - "name": "context" - }, - { - "type": "String", - "name": "xclass" - }, - { - "type": "String", - "name": "position" - }, - { - "type": "Integer", - "name": "note-number" - }, - { - "type": "Integer", - "name": "first-reference-note-number" - }, - { - "type": "Integer", - "name": "citation-number" - }, - { - "type": "Integer", - "name": "index" - }, - { - "type": "String", - "name": "mode" - } - ] -} \ No newline at end of file