From 01fdc3e1ae7fc8941ef605f890e1d67e9f3dbbeb Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 17:02:37 +0530
Subject: [PATCH 01/24] Refactor CitationStyleGeneratorTest
---
.../CitationStyleGeneratorTest.java | 31 ++++++++-----------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index df3571b3ca1..e246bab6a97 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -22,15 +22,16 @@
class CitationStyleGeneratorTest {
+ private final BibEntry testEntry = TestEntry.getTestEntry();
+ private final BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(testEntry)));
private final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager();
+ private final List styleList = CitationStyle.discoverCitationStyles();
@Test
void aCMCitation() {
- BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(TestEntry.getTestEntry())));
context.setMode(BibDatabaseMode.BIBLATEX);
- List styleList = CitationStyle.discoverCitationStyles();
CitationStyle style = styleList.stream().filter(e -> "ACM SIGGRAPH".equals(e.getTitle())).findAny().orElse(null);
- String citation = CitationStyleGenerator.generateCitation(List.of(TestEntry.getTestEntry()), style.getSource(), CitationStyleOutputFormat.HTML, context, new BibEntryTypesManager()).getFirst();
+ String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager).getFirst();
// if the acm-siggraph.csl citation style changes this has to be modified
String expected = " "
@@ -43,11 +44,9 @@ void aCMCitation() {
@Test
void aPACitation() {
- BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(TestEntry.getTestEntry())));
context.setMode(BibDatabaseMode.BIBLATEX);
- List
styleList = CitationStyle.discoverCitationStyles();
CitationStyle style = styleList.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null);
- String citation = CitationStyleGenerator.generateCitation(List.of(TestEntry.getTestEntry()), style.getSource(), CitationStyleOutputFormat.HTML, context, new BibEntryTypesManager()).getFirst();
+ String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager).getFirst();
// if the apa-7th-citation.csl citation style changes this has to be modified
String expected = " "
@@ -97,11 +96,10 @@ void htmlFormat() {
"
[1]
B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.
\n" +
"
\n";
- BibEntry entry = TestEntry.getTestEntry();
String style = CitationStyle.getDefault().getSource();
CitationStyleOutputFormat format = CitationStyleOutputFormat.HTML;
- String actualCitation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, new BibDatabaseContext(), bibEntryTypesManager).getFirst();
+ String actualCitation = CitationStyleGenerator.generateCitation(List.of(testEntry), style, format, context, bibEntryTypesManager).getFirst();
assertEquals(expectedCitation, actualCitation);
}
@@ -109,11 +107,10 @@ void htmlFormat() {
void textFormat() {
String expectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n";
- BibEntry entry = TestEntry.getTestEntry();
String style = CitationStyle.getDefault().getSource();
CitationStyleOutputFormat format = CitationStyleOutputFormat.TEXT;
- String actualCitation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, new BibDatabaseContext(new BibDatabase(List.of(entry))), bibEntryTypesManager).getFirst();
+ String actualCitation = CitationStyleGenerator.generateCitation(List.of(testEntry), style, format, context, bibEntryTypesManager).getFirst();
assertEquals(expectedCitation, actualCitation);
}
@@ -134,12 +131,11 @@ void handleDiacritics() {
@Test
void handleAmpersand() {
String expectedCitation = "[1]B. Smith, B. Jones, and J. Williams, “Famous quote: “&TitleTest&” - that is it,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n";
- BibEntry entry = TestEntry.getTestEntry();
- entry.setField(StandardField.TITLE, "Famous quote: “&TitleTest&” - that is it");
+ testEntry.setField(StandardField.TITLE, "Famous quote: “&TitleTest&” - that is it");
String style = CitationStyle.getDefault().getSource();
CitationStyleOutputFormat format = CitationStyleOutputFormat.TEXT;
- String actualCitation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, new BibDatabaseContext(), bibEntryTypesManager).getFirst();
+ String actualCitation = CitationStyleGenerator.generateCitation(List.of(testEntry), style, format, context, bibEntryTypesManager).getFirst();
assertEquals(expectedCitation, actualCitation);
}
@@ -208,7 +204,7 @@ static Stream cslMapping() {
.withField(StandardField.ISSUE, "7")
.withField(StandardField.EID, "e0270533"),
"ieee.csl"),
- Arguments.of(
+ Arguments.of(
"[1]F. Last and J. Doe, no. 33, pp. 7–8.\n",
BibDatabaseMode.BIBLATEX,
new BibEntry(StandardEntryType.Article)
@@ -574,15 +570,14 @@ static Stream cslMapping() {
@ParameterizedTest
@MethodSource
- void cslMapping(String expected, BibDatabaseMode mode, BibEntry entry, String cslFileName) throws Exception {
- BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(List.of(entry)));
- bibDatabaseContext.setMode(mode);
+ void cslMapping(String expected, BibDatabaseMode mode, BibEntry entry, String cslFileName) {
+ context.setMode(mode);
String citation = CitationStyleGenerator.generateCitation(
List.of(entry),
CitationStyle.createCitationStyleFromFile(cslFileName).orElseThrow().getSource(),
CitationStyleOutputFormat.TEXT,
- bibDatabaseContext,
+ context,
bibEntryTypesManager).getFirst();
assertEquals(expected, citation);
}
From 833be285ea46efd936de5c76b78a40f020b922d5 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 17:10:19 +0530
Subject: [PATCH 02/24] Add test: [StAX] Parse title, isNumericStyle
---
.../logic/citationstyle/CitationStyle.java | 2 +-
.../citationstyle/CitationStyleTest.java | 33 +++++++++++++++++--
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
index 61d15761158..5d3c41a56b9 100644
--- a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
+++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
@@ -76,7 +76,7 @@ private static Optional createCitationStyleFromSource(final Input
public record StyleInfo(String title, boolean isNumericStyle) {
}
- private static Optional parseStyleInfo(String filename, String content) {
+ public static Optional parseStyleInfo(String filename, String content) {
FACTORY.setProperty(XMLInputFactory.IS_COALESCING, true);
try {
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
index 421a941f35d..092ce549ed9 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
@@ -1,6 +1,8 @@
package org.jabref.logic.citationstyle;
import java.util.List;
+import java.util.Optional;
+import java.util.stream.Stream;
import org.jabref.logic.util.TestEntry;
import org.jabref.model.database.BibDatabase;
@@ -9,14 +11,18 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class CitationStyleTest {
@Test
- void getDefault() throws Exception {
+ void getDefault() {
assertNotNull(CitationStyle.getDefault());
}
@@ -37,8 +43,31 @@ void defaultCitation() {
}
@Test
- void discoverCitationStylesNotNull() throws Exception {
+ void discoverCitationStylesNotNull() {
List styleList = CitationStyle.discoverCitationStyles();
assertNotNull(styleList);
}
+
+ @ParameterizedTest
+ @MethodSource("citationStyleProvider")
+ void testParseStyleInfo(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
+ Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
+
+ assertTrue(citationStyle.isPresent(), "Citation style should be present for " + cslFileName);
+
+ CitationStyle.StyleInfo styleInfo = new CitationStyle.StyleInfo(citationStyle.get().getTitle(), citationStyle.get().isNumericStyle());
+
+ assertEquals(expectedTitle, styleInfo.title(), "Title should match for " + cslFileName);
+ assertEquals(expectedNumericNature, styleInfo.isNumericStyle(), "Numeric style should match for " + cslFileName);
+ }
+
+ private static Stream citationStyleProvider() {
+ return Stream.of(
+ Arguments.of("ieee.csl", "IEEE", true),
+ Arguments.of("apa.csl", "American Psychological Association 7th edition", false),
+ Arguments.of("vancouver.csl", "Vancouver", true),
+ Arguments.of("chicago-author-date.csl", "Chicago Manual of Style 17th edition (author-date)", false),
+ Arguments.of("nature.csl", "Nature", true)
+ );
+ }
}
From 1bf6b59c1f0e2dd8e10c6e5b177ea71beceae1e2 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 17:15:34 +0530
Subject: [PATCH 03/24] Add CSLFormatUtils
---
.../openoffice/oocsltext/CSLFormatUtils.java | 153 ++++++++++++++++++
src/main/resources/csl-locales | 2 +-
src/main/resources/csl-styles | 2 +-
3 files changed, 155 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
new file mode 100644
index 00000000000..e043e5b914b
--- /dev/null
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
@@ -0,0 +1,153 @@
+package org.jabref.logic.openoffice.oocsltext;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jabref.logic.citationkeypattern.BracketedPattern;
+import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
+import org.jabref.model.database.BibDatabaseContext;
+import org.jabref.model.entry.AuthorList;
+import org.jabref.model.entry.BibEntry;
+import org.jabref.model.entry.field.StandardField;
+import org.jabref.model.openoffice.ootext.OOTextIntoOO;
+
+import org.apache.commons.text.StringEscapeUtils;
+
+/**
+ * Contains utility constants and methods for processing of CSL citations as generated by methods of citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator}).
+ * These methods are used in {@link CSLCitationOOAdapter} which inserts CSL citation text into an OO document.
+ */
+public class CSLFormatUtils {
+
+ private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
+ public static final String[] PREFIXES = {"JABREF_", "CSL_"};
+
+ // TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
+ public static final String DEFAULT_BIBLIOGRAPHY_TITLE = "References";
+ public static final String DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
+ public static final CitationStyleOutputFormat OUTPUT_FORMAT = CitationStyleOutputFormat.HTML;
+ private static final int MAX_ALPHA_AUTHORS = 4;
+
+ /**
+ * Transforms provided HTML into a format that can be fully parsed by OOTextIntoOO.write(...)
+ * The transformed HTML can be used for inserting into a LibreOffice document
+ * Context: The HTML produced by CitationStyleGenerator.generateCitation(...) is not directly (completely) parsable by OOTextIntoOO.write(...)
+ * For more details, read the documentation of the write(...) method in the {@link OOTextIntoOO} class.
+ * Additional Information.
+ *
+ * @param html The HTML string to be transformed into OO-write ready HTML.
+ * @return The formatted html string
+ */
+ public static String transformHTML(String html) {
+ // Initial clean up of escaped characters
+ html = StringEscapeUtils.unescapeHtml4(html);
+
+ // Handle margins (spaces between citation number and text)
+ html = html.replaceAll("(.*?)
(.*?)
", "$1 $2");
+
+ // Remove unsupported tags
+ html = html.replaceAll("]*>", "");
+ html = html.replace("
", "");
+
+ // Remove unsupported links
+ html = html.replaceAll("]*>", "");
+ html = html.replace("", "");
+
+ // Replace span tags with inline styles for bold
+ html = html.replaceAll("(.*?)", "$1");
+
+ // Replace span tags with inline styles for italic
+ html = html.replaceAll("(.*?)", "$1");
+
+ // Replace span tags with inline styles for underline
+ html = html.replaceAll("(.*?)", "$1");
+
+ html = html.replaceAll("(.*?)", "$1");
+
+ // Clean up any remaining span tags
+ html = html.replaceAll("?span[^>]*>", "");
+
+ return html;
+ }
+
+ /**
+ * Method to update citation number of a bibliographic entry.
+ * By default, citeproc-java's generateCitation always starts the numbering of a list of citations with "1".
+ * If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number.
+ * If an entries has been cited before, the current number should be old number.
+ * The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]".
+ * Precondition: Use ONLY with numeric citation styles.
+ *
+ * @param citation the numeric citation with an unresolved number.
+ * @param currentNumber the correct number to update the citation with.
+ * @return the bibliographic citation with resolved number.
+ */
+ public static String updateSingleCitation(String citation, int currentNumber) {
+ Pattern pattern = Pattern.compile("(\\[|\\()?(\\d+)(\\]|\\))?(\\.)?\\s*");
+ Matcher matcher = pattern.matcher(citation);
+ StringBuilder sb = new StringBuilder();
+ boolean numberReplaced = false;
+
+ while (matcher.find()) {
+ if (!numberReplaced) {
+ String prefix = matcher.group(1) != null ? matcher.group(1) : "";
+ String suffix = matcher.group(3) != null ? matcher.group(3) : "";
+ String dot = matcher.group(4) != null ? "." : "";
+ String space = matcher.group().endsWith(" ") ? " " : "";
+
+ String replacement = prefix + currentNumber + suffix + dot + space;
+
+ matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
+ numberReplaced = true;
+ } else {
+ matcher.appendReplacement(sb, matcher.group());
+ }
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ }
+
+ /**
+ * Extracts year from a citation having single or multiple entries, for the purpose of using in in-text citations.
+ *
+ * @param formattedCitation - the citation cleaned up and formatted using transformHTML
+ */
+ public static String changeToInText(String formattedCitation) {
+ Matcher matcher = YEAR_IN_CITATION_PATTERN.matcher(formattedCitation);
+ if (matcher.find()) {
+ return matcher.group(2) + " " + matcher.group(1) + matcher.group(3);
+ }
+ return formattedCitation;
+ }
+
+ public static String generateAlphanumericCitation(List entries, BibDatabaseContext bibDatabaseContext) {
+ StringBuilder citation = new StringBuilder("[");
+ for (int i = 0; i < entries.size(); i++) {
+ BibEntry entry = entries.get(i);
+ Optional author = entry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase());
+ Optional year = entry.getResolvedFieldOrAlias(StandardField.YEAR, bibDatabaseContext.getDatabase());
+
+ if (author.isPresent() && year.isPresent()) {
+ AuthorList authorList = AuthorList.parse(author.get());
+ String alphaKey = BracketedPattern.authorsAlpha(authorList);
+
+ // Extract last two digits of the year
+ String shortYear = year.get().length() >= 2 ?
+ year.get().substring(year.get().length() - 2) :
+ year.get();
+
+ citation.append(alphaKey).append(shortYear);
+ } else {
+ citation.append(entry.getCitationKey().orElse(""));
+ }
+
+ if (i < entries.size() - 1) {
+ citation.append("; ");
+ }
+ }
+ citation.append("]");
+ return citation.toString();
+ }
+}
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index 242640a0e00..e631a52dcea 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
+Subproject commit e631a52dcea396be20d031b6456e91dba7772224
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index d9989a28ed4..bf2926b71a9 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
+Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
From 3c0bc52b2876793069c30dd0d476396df9cf94bc Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 18:05:45 +0530
Subject: [PATCH 04/24] Refactor CSLCitationOOAdapter and add JavaDoc
---
.../oocsltext/CSLCitationOOAdapter.java | 228 ++++++------------
.../openoffice/oocsltext/CSLFormatUtils.java | 78 +++---
2 files changed, 115 insertions(+), 191 deletions(-)
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
index ecb0fa932e5..ff39e307af9 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
@@ -4,14 +4,12 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
-import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jabref.logic.citationkeypattern.BracketedPattern;
import org.jabref.logic.citationstyle.CitationStyle;
import org.jabref.logic.citationstyle.CitationStyleGenerator;
-import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
@@ -27,17 +25,9 @@
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.Exception;
-import org.apache.commons.text.StringEscapeUtils;
public class CSLCitationOOAdapter {
- // TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
- public static final String BIBLIOGRAPHY_TITLE = "References";
- public static final String BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
- private static final int MAX_ALPHA_AUTHORS = 4;
-
- private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
- private final CitationStyleOutputFormat format = CitationStyleOutputFormat.HTML;
private final XTextDocument document;
private final CSLReferenceMarkManager markManager;
@@ -50,42 +40,10 @@ public void readExistingMarks() throws WrappedTargetException, NoSuchElementExce
markManager.readExistingMarks();
}
- public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle, List entries, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager)
- throws WrappedTargetException, CreationException {
-
- OOText title = OOFormat.paragraph(OOText.fromString(BIBLIOGRAPHY_TITLE), BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT);
- OOTextIntoOO.write(document, cursor, OOText.fromString(title.toString()));
- OOText ooBreak = OOFormat.paragraph(OOText.fromString(""), "Body Text");
- OOTextIntoOO.write(document, cursor, ooBreak);
-
- String style = selectedStyle.getSource();
-
- // Sort entries based on their order of appearance in the document
- entries.sort(Comparator.comparingInt(entry -> markManager.getCitationNumber(entry.getCitationKey().orElse(""))));
- for (BibEntry entry : entries) {
- String citation = CitationStyleGenerator.generateCitation(List.of(entry), style, format, bibDatabaseContext, bibEntryTypesManager).getFirst();
- String citationKey = entry.getCitationKey().orElse("");
- int currentNumber = markManager.getCitationNumber(citationKey);
-
- String formattedCitation;
- if (selectedStyle.isNumericStyle()) {
- formattedCitation = updateSingleCitation(transformHtml(citation), currentNumber);
- } else {
- formattedCitation = transformHtml(citation);
- }
- OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
-
- OOTextIntoOO.write(document, cursor, ooText);
- if (selectedStyle.isNumericStyle()) {
- // Select the paragraph break
- cursor.goLeft((short) 1, true);
-
- // Delete the selected content (paragraph break)
- cursor.setString("");
- }
- }
- }
-
+ /**
+ * Inserts a citation for a group of entries.
+ * Comparable to LaTeX's \cite command.
+ */
public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List entries, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager)
throws CreationException, IOException, Exception {
String style = selectedStyle.getSource();
@@ -93,12 +51,12 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List
String inTextCitation;
if (isAlphanumeric) {
- inTextCitation = generateAlphanumericCitation(entries, bibDatabaseContext);
+ inTextCitation = CSLFormatUtils.generateAlphanumericCitation(entries, bibDatabaseContext);
} else {
- inTextCitation = CitationStyleGenerator.generateInText(entries, style, format, bibDatabaseContext, bibEntryTypesManager).getText();
+ inTextCitation = CitationStyleGenerator.generateInText(entries, style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getText();
}
- String formattedCitation = transformHtml(inTextCitation);
+ String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
if (selectedStyle.isNumericStyle()) {
formattedCitation = updateMultipleCitations(formattedCitation, entries);
@@ -110,7 +68,7 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List
}
/**
- * Inserts the in-text citation for a group of entries.
+ * Inserts in-text citations for a group of entries.
* Comparable to LaTeX's \citet command.
*
* @implNote Very similar to the {@link #insertCitation(XTextCursor, CitationStyle, List, BibDatabaseContext, BibEntryTypesManager)} method.insertInText method
@@ -126,7 +84,7 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
String inTextCitation;
if (isAlphanumeric) {
// Generate the alphanumeric citation
- inTextCitation = generateAlphanumericCitation(List.of(currentEntry), bibDatabaseContext);
+ inTextCitation = CSLFormatUtils.generateAlphanumericCitation(List.of(currentEntry), bibDatabaseContext);
// Get the author's name
String authorName = currentEntry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase())
.map(AuthorList::parse)
@@ -135,9 +93,9 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
// Combine author name with the citation
inTextCitation = authorName + " " + inTextCitation;
} else {
- inTextCitation = CitationStyleGenerator.generateInText(List.of(currentEntry), style, format, bibDatabaseContext, bibEntryTypesManager).getText();
+ inTextCitation = CitationStyleGenerator.generateInText(List.of(currentEntry), style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getText();
}
- String formattedCitation = transformHtml(inTextCitation);
+ String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
String finalText;
if (selectedStyle.isNumericStyle()) {
formattedCitation = updateMultipleCitations(formattedCitation, List.of(currentEntry));
@@ -149,7 +107,7 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
} else if (isAlphanumeric) {
finalText = formattedCitation;
} else {
- finalText = changeToInText(formattedCitation);
+ finalText = CSLFormatUtils.changeToInText(formattedCitation);
}
if (iterator.hasNext()) {
finalText += ",";
@@ -160,14 +118,10 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
}
}
- private String changeToInText(String formattedCitation) {
- Matcher matcher = YEAR_IN_CITATION_PATTERN.matcher(formattedCitation);
- if (matcher.find()) {
- return matcher.group(2) + " " + matcher.group(1) + matcher.group(3);
- }
- return formattedCitation;
- }
-
+ /**
+ * Inserts "empty" citations for a list of entries at the cursor to the document.
+ * Adds the entries to the list for which bibliography is to be generated.
+ */
public void insertEmpty(XTextCursor cursor, List entries)
throws CreationException, Exception {
for (BibEntry entry : entries) {
@@ -180,6 +134,53 @@ public void insertEmpty(XTextCursor cursor, List entries)
cursor.collapseToEnd();
}
+ /**
+ * Creates a "Bibliography" section in the document and inserts a list of references.
+ * The list is generated based on the existing citations, in-text citations and empty citations in the document.
+ */
+ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle, List entries, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager)
+ throws WrappedTargetException, CreationException {
+
+ OOText title = OOFormat.paragraph(OOText.fromString(CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_TITLE), CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT);
+ OOTextIntoOO.write(document, cursor, OOText.fromString(title.toString()));
+ OOText ooBreak = OOFormat.paragraph(OOText.fromString(""), "Body Text");
+ OOTextIntoOO.write(document, cursor, ooBreak);
+
+ String style = selectedStyle.getSource();
+
+ // Sort entries based on their order of appearance in the document
+ entries.sort(Comparator.comparingInt(entry -> markManager.getCitationNumber(entry.getCitationKey().orElse(""))));
+ for (BibEntry entry : entries) {
+ String citation = CitationStyleGenerator.generateCitation(List.of(entry), style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getFirst();
+ String citationKey = entry.getCitationKey().orElse("");
+ int currentNumber = markManager.getCitationNumber(citationKey);
+
+ String formattedCitation;
+ if (selectedStyle.isNumericStyle()) {
+ formattedCitation = CSLFormatUtils.updateSingleCitation(CSLFormatUtils.transformHtml(citation), currentNumber);
+ } else {
+ formattedCitation = CSLFormatUtils.transformHtml(citation);
+ }
+ OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
+
+ OOTextIntoOO.write(document, cursor, ooText);
+ if (selectedStyle.isNumericStyle()) {
+ // Select the paragraph break
+ cursor.goLeft((short) 1, true);
+
+ // Delete the selected content (paragraph break)
+ cursor.setString("");
+ }
+ }
+ }
+
+ /**
+ * It is difficult to "segment" a single citation generated for a group of entries into distinct parts based on the entries such that each entry can be draped with its corresponding reference mark.
+ * This is because of the sheer variety in the styles of citations and the separators between them (when grouped) in case of Citation Style Language.
+ * Furthermore, it is also difficult to generate a "single" reference mark for a group of entries.
+ * Thus, in case of citations for a group of entries, we first insert the citation (text), then insert the invisible reference marks for each entry separately after it.
+ * Implements "smart spaces" - adds a space before the citation if not already present.
+ */
private void insertMultipleReferenceMarks(XTextCursor cursor, List entries, OOText ooText)
throws CreationException, Exception {
boolean preceedingSpaceExists;
@@ -218,7 +219,7 @@ private void insertMultipleReferenceMarks(XTextCursor cursor, List ent
}
/**
- * Transforms the numbers in the citation to globally-unique numbers
+ * Transforms the numbers in the citation to globally-unique (and thus, reusable) numbers.
*/
private String updateMultipleCitations(String citation, List entries) {
Pattern pattern = Pattern.compile("(\\D*)(\\d+)(\\D*)");
@@ -238,107 +239,20 @@ private String updateMultipleCitations(String citation, List entries)
return sb.toString();
}
- public static String updateSingleCitation(String citation, int currentNumber) {
- Pattern pattern = Pattern.compile("(\\[|\\()?(\\d+)(\\]|\\))?(\\.)?\\s*");
- Matcher matcher = pattern.matcher(citation);
- StringBuilder sb = new StringBuilder();
- boolean numberReplaced = false;
-
- while (matcher.find()) {
- if (!numberReplaced) {
- String prefix = matcher.group(1) != null ? matcher.group(1) : "";
- String suffix = matcher.group(3) != null ? matcher.group(3) : "";
- String dot = matcher.group(4) != null ? "." : "";
- String space = matcher.group().endsWith(" ") ? " " : "";
-
- String replacement = prefix + currentNumber + suffix + dot + space;
-
- matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
- numberReplaced = true;
- } else {
- matcher.appendReplacement(sb, matcher.group());
- }
- }
- matcher.appendTail(sb);
- return sb.toString();
- }
-
/**
- * Transforms provided HTML into a format that can be fully parsed by OOTextIntoOO.write(...)
- * The transformed HTML can be used for inserting into a LibreOffice document
- * Context: The HTML produced by CitationStyleGenerator.generateCitation(...) is not directly (completely) parsable by OOTextIntoOO.write(...)
- * For more details, read the documentation of the write(...) method in the {@link OOTextIntoOO} class.
- * Additional Information.
- *
- * @param html The HTML string to be transformed into OO-write ready HTML.
- * @return The formatted html string
+ * Checks if an entry has already been cited before in the document.
+ * Required for consistent numbering of numeric citations - if present, the number is to be reused, else a new number is to be assigned.
*/
- private String transformHtml(String html) {
- // Initial clean up of escaped characters
- html = StringEscapeUtils.unescapeHtml4(html);
-
- // Handle margins (spaces between citation number and text)
- html = html.replaceAll("(.*?)
(.*?)
", "$1 $2");
-
- // Remove unsupported tags
- html = html.replaceAll("]*>", "");
- html = html.replace("
", "");
-
- // Remove unsupported links
- html = html.replaceAll("]*>", "");
- html = html.replace("", "");
-
- // Replace span tags with inline styles for bold
- html = html.replaceAll("(.*?)", "$1");
-
- // Replace span tags with inline styles for italic
- html = html.replaceAll("(.*?)", "$1");
-
- // Replace span tags with inline styles for underline
- html = html.replaceAll("(.*?)", "$1");
-
- html = html.replaceAll("(.*?)", "$1");
-
- // Clean up any remaining span tags
- html = html.replaceAll("?span[^>]*>", "");
-
- return html;
- }
-
public boolean isCitedEntry(BibEntry entry) {
String citationKey = entry.getCitationKey().orElse("");
return markManager.hasCitationForKey(citationKey);
}
- private String generateAlphanumericCitation(List entries, BibDatabaseContext bibDatabaseContext) {
- StringBuilder citation = new StringBuilder("[");
- for (int i = 0; i < entries.size(); i++) {
- BibEntry entry = entries.get(i);
- Optional author = entry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase());
- Optional year = entry.getResolvedFieldOrAlias(StandardField.YEAR, bibDatabaseContext.getDatabase());
-
- if (author.isPresent() && year.isPresent()) {
- AuthorList authorList = AuthorList.parse(author.get());
- String alphaKey = BracketedPattern.authorsAlpha(authorList);
-
- // Extract last two digits of the year
- String shortYear = year.get().length() >= 2 ?
- year.get().substring(year.get().length() - 2) :
- year.get();
-
- citation.append(alphaKey).append(shortYear);
- } else {
- citation.append(entry.getCitationKey().orElse(""));
- }
-
- if (i < entries.size() - 1) {
- citation.append("; ");
- }
- }
- citation.append("]");
- return citation.toString();
- }
-
+ /**
+ * Currently, we have support for one alphanumeric CSL style.
+ * There is no tag or field in .csl style files that can be parsed to determine if it is an alphanumeric style.
+ * Thus, we currently hardcode the check for "DIN 1505-2".
+ */
private boolean isAlphanumericStyle(CitationStyle style) {
return "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(style.getTitle());
}
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
index e043e5b914b..59839f37d98 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
@@ -10,9 +10,13 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
+import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.StandardField;
+import org.jabref.model.openoffice.ootext.OOText;
import org.jabref.model.openoffice.ootext.OOTextIntoOO;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
import org.apache.commons.text.StringEscapeUtils;
/**
@@ -21,26 +25,25 @@
*/
public class CSLFormatUtils {
- private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
public static final String[] PREFIXES = {"JABREF_", "CSL_"};
// TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
public static final String DEFAULT_BIBLIOGRAPHY_TITLE = "References";
public static final String DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
public static final CitationStyleOutputFormat OUTPUT_FORMAT = CitationStyleOutputFormat.HTML;
- private static final int MAX_ALPHA_AUTHORS = 4;
+ private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
/**
- * Transforms provided HTML into a format that can be fully parsed by OOTextIntoOO.write(...)
+ * Transforms provided HTML into a format that can be fully parsed by {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write}.
* The transformed HTML can be used for inserting into a LibreOffice document
* Context: The HTML produced by CitationStyleGenerator.generateCitation(...) is not directly (completely) parsable by OOTextIntoOO.write(...)
- * For more details, read the documentation of the write(...) method in the {@link OOTextIntoOO} class.
+ * For more details, read the documentation for the {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write} method in the OOTextIntoOO class.
* Additional Information.
*
* @param html The HTML string to be transformed into OO-write ready HTML.
* @return The formatted html string
*/
- public static String transformHTML(String html) {
+ public static String transformHtml(String html) {
// Initial clean up of escaped characters
html = StringEscapeUtils.unescapeHtml4(html);
@@ -72,6 +75,42 @@ public static String transformHTML(String html) {
return html;
}
+ /**
+ * Alphanumeric citations are not natively supported by citeproc-java. (See {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}).
+ * Thus, we manually format a citation to produce its alphanumeric form.
+ *
+ * @param entries the list of entries for which the alphanumeric citation is to be generated.
+ * @return the alphanumeric citation (for a single entry or a group of entries).
+ */
+ public static String generateAlphanumericCitation(List entries, BibDatabaseContext bibDatabaseContext) {
+ StringBuilder citation = new StringBuilder("[");
+ for (int i = 0; i < entries.size(); i++) {
+ BibEntry entry = entries.get(i);
+ Optional author = entry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase());
+ Optional year = entry.getResolvedFieldOrAlias(StandardField.YEAR, bibDatabaseContext.getDatabase());
+
+ if (author.isPresent() && year.isPresent()) {
+ AuthorList authorList = AuthorList.parse(author.get());
+ String alphaKey = BracketedPattern.authorsAlpha(authorList);
+
+ // Extract last two digits of the year
+ String shortYear = year.get().length() >= 2 ?
+ year.get().substring(year.get().length() - 2) :
+ year.get();
+
+ citation.append(alphaKey).append(shortYear);
+ } else {
+ citation.append(entry.getCitationKey().orElse(""));
+ }
+
+ if (i < entries.size() - 1) {
+ citation.append("; ");
+ }
+ }
+ citation.append("]");
+ return citation.toString();
+ }
+
/**
* Method to update citation number of a bibliographic entry.
* By default, citeproc-java's generateCitation always starts the numbering of a list of citations with "1".
@@ -121,33 +160,4 @@ public static String changeToInText(String formattedCitation) {
}
return formattedCitation;
}
-
- public static String generateAlphanumericCitation(List entries, BibDatabaseContext bibDatabaseContext) {
- StringBuilder citation = new StringBuilder("[");
- for (int i = 0; i < entries.size(); i++) {
- BibEntry entry = entries.get(i);
- Optional author = entry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase());
- Optional year = entry.getResolvedFieldOrAlias(StandardField.YEAR, bibDatabaseContext.getDatabase());
-
- if (author.isPresent() && year.isPresent()) {
- AuthorList authorList = AuthorList.parse(author.get());
- String alphaKey = BracketedPattern.authorsAlpha(authorList);
-
- // Extract last two digits of the year
- String shortYear = year.get().length() >= 2 ?
- year.get().substring(year.get().length() - 2) :
- year.get();
-
- citation.append(alphaKey).append(shortYear);
- } else {
- citation.append(entry.getCitationKey().orElse(""));
- }
-
- if (i < entries.size() - 1) {
- citation.append("; ");
- }
- }
- citation.append("]");
- return citation.toString();
- }
}
From 262287a58293dbca21b7ef0a638b62729e6d6ec7 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 18:13:27 +0530
Subject: [PATCH 05/24] Add test for citeproc DIN 1505-2
---
.../CitationStyleGeneratorTest.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index e246bab6a97..250f5a884e1 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -57,6 +57,22 @@ void aPACitation() {
assertEquals(expected, citation);
}
+ /**
+ * The below test, as of now, fails due to citeproc-java returning an empty citation.
+ * Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
+ */
+// @Test
+// void din1502AlphanumericInTextCitation() throws IOException {
+// context.setMode(BibDatabaseMode.BIBLATEX);
+// CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().orElse(null);
+// Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager);
+// String inTextCitationText = citation.getText();
+//
+// String expected = "[Smit2016]";
+//
+// assertEquals(expected, inTextCitationText);
+// }
+
@Test
void ignoreNewLine() {
BibEntry entry = new BibEntry();
From 3f87126a7af59a52554dce77708ab70224d69922 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 18:37:50 +0530
Subject: [PATCH 06/24] Better method names, more javadoc
---
.../oocsltext/CSLCitationOOAdapter.java | 8 +++---
.../openoffice/oocsltext/CSLFormatUtils.java | 25 ++++++++-----------
2 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
index ff39e307af9..626554567e1 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
@@ -59,7 +59,7 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List
String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
if (selectedStyle.isNumericStyle()) {
- formattedCitation = updateMultipleCitations(formattedCitation, entries);
+ formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, entries);
}
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
@@ -98,7 +98,7 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
String finalText;
if (selectedStyle.isNumericStyle()) {
- formattedCitation = updateMultipleCitations(formattedCitation, List.of(currentEntry));
+ formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, List.of(currentEntry));
String prefix = currentEntry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase())
.map(AuthorList::parse)
.map(list -> BracketedPattern.joinAuthorsOnLastName(list, 1, "", " et al.") + " ")
@@ -157,7 +157,7 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
String formattedCitation;
if (selectedStyle.isNumericStyle()) {
- formattedCitation = CSLFormatUtils.updateSingleCitation(CSLFormatUtils.transformHtml(citation), currentNumber);
+ formattedCitation = CSLFormatUtils.updateSingleBibliographyNumber(CSLFormatUtils.transformHtml(citation), currentNumber);
} else {
formattedCitation = CSLFormatUtils.transformHtml(citation);
}
@@ -221,7 +221,7 @@ private void insertMultipleReferenceMarks(XTextCursor cursor, List ent
/**
* Transforms the numbers in the citation to globally-unique (and thus, reusable) numbers.
*/
- private String updateMultipleCitations(String citation, List entries) {
+ private String updateSingleOrMultipleCitationNumbers(String citation, List entries) {
Pattern pattern = Pattern.compile("(\\D*)(\\d+)(\\D*)");
Matcher matcher = pattern.matcher(citation);
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
index 59839f37d98..9d391a8b0b6 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
@@ -25,8 +25,6 @@
*/
public class CSLFormatUtils {
- public static final String[] PREFIXES = {"JABREF_", "CSL_"};
-
// TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
public static final String DEFAULT_BIBLIOGRAPHY_TITLE = "References";
public static final String DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
@@ -34,14 +32,13 @@ public class CSLFormatUtils {
private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
/**
- * Transforms provided HTML into a format that can be fully parsed by {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write}.
- * The transformed HTML can be used for inserting into a LibreOffice document
- * Context: The HTML produced by CitationStyleGenerator.generateCitation(...) is not directly (completely) parsable by OOTextIntoOO.write(...)
- * For more details, read the documentation for the {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write} method in the OOTextIntoOO class.
+ * Transforms provided HTML into a format that can be fully parsed and inserted into an OO document.
+ * Context: The HTML produced by {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} or {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} is not directly (completely) parsable by by {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write}.
+ * For more details, read the documentation for the {@link OOTextIntoOO} class.
* Additional Information.
*
* @param html The HTML string to be transformed into OO-write ready HTML.
- * @return The formatted html string
+ * @return The formatted html string.
*/
public static String transformHtml(String html) {
// Initial clean up of escaped characters
@@ -76,7 +73,7 @@ public static String transformHtml(String html) {
}
/**
- * Alphanumeric citations are not natively supported by citeproc-java. (See {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}).
+ * Alphanumeric citations are not natively supported by citeproc-java (see {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}).
* Thus, we manually format a citation to produce its alphanumeric form.
*
* @param entries the list of entries for which the alphanumeric citation is to be generated.
@@ -112,18 +109,18 @@ public static String generateAlphanumericCitation(List entries, BibDat
}
/**
- * Method to update citation number of a bibliographic entry.
- * By default, citeproc-java's generateCitation always starts the numbering of a list of citations with "1".
+ * Method to update citation number of a bibliographic entry (to be inserted in the list of references).
+ * By default, citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} always start the numbering of a list of citations with "1".
* If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number.
- * If an entries has been cited before, the current number should be old number.
+ * If an entries has been cited before, the colder number should be reused.
* The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]".
- * Precondition: Use ONLY with numeric citation styles.
+ * Precondition: Use ONLY with numeric citation styles.
*
* @param citation the numeric citation with an unresolved number.
* @param currentNumber the correct number to update the citation with.
* @return the bibliographic citation with resolved number.
*/
- public static String updateSingleCitation(String citation, int currentNumber) {
+ public static String updateSingleBibliographyNumber(String citation, int currentNumber) {
Pattern pattern = Pattern.compile("(\\[|\\()?(\\d+)(\\]|\\))?(\\.)?\\s*");
Matcher matcher = pattern.matcher(citation);
StringBuilder sb = new StringBuilder();
@@ -151,7 +148,7 @@ public static String updateSingleCitation(String citation, int currentNumber) {
/**
* Extracts year from a citation having single or multiple entries, for the purpose of using in in-text citations.
*
- * @param formattedCitation - the citation cleaned up and formatted using transformHTML
+ * @param formattedCitation the citation cleaned up and formatted using {@link CSLFormatUtils#transformHtml transformHTML}.
*/
public static String changeToInText(String formattedCitation) {
Matcher matcher = YEAR_IN_CITATION_PATTERN.matcher(formattedCitation);
From 70a8e47e5483c9baa93e4c20c9bfc22e09dfab48 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:19:07 +0530
Subject: [PATCH 07/24] Add tests for CSLFormatUtils
---
.../oocsltext/CSLCitationOOAdapter.java | 8 +-
.../openoffice/oocsltext/CSLFormatUtils.java | 7 +-
.../oocsltext/CSLFormatUtilsTest.java | 721 ++++++++++++++++++
3 files changed, 729 insertions(+), 7 deletions(-)
create mode 100644 src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
index 626554567e1..ae4b6b2ea15 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
@@ -56,7 +56,7 @@ public void insertCitation(XTextCursor cursor, CitationStyle selectedStyle, List
inTextCitation = CitationStyleGenerator.generateInText(entries, style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getText();
}
- String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
+ String formattedCitation = CSLFormatUtils.transformHTML(inTextCitation);
if (selectedStyle.isNumericStyle()) {
formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, entries);
@@ -95,7 +95,7 @@ public void insertInTextCitation(XTextCursor cursor, CitationStyle selectedStyle
} else {
inTextCitation = CitationStyleGenerator.generateInText(List.of(currentEntry), style, CSLFormatUtils.OUTPUT_FORMAT, bibDatabaseContext, bibEntryTypesManager).getText();
}
- String formattedCitation = CSLFormatUtils.transformHtml(inTextCitation);
+ String formattedCitation = CSLFormatUtils.transformHTML(inTextCitation);
String finalText;
if (selectedStyle.isNumericStyle()) {
formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, List.of(currentEntry));
@@ -157,9 +157,9 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
String formattedCitation;
if (selectedStyle.isNumericStyle()) {
- formattedCitation = CSLFormatUtils.updateSingleBibliographyNumber(CSLFormatUtils.transformHtml(citation), currentNumber);
+ formattedCitation = CSLFormatUtils.updateSingleBibliographyNumber(CSLFormatUtils.transformHTML(citation), currentNumber);
} else {
- formattedCitation = CSLFormatUtils.transformHtml(citation);
+ formattedCitation = CSLFormatUtils.transformHTML(citation);
}
OOText ooText = OOFormat.setLocaleNone(OOText.fromString(formattedCitation));
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
index 9d391a8b0b6..9e13a2e9927 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
@@ -40,7 +40,7 @@ public class CSLFormatUtils {
* @param html The HTML string to be transformed into OO-write ready HTML.
* @return The formatted html string.
*/
- public static String transformHtml(String html) {
+ public static String transformHTML(String html) {
// Initial clean up of escaped characters
html = StringEscapeUtils.unescapeHtml4(html);
@@ -114,7 +114,8 @@ public static String generateAlphanumericCitation(List entries, BibDat
* If a citation doesn't correspond to the first cited entry, the number should be changed to the relevant current citation number.
* If an entries has been cited before, the colder number should be reused.
* The number can be enclosed in different formats, such as "1", "1.", "1)", "(1)" or "[1]".
- * Precondition: Use ONLY with numeric citation styles.
+ *
+ * Precondition: Use ONLY with numeric citation styles.
*
* @param citation the numeric citation with an unresolved number.
* @param currentNumber the correct number to update the citation with.
@@ -148,7 +149,7 @@ public static String updateSingleBibliographyNumber(String citation, int current
/**
* Extracts year from a citation having single or multiple entries, for the purpose of using in in-text citations.
*
- * @param formattedCitation the citation cleaned up and formatted using {@link CSLFormatUtils#transformHtml transformHTML}.
+ * @param formattedCitation the citation cleaned up and formatted using {@link CSLFormatUtils#transformHTML transformHTML}.
*/
public static String changeToInText(String formattedCitation) {
Matcher matcher = YEAR_IN_CITATION_PATTERN.matcher(formattedCitation);
diff --git a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
new file mode 100644
index 00000000000..f65fe1f0c18
--- /dev/null
+++ b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
@@ -0,0 +1,721 @@
+package org.jabref.logic.openoffice.oocsltext;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.jabref.logic.citationstyle.CitationStyle;
+import org.jabref.logic.citationstyle.CitationStyleGenerator;
+import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
+import org.jabref.logic.util.TestEntry;
+import org.jabref.model.database.BibDatabase;
+import org.jabref.model.database.BibDatabaseContext;
+import org.jabref.model.database.BibDatabaseMode;
+import org.jabref.model.entry.BibEntry;
+import org.jabref.model.entry.BibEntryTypesManager;
+import org.jabref.model.entry.field.StandardField;
+import org.jabref.model.entry.types.StandardEntryType;
+import org.jabref.model.openoffice.ootext.OOText;
+
+import de.undercouch.citeproc.output.Citation;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.jabref.logic.openoffice.oocsltext.CSLFormatUtils.generateAlphanumericCitation;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class CSLFormatUtilsTest {
+
+ private static final List STYLE_LIST = CitationStyle.discoverCitationStyles();
+
+ private final BibEntry testEntry = TestEntry.getTestEntry();
+ private final BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(List.of(TestEntry.getTestEntry())));
+ private final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager();
+
+ /**
+ * Test to check transformation of raw, unsupported HTML into OO-ready HTML.
+ *
+ * @param input the raw HTML.
+ */
+ @ParameterizedTest
+ @MethodSource("rawHTMLProvider")
+ void ooHTMLTransformFromRawHTML(String input, String expected) {
+ String actual = CSLFormatUtils.transformHTML(input);
+ assertEquals(expected, actual);
+ }
+
+ static Stream rawHTMLProvider() {
+ return Stream.of(
+ // First three are general test cases for unescaping HTML entities
+
+ // Ampersand (& entity)
+ Arguments.of(
+ "Smith & Jones",
+ "Smith & Jones"
+ ),
+
+ // Non-breaking space ( entity)
+ Arguments.of(
+ "Text with non-breaking spaces",
+ "Text with non-breaking spaces"
+ ),
+
+ // Bold formatting, less than, greater than symbols (<, > entities)
+ Arguments.of(
+ "<b>Bold Text</b>",
+ "Bold Text"
+ ),
+
+ // Handling margins
+ Arguments.of(
+ "[1]
Citation text
",
+ "[1] Citation text"
+ ),
+
+ // Removing unsupported div tags
+ Arguments.of(
+ "Aligned text
",
+ "Aligned text"
+ ),
+
+ // Removing unsupported links
+ Arguments.of(
+ "Text with link",
+ "Text with link"
+ ),
+
+ // Replacing span tags with inline styles for bold
+ Arguments.of(
+ "Text with bold",
+ "Text with bold"
+ ),
+
+ // Replacing span tags with inline styles for italic
+ Arguments.of(
+ "Text with italic",
+ "Text with italic"
+ ),
+
+ // Replacing span tags with inline styles for underline
+ Arguments.of(
+ "Text with underline",
+ "Text with underline"
+ ),
+
+ // Replacing span tags with inline styles for small-caps
+ Arguments.of(
+ "Text with small caps",
+ "Text with small caps"
+ ),
+
+ // Test case for cleaning up remaining span tags
+ Arguments.of(
+ "Text with unnecessary span",
+ "Text with unnecessary span"
+ ),
+
+ // Test case combining multiple transformations
+ Arguments.of(
+ "[1]
Author, "Title," Journal, vol. 1, no. 1, pp. 1-10, 2023.
",
+ "[1] Author, \"Title,\" Journal, vol. 1, no. 1, pp. 1-10, 2023."
+ ),
+
+ // Comprehensive test
+ Arguments.of(
+ "[1]
" +
+ "
Smith & Jones, " +
+ ""
Analysis of <code> in HTML," " +
+ "
Journal of Web Development, " +
+ "vol. 1, no. 1, pp. 1-10, 2023. " +
+ "
https://doi.org/10.1000/example ",
+
+ "[1] Smith & Jones, " +
+ "\"Analysis of in HTML,\" " +
+ "Journal of Web Development, " +
+ "vol. 1, no. 1, pp. 1-10, 2023. " +
+ "https://doi.org/10.1000/example"
+ )
+ );
+ }
+
+ /**
+ * Test to check correct transformation of raw CSL bibliography generated by citeproc-java methods into OO-ready text.
+ *
+ * Precondition: This test assumes that {@link CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} works as expected.
+ *
+ *
+ * @param style the CSL style to test transformation on.
+ */
+ @ParameterizedTest
+ @MethodSource("rawBibliographyProvider")
+ void ooHTMLTransformFromRawBibliography(CitationStyle style, String expected) {
+ String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager).getFirst();
+ String actual = CSLFormatUtils.transformHTML(citation);
+ assertEquals(expected, actual);
+ }
+
+ static Stream rawBibliographyProvider() {
+ return Stream.of(
+
+ // Non-numeric, parentheses, commas, full stops, slashes, hyphens, colons, italics
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ " Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb\n"
+ ),
+
+ // Numeric type "[1]", brackets, newlines
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Numeric type "1."
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ " Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n"
+ ),
+
+ // Semicolons
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef\n" +
+ " \n"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. BibTeX Journal 34, 45–67 (2016).\n" +
+ " \n"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. BibTeX Journal. 2016;34(3):45-67. doi:10.1001/bla.blubb\n" +
+ " \n"
+ ),
+
+ // Small-caps
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ " Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.\n"
+ ),
+
+ // Underlines
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ " Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .\n"
+ ),
+
+ // Non-breaking spaces
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ " Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.\n"
+ ),
+
+ // Numeric with a full stop - "1."
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
+ " \n"
+ ),
+
+ // Bold text, bold numeric with a full stop - "1."
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
+ " \n"
+ ),
+
+ // Naked numeric - "1"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Numeric in parentheses - "(1)"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Numeric with right parenthesis - "1)"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 1) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
+ " \n"
+ ),
+
+ // Numeric in superscript - "1"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ " 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
+ )
+ );
+ }
+
+ /**
+ * Test to check correct transformation of raw CSL citation with a single entry generated by citeproc-java methods into OO-ready text.
+ *
+ * Precondition: This test assumes that {@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} works as expected.
+ *
+ *
+ * @param style the CSL style to test transformation on.
+ */
+ @ParameterizedTest
+ @MethodSource("rawCitationWithSingleEntryProvider")
+ void ooHTMLTransformFromCitationWithSingleEntry(CitationStyle style, String expected) throws IOException {
+ Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager);
+ String inTextCitationText = citation.getText();
+ String actual = CSLFormatUtils.transformHTML(inTextCitationText);
+ OOText ooText = OOText.fromString(actual);
+ assertEquals(OOText.fromString(expected), ooText);
+ }
+
+ static Stream rawCitationWithSingleEntryProvider() {
+ return Stream.of(
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ "(Smith et al., 2016)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ "[1]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ "[1]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ "(Smith, Jones, and Williams 2016)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ "(1)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ "1"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ "1"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ "(Smith, Jones, Williams, 2016)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ "(Smith, Jones, & Williams)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ "Smith, B., B. Jones, and J. Williams, 2016."
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ "[1]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ "(1)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ "1"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ "1"
+ ),
+
+ // Note: not sure if the right parenthesis outside the superscript is correct, but that's how citeproc-java generates it in raw form as well.
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ "1)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ "1"
+ )
+ );
+ }
+
+ /**
+ * Test to check correct transformation of raw CSL citations with multiple entries generated by citeproc-java methods into OO-ready text.
+ *
+ * Precondition: This test assumes that {@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} works as expected.
+ *
+ *
+ * @param style the CSL style to test transformation on.
+ */
+ @ParameterizedTest
+ @MethodSource("rawCitationWithMultipleEntriesProvider")
+ void ooHTMLTransformFromCitationWithMultipleEntries(CitationStyle style, String expected) throws IOException {
+ BibEntry entry1 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Garcia, Maria and Lee, David")
+ .withField(StandardField.JOURNAL, "International Review of Physics")
+ .withField(StandardField.NUMBER, "6")
+ .withField(StandardField.PAGES, "789--810")
+ .withField(StandardField.TITLE, "Quantum Entanglement in Superconductors")
+ .withField(StandardField.VOLUME, "28")
+ .withField(StandardField.ISSUE, "3")
+ .withField(StandardField.YEAR, "2021")
+ .withCitationKey("Garcia_2021");
+
+ BibEntry entry2 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Smith, John and Johnson, Emily")
+ .withField(StandardField.JOURNAL, "Journal of Computer Science")
+ .withField(StandardField.NUMBER, "4")
+ .withField(StandardField.PAGES, "101--120")
+ .withField(StandardField.TITLE, "A Study on Machine Learning Algorithms")
+ .withField(StandardField.VOLUME, "15")
+ .withField(StandardField.ISSUE, "2")
+ .withField(StandardField.YEAR, "2020")
+ .withCitationKey("Smith_2020");
+
+ List entries = List.of(entry1, entry2);
+ BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(entries));
+ context.setMode(BibDatabaseMode.BIBLATEX);
+ Citation citation = CitationStyleGenerator.generateInText(entries, style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager);
+ String inTextCitationText = citation.getText();
+ String actual = CSLFormatUtils.transformHTML(inTextCitationText);
+ assertEquals(expected, actual);
+ }
+
+ static Stream rawCitationWithMultipleEntriesProvider() {
+ return Stream.of(
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ "(Garcia & Lee, 2021; Smith & Johnson, 2020)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ "[1], [2]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ "[1, 2]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ "(Garcia and Lee 2021; Smith and Johnson 2020)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ "(1,2)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ "1,2"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ "1,2"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ "(Garcia, Lee, 2021; Smith, Johnson, 2020)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ "(Garcia & Lee; Smith & Johnson)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ "Garcia, M. and D. Lee, 2021 ; Smith, J. and E. Johnson, 2020."
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ "[1, 2]"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ "(1,2)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ "1,2"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ "1,2"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ "1,2)"
+ ),
+
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ "1,2"
+ )
+ );
+ }
+
+ /**
+ * Test for modifying the number (index) of a numeric citation.
+ * The numeric index should change to the provided "current number".
+ * The rest of the citation should stay as it is (other numbers in the body shouldn't be affected).
+ *
+ * Precondition 1: This test assumes that {@link CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} works as expected.
+ * Precondition 2: This test assumes that the method {@link CSLFormatUtils#transformHTML(String) transformHTML} works as expected.
+ * Precondition 3: Only run this test on numeric Citation Styles.
+ *
+ * @param style the numeric style to test updation on
+ */
+ @ParameterizedTest
+ @MethodSource("rawNumericCitationProvider")
+ void updateSingleNumericCitation(CitationStyle style, String expected) {
+ String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager).getFirst();
+ String transformedCitation = CSLFormatUtils.transformHTML(citation);
+ String actual = CSLFormatUtils.updateSingleBibliographyNumber(transformedCitation, 3);
+ assertEquals(expected, actual);
+ }
+
+ static Stream rawNumericCitationProvider() {
+ return Stream.of(
+ // Type: "[1]"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Type: "1."
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
+ " \n"
+ ),
+
+ // Type:"1."
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 3. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
+ " \n"
+ ),
+
+ // Type: "1"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Type: "(1)"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
+ " \n"
+ ),
+
+ // Type: "1)"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ " \n" +
+ " 3) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
+ " \n"
+ ),
+
+ // Type: "1"
+ Arguments.of(
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ " 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
+ )
+ );
+ }
+
+ /**
+ * Tests if a citation (LaTeX "\cite") is converted into an in-text citation (LaTeX "\citet") as expected.
+ */
+ @ParameterizedTest
+ @MethodSource("provideCitations")
+ void testChangeToInText(String input, String expected) {
+ String actual = CSLFormatUtils.changeToInText(input);
+ assertEquals(expected, actual);
+ }
+
+ private static Stream provideCitations() {
+ return Stream.of(
+
+ // APA Style
+ Arguments.of("(Smith, 2020)", "Smith (2020)"),
+ Arguments.of("(Johnson & Brown, 2018)", "Johnson & Brown (2018)"),
+ Arguments.of("(Williams et al., 2019)", "Williams et al. (2019)"),
+
+ // MLA Style
+ Arguments.of("(Smith 20)", "(Smith 20)"),
+ Arguments.of("(Johnson and Brown 18)", "(Johnson and Brown 18)"),
+ Arguments.of("(Williams et al. 19)", "(Williams et al. 19)"),
+
+ // Chicago Style (Author-Date)
+ Arguments.of("(Smith 2020)", "(Smith 2020)"),
+ Arguments.of("(Johnson and Brown 2018)", "(Johnson and Brown 2018)"),
+ Arguments.of("(Williams et al. 2019)", "(Williams et al. 2019)"),
+
+ // Harvard Style
+ Arguments.of("(Smith, 2020)", "Smith (2020)"),
+ Arguments.of("(Johnson and Brown, 2018)", "Johnson and Brown (2018)"),
+ Arguments.of("(Williams et al., 2019)", "Williams et al. (2019)"),
+
+ // IEEE Style
+ Arguments.of("[1]", "[1]"),
+ Arguments.of("[2], [3]", "[2], [3]"),
+
+ // Vancouver Style
+ Arguments.of("(1)", "(1)"),
+ Arguments.of("(1,2)", "(1,2)", "Vancouver"),
+
+ // Nature Style
+ Arguments.of("1", "1", "Nature"),
+ Arguments.of("1,2", "1,2", "Nature"),
+
+ // AMA Style
+ Arguments.of("1", "1", "AMA"),
+ Arguments.of("1,2", "1,2", "AMA")
+
+ );
+ }
+
+ /**
+ * Test for proper generation of alphanumeric citations (currently supported: DIN 1505-2).
+ *
+ * Precondition: This test assumes that the method {@link org.jabref.logic.citationkeypattern.BracketedPattern#authorsAlpha authorsAlpha} works as expected.
+ */
+ @ParameterizedTest
+ @MethodSource("provideBibEntries")
+ void testGenerateAlphanumericCitation(List entries, String expected) {
+ BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(entries));
+ String actual = generateAlphanumericCitation(entries, context);
+ assertEquals(expected, actual);
+ }
+
+ private static Stream provideBibEntries() {
+ BibEntry entry1 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Garcia, Maria")
+ .withField(StandardField.TITLE, "Quantum Entanglement in Superconductors")
+ .withField(StandardField.JOURNAL, "International Review of Physics")
+ .withField(StandardField.VOLUME, "28")
+ .withField(StandardField.NUMBER, "6")
+ .withField(StandardField.PAGES, "789--810")
+ .withField(StandardField.YEAR, "2021")
+ .withCitationKey("Garcia_2021");
+
+ BibEntry entry2 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Smith, John and Johnson, Emily")
+ .withField(StandardField.TITLE, "A Study on Machine Learning Algorithms")
+ .withField(StandardField.JOURNAL, "Journal of Computer Science")
+ .withField(StandardField.VOLUME, "15")
+ .withField(StandardField.NUMBER, "4")
+ .withField(StandardField.PAGES, "101--120")
+ .withField(StandardField.YEAR, "2020")
+ .withCitationKey("Smith_2020");
+
+ BibEntry entry3 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Johnson, Emily; Williams, Jessica; Lee, David")
+ .withField(StandardField.TITLE, "Trends in Artificial Intelligence")
+ .withField(StandardField.JOURNAL, "AI Magazine")
+ .withField(StandardField.VOLUME, "41")
+ .withField(StandardField.NUMBER, "2")
+ .withField(StandardField.PAGES, "45--60")
+ .withField(StandardField.YEAR, "2019")
+ .withCitationKey("Johnson_2019");
+
+ BibEntry entry4 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Smith, John; Johnson, Emily; Lee, David; Williams, Jessica")
+ .withField(StandardField.TITLE, "Big Data Analytics in Healthcare")
+ .withField(StandardField.JOURNAL, "Journal of Medical Informatics")
+ .withField(StandardField.VOLUME, "23")
+ .withField(StandardField.NUMBER, "1")
+ .withField(StandardField.PAGES, "11--25")
+ .withField(StandardField.YEAR, "2018")
+ .withCitationKey("Smith_2018");
+
+ BibEntry entry5 = new BibEntry(StandardEntryType.Article)
+ .withField(StandardField.AUTHOR, "Garcia, Maria; Smith, John; Johnson, Emily; Lee, David; Williams, Jessica")
+ .withField(StandardField.TITLE, "Advances in Renewable Energy Technologies")
+ .withField(StandardField.JOURNAL, "Energy Policy")
+ .withField(StandardField.VOLUME, "52")
+ .withField(StandardField.NUMBER, "3")
+ .withField(StandardField.PAGES, "120--135")
+ .withField(StandardField.YEAR, "2017")
+ .withCitationKey("Garcia_2017");
+
+ return Stream.of(
+ // Entry with single author
+ Arguments.of(List.of(entry1), "[Ga21]"),
+
+ // Entry with two authors
+ Arguments.of(List.of(entry2), "[SJ20]"),
+
+ // Entry with three authors
+ Arguments.of(List.of(entry3), "[JWL19]"),
+
+ // Entry with four authors
+ Arguments.of(List.of(entry4), "[SJLW18]"),
+
+ // Entry with five authors
+ Arguments.of(List.of(entry5), "[GSJL17]"),
+
+ // Multiple entries with varying number of authors
+ Arguments.of(List.of(entry1, entry2, entry3, entry4, entry5), "[Ga21; SJ20; JWL19; SJLW18; GSJL17]")
+
+ );
+ }
+}
From be680d3f36feeabc157d6de06773ba6e35eb0853 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:37:18 +0530
Subject: [PATCH 08/24] Add javadoc for adapter
---
.../logic/openoffice/oocsltext/CSLCitationOOAdapter.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
index ae4b6b2ea15..f5acc9f230d 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
@@ -26,6 +26,11 @@
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.Exception;
+/**
+ * This class processes CSL citations in JabRef and interacts directly with LibreOffice using an XTextDocument instance.
+ * It is tightly coupled with {@link CSLReferenceMarkManager} for management of reference marks tied to the CSL citations.
+ * Any method in this class is NOT supposed to be moved.
+ */
public class CSLCitationOOAdapter {
private final XTextDocument document;
From b9b915f2bd21244e3651dedc6d1e568af0710c66 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:38:46 +0530
Subject: [PATCH 09/24] Fix locales
---
src/main/resources/csl-locales | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index e631a52dcea..242640a0e00 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit e631a52dcea396be20d031b6456e91dba7772224
+Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
From 44773dce8960b2acf045226023fb433426b1a7c0 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:39:19 +0530
Subject: [PATCH 10/24] Fix submodules for styles
---
src/main/resources/csl-styles | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index bf2926b71a9..d9989a28ed4 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
+Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
From c14378259f296ed3d9a41267f5a4f48daae66318 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:46:14 +0530
Subject: [PATCH 11/24] OpenRewrite
---
src/main/resources/csl-locales | 2 +-
src/main/resources/csl-styles | 2 +-
.../java/org/jabref/logic/citationstyle/CitationStyleTest.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index 242640a0e00..e631a52dcea 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
+Subproject commit e631a52dcea396be20d031b6456e91dba7772224
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index d9989a28ed4..bf2926b71a9 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
+Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
index 092ce549ed9..9e2b210a667 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
@@ -50,7 +50,7 @@ void discoverCitationStylesNotNull() {
@ParameterizedTest
@MethodSource("citationStyleProvider")
- void testParseStyleInfo(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
+ void parseStyleInfo(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
assertTrue(citationStyle.isPresent(), "Citation style should be present for " + cslFileName);
From 168ac647b3d3fe1d7a9822027330f46a794ad0b0 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:46:48 +0530
Subject: [PATCH 12/24] Fix submodules for styles
---
src/main/resources/csl-styles | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index bf2926b71a9..d9989a28ed4 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
+Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
From 9848d78d531be28c9d25ea79eebe8be4aef95cec Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:47:04 +0530
Subject: [PATCH 13/24] Fix locales
---
src/main/resources/csl-locales | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index e631a52dcea..242640a0e00 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit e631a52dcea396be20d031b6456e91dba7772224
+Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
From cc24c9808faffd6dd8cac670d4d6d626ef6a786a Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 19:52:48 +0530
Subject: [PATCH 14/24] Rename test method
---
src/main/resources/csl-locales | 2 +-
src/main/resources/csl-styles | 2 +-
.../java/org/jabref/logic/citationstyle/CitationStyleTest.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index 242640a0e00..e631a52dcea 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
+Subproject commit e631a52dcea396be20d031b6456e91dba7772224
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index d9989a28ed4..bf2926b71a9 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
+Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
index 9e2b210a667..2988ac6b6bf 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
@@ -50,7 +50,7 @@ void discoverCitationStylesNotNull() {
@ParameterizedTest
@MethodSource("citationStyleProvider")
- void parseStyleInfo(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
+ void parseStyleInfoTest(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
assertTrue(citationStyle.isPresent(), "Citation style should be present for " + cslFileName);
From 8d81fbbceebb675e19996291858ddf63a2c88bdc Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 20:46:55 +0530
Subject: [PATCH 15/24] Change order of methods in mark manager
---
.../oocsltext/CSLReferenceMarkManager.java | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java
index 027b6662c23..42440572166 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java
@@ -43,6 +43,21 @@ public CSLReferenceMarkManager(XTextDocument document) {
this.citationKeyToNumber = new HashMap<>();
}
+ public CSLReferenceMark createReferenceMark(BibEntry entry) throws Exception {
+ String citationKey = entry.getCitationKey().orElse(CUID.randomCUID2(8).toString());
+ int citationNumber = getCitationNumber(citationKey);
+ CSLReferenceMark referenceMark = CSLReferenceMark.of(citationKey, citationNumber, factory);
+ addMark(referenceMark);
+ return referenceMark;
+ }
+
+ public void addMark(CSLReferenceMark mark) {
+ marksByName.put(mark.getName(), mark);
+ idsByMark.put(mark, marksByID.size());
+ marksByID.add(mark);
+ updateCitationInfo(mark.getName());
+ }
+
public void readExistingMarks() throws WrappedTargetException, NoSuchElementException {
XReferenceMarksSupplier supplier = UnoRuntime.queryInterface(XReferenceMarksSupplier.class, document);
XNameAccess marks = supplier.getReferenceMarks();
@@ -72,26 +87,11 @@ private void updateCitationInfo(String name) {
}
}
- public void addMark(CSLReferenceMark mark) {
- marksByName.put(mark.getName(), mark);
- idsByMark.put(mark, marksByID.size());
- marksByID.add(mark);
- updateCitationInfo(mark.getName());
+ public boolean hasCitationForKey(String citationKey) {
+ return citationKeyToNumber.containsKey(citationKey);
}
public int getCitationNumber(String citationKey) {
return citationKeyToNumber.computeIfAbsent(citationKey, k -> ++highestCitationNumber);
}
-
- public CSLReferenceMark createReferenceMark(BibEntry entry) throws Exception {
- String citationKey = entry.getCitationKey().orElse(CUID.randomCUID2(8).toString());
- int citationNumber = getCitationNumber(citationKey);
- CSLReferenceMark referenceMark = CSLReferenceMark.of(citationKey, citationNumber, factory);
- addMark(referenceMark);
- return referenceMark;
- }
-
- public boolean hasCitationForKey(String citationKey) {
- return citationKeyToNumber.containsKey(citationKey);
- }
}
From dd56e89e17d9f18f3c8b673c94fb599460de4ca3 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 21:35:59 +0530
Subject: [PATCH 16/24] Fix submodules for styles
---
src/main/resources/csl-styles | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles
index bf2926b71a9..d9989a28ed4 160000
--- a/src/main/resources/csl-styles
+++ b/src/main/resources/csl-styles
@@ -1 +1 @@
-Subproject commit bf2926b71a969644ce735760977d1246aed1f2e2
+Subproject commit d9989a28ed474d87dbb600fc233fb37e773b59a8
From 584056413bf512d0242fd2ddfed44863a4c44b79 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 21:36:07 +0530
Subject: [PATCH 17/24] Fix locales
---
src/main/resources/csl-locales | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/csl-locales b/src/main/resources/csl-locales
index e631a52dcea..242640a0e00 160000
--- a/src/main/resources/csl-locales
+++ b/src/main/resources/csl-locales
@@ -1 +1 @@
-Subproject commit e631a52dcea396be20d031b6456e91dba7772224
+Subproject commit 242640a0e00972f48c417530f9c2b9518504c0b6
From cd2539c3aa734ab8459d5800418a53532b4245ef Mon Sep 17 00:00:00 2001
From: subhramit
Date: Fri, 16 Aug 2024 23:59:20 +0530
Subject: [PATCH 18/24] Disable test
---
.../CitationStyleGeneratorTest.java | 26 +++++++++++--------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index 250f5a884e1..76896069b88 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -1,5 +1,6 @@
package org.jabref.logic.citationstyle;
+import java.io.IOException;
import java.util.List;
import java.util.stream.Stream;
@@ -13,6 +14,8 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
+import de.undercouch.citeproc.output.Citation;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -61,17 +64,18 @@ void aPACitation() {
* The below test, as of now, fails due to citeproc-java returning an empty citation.
* Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
*/
-// @Test
-// void din1502AlphanumericInTextCitation() throws IOException {
-// context.setMode(BibDatabaseMode.BIBLATEX);
-// CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().orElse(null);
-// Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager);
-// String inTextCitationText = citation.getText();
-//
-// String expected = "[Smit2016]";
-//
-// assertEquals(expected, inTextCitationText);
-// }
+ @Test
+ @Disabled
+ void din1502AlphanumericInTextCitation() throws IOException {
+ context.setMode(BibDatabaseMode.BIBLATEX);
+ CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().orElse(null);
+ Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager);
+ String inTextCitationText = citation.getText();
+
+ String expected = "[Smit2016]";
+
+ assertEquals(expected, inTextCitationText);
+ }
@Test
void ignoreNewLine() {
From 4b2593278f945f2918642354caa68b66e57e55e5 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Tue, 20 Aug 2024 13:19:31 +0530
Subject: [PATCH 19/24] Review actions - I
---
.../logic/citationstyle/CitationStyle.java | 4 +-
.../oocsltext/CSLCitationOOAdapter.java | 5 +-
.../openoffice/oocsltext/CSLFormatUtils.java | 3 +-
.../CitationStyleGeneratorTest.java | 8 +-
.../oocsltext/CSLFormatUtilsTest.java | 115 +++++++++---------
5 files changed, 71 insertions(+), 64 deletions(-)
diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
index 5d3c41a56b9..2da81dd1d54 100644
--- a/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
+++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
@@ -26,6 +26,7 @@
import org.jabref.logic.openoffice.style.OOStyle;
import org.jabref.logic.util.StandardFileType;
+import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -76,7 +77,8 @@ private static Optional createCitationStyleFromSource(final Input
public record StyleInfo(String title, boolean isNumericStyle) {
}
- public static Optional parseStyleInfo(String filename, String content) {
+ @VisibleForTesting
+ static Optional parseStyleInfo(String filename, String content) {
FACTORY.setProperty(XMLInputFactory.IS_COALESCING, true);
try {
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
index bda82d00a8d..11b2f9d0053 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
@@ -180,11 +180,12 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
}
/**
- * It is difficult to "segment" a single citation generated for a group of entries into distinct parts based on the entries such that each entry can be draped with its corresponding reference mark.
+ * Inserts multiple references and also adds a space before the citation if not already present ("smart space").
+ *
+ * @implNote It is difficult to "segment" a single citation generated for a group of entries into distinct parts based on the entries such that each entry can be draped with its corresponding reference mark.
* This is because of the sheer variety in the styles of citations and the separators between them (when grouped) in case of Citation Style Language.
* Furthermore, it is also difficult to generate a "single" reference mark for a group of entries.
* Thus, in case of citations for a group of entries, we first insert the citation (text), then insert the invisible reference marks for each entry separately after it.
- * Implements "smart spaces" - adds a space before the citation if not already present.
*/
private void insertMultipleReferenceMarks(XTextCursor cursor, List entries, OOText ooText)
throws CreationException, Exception {
diff --git a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
index 9e13a2e9927..0666a411cf7 100644
--- a/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
+++ b/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtils.java
@@ -20,7 +20,7 @@
import org.apache.commons.text.StringEscapeUtils;
/**
- * Contains utility constants and methods for processing of CSL citations as generated by methods of citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator}).
+ * Contains utility constants and methods for processing of CSL citations as generated by methods of citeproc-java ({@link org.jabref.logic.citationstyle.CitationStyleGenerator}).
* These methods are used in {@link CSLCitationOOAdapter} which inserts CSL citation text into an OO document.
*/
public class CSLFormatUtils {
@@ -28,6 +28,7 @@ public class CSLFormatUtils {
// TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
public static final String DEFAULT_BIBLIOGRAPHY_TITLE = "References";
public static final String DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
+
public static final CitationStyleOutputFormat OUTPUT_FORMAT = CitationStyleOutputFormat.HTML;
private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index 76896069b88..c113d0368cb 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -33,7 +33,7 @@ class CitationStyleGeneratorTest {
@Test
void aCMCitation() {
context.setMode(BibDatabaseMode.BIBLATEX);
- CitationStyle style = styleList.stream().filter(e -> "ACM SIGGRAPH".equals(e.getTitle())).findAny().orElse(null);
+ CitationStyle style = styleList.stream().filter(e -> "ACM SIGGRAPH".equals(e.getTitle())).findAny().get();
String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager).getFirst();
// if the acm-siggraph.csl citation style changes this has to be modified
@@ -48,7 +48,7 @@ void aCMCitation() {
@Test
void aPACitation() {
context.setMode(BibDatabaseMode.BIBLATEX);
- CitationStyle style = styleList.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null);
+ CitationStyle style = styleList.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get();
String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager).getFirst();
// if the apa-7th-citation.csl citation style changes this has to be modified
@@ -61,14 +61,14 @@ void aPACitation() {
}
/**
- * The below test, as of now, fails due to citeproc-java returning an empty citation.
+ * Fails due to citeproc-java returning an empty citation.
* Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
*/
@Test
@Disabled
void din1502AlphanumericInTextCitation() throws IOException {
context.setMode(BibDatabaseMode.BIBLATEX);
- CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().orElse(null);
+ CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().get();
Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager);
String inTextCitationText = citation.getText();
diff --git a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
index f65fe1f0c18..bd56bcc2bc7 100644
--- a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
+++ b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
@@ -47,6 +47,7 @@ void ooHTMLTransformFromRawHTML(String input, String expected) {
static Stream rawHTMLProvider() {
return Stream.of(
+
// First three are general test cases for unescaping HTML entities
// Ampersand (& entity)
@@ -160,13 +161,13 @@ static Stream rawBibliographyProvider() {
// Non-numeric, parentheses, commas, full stops, slashes, hyphens, colons, italics
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
" Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb\n"
),
// Numeric type "[1]", brackets, newlines
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
" \n" +
" [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
" \n"
@@ -174,34 +175,34 @@ static Stream rawBibliographyProvider() {
// Numeric type "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.\n" +
" \n"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
" Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n"
),
// Semicolons
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef\n" +
" \n"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. BibTeX Journal 34, 45–67 (2016).\n" +
" \n"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. BibTeX Journal. 2016;34(3):45-67. doi:10.1001/bla.blubb\n" +
" \n"
@@ -209,25 +210,25 @@ static Stream rawBibliographyProvider() {
// Small-caps
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
" Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.\n"
),
// Underlines
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
" Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .\n"
),
// Non-breaking spaces
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
" Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.\n"
),
// Numeric with a full stop - "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
" \n"
@@ -235,7 +236,7 @@ static Stream rawBibliographyProvider() {
// Bold text, bold numeric with a full stop - "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
" \n"
@@ -243,7 +244,7 @@ static Stream rawBibliographyProvider() {
// Naked numeric - "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
" \n" +
" 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
" \n"
@@ -251,7 +252,7 @@ static Stream rawBibliographyProvider() {
// Numeric in parentheses - "(1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
" \n" +
" (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
" \n"
@@ -259,7 +260,7 @@ static Stream rawBibliographyProvider() {
// Numeric with right parenthesis - "1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
" \n" +
" 1) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
" \n"
@@ -267,7 +268,7 @@ static Stream rawBibliographyProvider() {
// Numeric in superscript - "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
" 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
)
);
@@ -295,83 +296,83 @@ static Stream rawCitationWithSingleEntryProvider() {
return Stream.of(
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
"(Smith et al., 2016)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
"[1]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
"[1]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
"(Smith, Jones, and Williams 2016)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
"(1)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
"1"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
"1"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
"(Smith, Jones, Williams, 2016)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
"(Smith, Jones, & Williams)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
"Smith, B., B. Jones, and J. Williams, 2016."
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
"[1]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
"(1)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
"1"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
"1"
),
// Note: not sure if the right parenthesis outside the superscript is correct, but that's how citeproc-java generates it in raw form as well.
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
"1)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
"1"
)
);
@@ -422,82 +423,82 @@ void ooHTMLTransformFromCitationWithMultipleEntries(CitationStyle style, String
static Stream rawCitationWithMultipleEntriesProvider() {
return Stream.of(
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
"(Garcia & Lee, 2021; Smith & Johnson, 2020)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
"[1], [2]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
"[1, 2]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
"(Garcia and Lee 2021; Smith and Johnson 2020)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
"(1,2)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
"1,2"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
"1,2"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
"(Garcia, Lee, 2021; Smith, Johnson, 2020)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
"(Garcia & Lee; Smith & Johnson)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
"Garcia, M. and D. Lee, 2021 ; Smith, J. and E. Johnson, 2020."
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
"[1, 2]"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
"(1,2)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
"1,2"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
"1,2"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
"1,2)"
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
"1,2"
)
);
@@ -525,9 +526,10 @@ void updateSingleNumericCitation(CitationStyle style, String expected) {
static Stream rawNumericCitationProvider() {
return Stream.of(
+
// Type: "[1]"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
" \n" +
" [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
" \n"
@@ -535,7 +537,7 @@ static Stream rawNumericCitationProvider() {
// Type: "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
" \n"
@@ -543,7 +545,7 @@ static Stream rawNumericCitationProvider() {
// Type:"1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
" \n" +
" 3. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
" \n"
@@ -551,7 +553,7 @@ static Stream rawNumericCitationProvider() {
// Type: "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
" \n" +
" 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
" \n"
@@ -559,7 +561,7 @@ static Stream rawNumericCitationProvider() {
// Type: "(1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
" \n" +
" (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
" \n"
@@ -567,7 +569,7 @@ static Stream rawNumericCitationProvider() {
// Type: "1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
" \n" +
" 3) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
" \n"
@@ -575,7 +577,7 @@ static Stream rawNumericCitationProvider() {
// Type: "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().orElse(null),
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
" 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
)
);
@@ -586,7 +588,7 @@ static Stream rawNumericCitationProvider() {
*/
@ParameterizedTest
@MethodSource("provideCitations")
- void testChangeToInText(String input, String expected) {
+ void ChangeToInText(String input, String expected) {
String actual = CSLFormatUtils.changeToInText(input);
assertEquals(expected, actual);
}
@@ -698,6 +700,7 @@ private static Stream provideBibEntries() {
.withCitationKey("Garcia_2017");
return Stream.of(
+
// Entry with single author
Arguments.of(List.of(entry1), "[Ga21]"),
From cf51468737e78d683b7e9b8e2bf59d9df34b0030 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Tue, 20 Aug 2024 13:33:37 +0530
Subject: [PATCH 20/24] Better javadoc for disabled test
---
.../jabref/logic/citationstyle/CitationStyleGeneratorTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index c113d0368cb..79fdac853c9 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -61,7 +61,7 @@ void aPACitation() {
}
/**
- * Fails due to citeproc-java returning an empty citation.
+ * Fails due to citeproc-java ({@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText}) returning an empty citation.
* Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
*/
@Test
From 0255611d0eb8700057eb41845c6ec3b5475f6a57 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Tue, 20 Aug 2024 14:41:18 +0530
Subject: [PATCH 21/24] Remove "public" as per best practices
---
.../jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
index bd56bcc2bc7..ea9b0fe1dcb 100644
--- a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
+++ b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
@@ -25,7 +25,7 @@
import static org.jabref.logic.openoffice.oocsltext.CSLFormatUtils.generateAlphanumericCitation;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class CSLFormatUtilsTest {
+class CSLFormatUtilsTest {
private static final List STYLE_LIST = CitationStyle.discoverCitationStyles();
From 3962402a8698bd3f91668e6703ea8f76b8ce29e3 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Wed, 21 Aug 2024 15:09:45 +0530
Subject: [PATCH 22/24] Review changes [3]
---
.../CitationStyleGeneratorTest.java | 4 +-
.../citationstyle/CitationStyleTest.java | 54 ++-
.../oocsltext/CSLFormatUtilsTest.java | 376 +++++++++---------
3 files changed, 225 insertions(+), 209 deletions(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index 79fdac853c9..c3b02bf9c9a 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -72,9 +72,7 @@ void din1502AlphanumericInTextCitation() throws IOException {
Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CitationStyleOutputFormat.HTML, context, bibEntryTypesManager);
String inTextCitationText = citation.getText();
- String expected = "[Smit2016]";
-
- assertEquals(expected, inTextCitationText);
+ assertEquals("[Smit2016]", inTextCitationText);
}
@Test
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
index 2988ac6b6bf..d7a94725879 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
@@ -49,25 +49,55 @@ void discoverCitationStylesNotNull() {
}
@ParameterizedTest
- @MethodSource("citationStyleProvider")
- void parseStyleInfoTest(String cslFileName, String expectedTitle, boolean expectedNumericNature) {
+ @MethodSource
+ void citationStylePresent(String cslFileName) {
Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
+ assertTrue(citationStyle.isPresent());
+ }
- assertTrue(citationStyle.isPresent(), "Citation style should be present for " + cslFileName);
+ static Stream citationStylePresent() {
+ return java.util.stream.Stream.of(
+ Arguments.of("ieee.csl"),
+ Arguments.of("apa.csl"),
+ Arguments.of("vancouver.csl"),
+ Arguments.of("chicago-author-date.csl"),
+ Arguments.of("nature.csl")
+ );
+ }
+ @ParameterizedTest
+ @MethodSource
+ void titleMatches(String cslFileName, String expectedTitle) {
+ Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
CitationStyle.StyleInfo styleInfo = new CitationStyle.StyleInfo(citationStyle.get().getTitle(), citationStyle.get().isNumericStyle());
-
- assertEquals(expectedTitle, styleInfo.title(), "Title should match for " + cslFileName);
- assertEquals(expectedNumericNature, styleInfo.isNumericStyle(), "Numeric style should match for " + cslFileName);
+ assertEquals(expectedTitle, styleInfo.title());
}
- private static Stream citationStyleProvider() {
+ static Stream titleMatches() {
return Stream.of(
- Arguments.of("ieee.csl", "IEEE", true),
- Arguments.of("apa.csl", "American Psychological Association 7th edition", false),
- Arguments.of("vancouver.csl", "Vancouver", true),
- Arguments.of("chicago-author-date.csl", "Chicago Manual of Style 17th edition (author-date)", false),
- Arguments.of("nature.csl", "Nature", true)
+ Arguments.of("ieee.csl", "IEEE"),
+ Arguments.of("apa.csl", "American Psychological Association 7th edition"),
+ Arguments.of("vancouver.csl", "Vancouver"),
+ Arguments.of("chicago-author-date.csl", "Chicago Manual of Style 17th edition (author-date)"),
+ Arguments.of("nature.csl", "Nature")
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ void numericPropertyMatches(String cslFileName, boolean expectedNumericNature) {
+ Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
+ CitationStyle.StyleInfo styleInfo = new CitationStyle.StyleInfo(citationStyle.get().getTitle(), citationStyle.get().isNumericStyle());
+ assertEquals(expectedNumericNature, styleInfo.isNumericStyle());
+ }
+
+ private static Stream numericPropertyMatches() {
+ return java.util.stream.Stream.of(
+ Arguments.of("ieee.csl", true),
+ Arguments.of("apa.csl", false),
+ Arguments.of("vancouver.csl", true),
+ Arguments.of("chicago-author-date.csl", false),
+ Arguments.of("nature.csl", true)
);
}
}
diff --git a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
index ea9b0fe1dcb..ada5ac67c42 100644
--- a/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
+++ b/src/test/java/org/jabref/logic/openoffice/oocsltext/CSLFormatUtilsTest.java
@@ -35,107 +35,107 @@ class CSLFormatUtilsTest {
/**
* Test to check transformation of raw, unsupported HTML into OO-ready HTML.
- *
- * @param input the raw HTML.
*/
@ParameterizedTest
- @MethodSource("rawHTMLProvider")
- void ooHTMLTransformFromRawHTML(String input, String expected) {
- String actual = CSLFormatUtils.transformHTML(input);
+ @MethodSource
+ void ooHTMLTransformFromRawHTML(String expected, String rawHtml) {
+ String actual = CSLFormatUtils.transformHTML(rawHtml);
assertEquals(expected, actual);
}
- static Stream rawHTMLProvider() {
+ static Stream ooHTMLTransformFromRawHTML() {
return Stream.of(
- // First three are general test cases for unescaping HTML entities
+ // region: general test cases for unescaping HTML entities
// Ampersand (& entity)
Arguments.of(
- "Smith & Jones",
- "Smith & Jones"
+ "Smith & Jones",
+ "Smith & Jones"
),
// Non-breaking space ( entity)
Arguments.of(
- "Text with non-breaking spaces",
- "Text with non-breaking spaces"
+ "Text with non-breaking spaces",
+ "Text with non-breaking spaces"
),
// Bold formatting, less than, greater than symbols (<, > entities)
Arguments.of(
- "<b>Bold Text</b>",
- "Bold Text"
+ "Bold Text",
+ "<b>Bold Text</b>"
),
+ // endregion
+
// Handling margins
Arguments.of(
- "[1]
Citation text
",
- "[1] Citation text"
+ "[1] Citation text",
+ "[1]
Citation text
"
),
// Removing unsupported div tags
Arguments.of(
- "Aligned text
",
- "Aligned text"
+ "Aligned text",
+ "Aligned text
"
),
// Removing unsupported links
Arguments.of(
- "Text with link",
- "Text with link"
+ "Text with link",
+ "Text with link"
),
// Replacing span tags with inline styles for bold
Arguments.of(
- "Text with bold",
- "Text with bold"
+ "Text with bold",
+ "Text with bold"
),
// Replacing span tags with inline styles for italic
Arguments.of(
- "Text with italic",
- "Text with italic"
+ "Text with italic",
+ "Text with italic"
),
// Replacing span tags with inline styles for underline
Arguments.of(
- "Text with underline",
- "Text with underline"
+ "Text with underline",
+ "Text with underline"
),
// Replacing span tags with inline styles for small-caps
Arguments.of(
- "Text with small caps",
- "Text with small caps"
+ "Text with small caps",
+ "Text with small caps"
),
// Test case for cleaning up remaining span tags
Arguments.of(
- "Text with unnecessary span",
- "Text with unnecessary span"
+ "Text with unnecessary span",
+ "Text with unnecessary span"
),
// Test case combining multiple transformations
Arguments.of(
- "[1]
Author, "Title," Journal, vol. 1, no. 1, pp. 1-10, 2023.
",
- "[1] Author, \"Title,\" Journal, vol. 1, no. 1, pp. 1-10, 2023."
+ "[1] Author, \"Title,\" Journal, vol. 1, no. 1, pp. 1-10, 2023.",
+ "[1]
Author, "Title," Journal, vol. 1, no. 1, pp. 1-10, 2023.
"
),
// Comprehensive test
Arguments.of(
+ "[1] Smith & Jones, " +
+ "\"Analysis of in HTML,\" " +
+ "Journal of Web Development, " +
+ "vol. 1, no. 1, pp. 1-10, 2023. " +
+ "https://doi.org/10.1000/example",
+
"[1]
" +
"
Smith & Jones, " +
""
Analysis of <code> in HTML," " +
"
Journal of Web Development, " +
"vol. 1, no. 1, pp. 1-10, 2023. " +
- "
https://doi.org/10.1000/example ",
-
- "[1] Smith & Jones, " +
- "\"Analysis of in HTML,\" " +
- "Journal of Web Development, " +
- "vol. 1, no. 1, pp. 1-10, 2023. " +
- "https://doi.org/10.1000/example"
+ "https://doi.org/10.1000/example "
)
);
}
@@ -145,131 +145,129 @@ static Stream rawHTMLProvider() {
*
* Precondition: This test assumes that {@link CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} works as expected.
*
- *
- * @param style the CSL style to test transformation on.
*/
@ParameterizedTest
- @MethodSource("rawBibliographyProvider")
- void ooHTMLTransformFromRawBibliography(CitationStyle style, String expected) {
+ @MethodSource
+ void ooHTMLTransformFromRawBibliography(String expected, CitationStyle style) {
String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager).getFirst();
String actual = CSLFormatUtils.transformHTML(citation);
assertEquals(expected, actual);
}
- static Stream rawBibliographyProvider() {
+ static Stream ooHTMLTransformFromRawBibliography() {
return Stream.of(
// Non-numeric, parentheses, commas, full stops, slashes, hyphens, colons, italics
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
- " Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb\n"
+ " Smith, B., Jones, B., & Williams, J. (2016). Title of the test entry. BibTeX Journal, 34(3), 45–67. https://doi.org/10.1001/bla.blubb\n",
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get()
),
// Numeric type "[1]", brackets, newlines
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
" \n" +
" [1] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),
// Numeric type "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B., Williams, J.: Title of the test entry. BibTeX Journal. 34, 45–67 (2016). https://doi.org/10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
- " Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n"
+ " Smith, Bill, Bob Jones, and Jeff Williams. 2016. “Title of the Test Entry.” Edited by Phil Taylor. BibTeX Journal 34 (3): 45–67. https://doi.org/10.1001/bla.blubb.\n",
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get()
),
// Semicolons
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, editor. BibTeX Journal [Internet]. 2016 Jul;34(3):45–67. Available from: https://github.com/JabRef\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B. & Williams, J. Title of the test entry. BibTeX Journal 34, 45–67 (2016).\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. Taylor P, ed. BibTeX Journal. 2016;34(3):45-67. doi:10.1001/bla.blubb\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get()
),
// Small-caps
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
- " Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.\n"
+ " Smith, B., Jones, B., Williams, J. (2016) Title of the test entry Taylor, P. (ed.). BibTeX Journal, 34(3), pp. 45–67.\n",
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get()
),
// Underlines
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
- " Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .\n"
+ " Smith, Bill, Bob Jones, and Jeff Williams. “Title of the test entry.” Ed. Phil Taylor. BibTeX Journal 34.3 (2016): 45–67. .\n",
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get()
),
// Non-breaking spaces
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
- " Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.\n"
+ " Smith, Bill, Bob Jones, & Jeff Williams, “Title of the test entry,” BibTeX Journal, 2016, vol. 34, no. 3, pp. 45–67.\n",
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get()
),
// Numeric with a full stop - "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),
// Bold text, bold numeric with a full stop - "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
" \n" +
" 1. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),
// Naked numeric - "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
" \n" +
" 1 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),
// Numeric in parentheses - "(1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
" \n" +
" (1) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),
// Numeric with right parenthesis - "1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
" \n" +
" 1) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),
// Numeric in superscript - "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
- " 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
+ " 1 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n",
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
}
@@ -279,12 +277,10 @@ static Stream rawBibliographyProvider() {
*
* Precondition: This test assumes that {@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} works as expected.
*
- *
- * @param style the CSL style to test transformation on.
*/
@ParameterizedTest
- @MethodSource("rawCitationWithSingleEntryProvider")
- void ooHTMLTransformFromCitationWithSingleEntry(CitationStyle style, String expected) throws IOException {
+ @MethodSource
+ void ooHTMLTransformFromCitationWithSingleEntry(String expected, CitationStyle style) throws IOException {
Citation citation = CitationStyleGenerator.generateInText(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager);
String inTextCitationText = citation.getText();
String actual = CSLFormatUtils.transformHTML(inTextCitationText);
@@ -292,88 +288,88 @@ void ooHTMLTransformFromCitationWithSingleEntry(CitationStyle style, String expe
assertEquals(OOText.fromString(expected), ooText);
}
- static Stream rawCitationWithSingleEntryProvider() {
+ static Stream ooHTMLTransformFromCitationWithSingleEntry() {
return Stream.of(
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
- "(Smith et al., 2016)"
+ "(Smith et al., 2016)",
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
- "[1]"
+ "[1]",
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
- "[1]"
+ "[1]",
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
- "(Smith, Jones, and Williams 2016)"
+ "(Smith, Jones, and Williams 2016)",
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
- "(1)"
+ "(1)",
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
- "1"
+ "1",
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
- "1"
+ "1",
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
- "(Smith, Jones, Williams, 2016)"
+ "(Smith, Jones, Williams, 2016)",
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
- "(Smith, Jones, & Williams)"
+ "(Smith, Jones, & Williams)",
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
- "Smith, B., B. Jones, and J. Williams, 2016."
+ "Smith, B., B. Jones, and J. Williams, 2016.",
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
- "[1]"
+ "[1]",
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
- "(1)"
+ "(1)",
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
- "1"
+ "1",
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
- "1"
+ "1",
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),
// Note: not sure if the right parenthesis outside the superscript is correct, but that's how citeproc-java generates it in raw form as well.
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
- "1)"
+ "1)",
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
- "1"
+ "1",
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
}
@@ -383,12 +379,10 @@ static Stream rawCitationWithSingleEntryProvider() {
*
* Precondition: This test assumes that {@link CitationStyleGenerator#generateInText(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateInText} works as expected.
*
- *
- * @param style the CSL style to test transformation on.
*/
@ParameterizedTest
- @MethodSource("rawCitationWithMultipleEntriesProvider")
- void ooHTMLTransformFromCitationWithMultipleEntries(CitationStyle style, String expected) throws IOException {
+ @MethodSource
+ void ooHTMLTransformFromCitationWithMultipleEntries(String expected, CitationStyle style) throws IOException {
BibEntry entry1 = new BibEntry(StandardEntryType.Article)
.withField(StandardField.AUTHOR, "Garcia, Maria and Lee, David")
.withField(StandardField.JOURNAL, "International Review of Physics")
@@ -420,86 +414,86 @@ void ooHTMLTransformFromCitationWithMultipleEntries(CitationStyle style, String
assertEquals(expected, actual);
}
- static Stream rawCitationWithMultipleEntriesProvider() {
+ static Stream ooHTMLTransformFromCitationWithMultipleEntries() {
return Stream.of(
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get(),
- "(Garcia & Lee, 2021; Smith & Johnson, 2020)"
+ "(Garcia & Lee, 2021; Smith & Johnson, 2020)",
+ STYLE_LIST.stream().filter(e -> "American Psychological Association 7th edition".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
- "[1], [2]"
+ "[1], [2]",
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get(),
- "[1, 2]"
+ "[1, 2]",
+ STYLE_LIST.stream().filter(e -> "Springer - Lecture Notes in Computer Science".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get(),
- "(Garcia and Lee 2021; Smith and Johnson 2020)"
+ "(Garcia and Lee 2021; Smith and Johnson 2020)",
+ STYLE_LIST.stream().filter(e -> "Chicago Manual of Style 17th edition (author-date)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get(),
- "(1,2)"
+ "(1,2)",
+ STYLE_LIST.stream().filter(e -> "Vancouver".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get(),
- "1,2"
+ "1,2",
+ STYLE_LIST.stream().filter(e -> "Nature".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get(),
- "1,2"
+ "1,2",
+ STYLE_LIST.stream().filter(e -> "American Medical Association 11th edition".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get(),
- "(Garcia, Lee, 2021; Smith, Johnson, 2020)"
+ "(Garcia, Lee, 2021; Smith, Johnson, 2020)",
+ STYLE_LIST.stream().filter(e -> "De Montfort University - Harvard".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get(),
- "(Garcia & Lee; Smith & Johnson)"
+ "(Garcia & Lee; Smith & Johnson)",
+ STYLE_LIST.stream().filter(e -> "Modern Language Association 7th edition (underline)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get(),
- "Garcia, M. and D. Lee, 2021 ; Smith, J. and E. Johnson, 2020."
+ "Garcia, M. and D. Lee, 2021 ; Smith, J. and E. Johnson, 2020.",
+ STYLE_LIST.stream().filter(e -> "Histoire & Mesure (Français)".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
- "[1, 2]"
+ "[1, 2]",
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
- "(1,2)"
+ "(1,2)",
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
- "1,2"
+ "1,2",
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
- "1,2"
+ "1,2",
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
- "1,2)"
+ "1,2)",
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
- "1,2"
+ "1,2",
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
}
@@ -511,74 +505,72 @@ static Stream rawCitationWithMultipleEntriesProvider() {
*
* Precondition 1: This test assumes that {@link CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} works as expected.
* Precondition 2: This test assumes that the method {@link CSLFormatUtils#transformHTML(String) transformHTML} works as expected.
- * Precondition 3: Only run this test on numeric Citation Styles.
- *
- * @param style the numeric style to test updation on
+ * Precondition 3: Run this test ONLY on numeric Citation Styles.
*/
@ParameterizedTest
- @MethodSource("rawNumericCitationProvider")
- void updateSingleNumericCitation(CitationStyle style, String expected) {
+ @MethodSource
+ void updateSingleNumericCitation(String expected, CitationStyle style) {
String citation = CitationStyleGenerator.generateCitation(List.of(testEntry), style.getSource(), CSLFormatUtils.OUTPUT_FORMAT, context, bibEntryTypesManager).getFirst();
String transformedCitation = CSLFormatUtils.transformHTML(citation);
String actual = CSLFormatUtils.updateSingleBibliographyNumber(transformedCitation, 3);
assertEquals(expected, actual);
}
- static Stream rawNumericCitationProvider() {
+ static Stream updateSingleNumericCitation() {
return Stream.of(
// Type: "[1]"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get(),
" \n" +
" [3] B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016, doi: 10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "IEEE".equals(e.getTitle())).findAny().get()
),
// Type: "1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get(),
" \n" +
" 3. Smith, B., Jones, B. and Williams, J. 2016. Title of the test entry. BibTeX Journal. 34: 45–67.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "The Journal of Veterinary Medical Science".equals(e.getTitle())).findAny().get()
),
// Type:"1."
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get(),
" \n" +
" 3. Smith B, Jones B, Williams J. Title of the test entry. BibTeX Journal 2016 ; 34 : 45–67.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Acta Orthopædica Belgica".equals(e.getTitle())).findAny().get()
),
// Type: "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get(),
" \n" +
" 3 Smith Bill, Jones Bob, Williams Jeff. Title of the test entry. BibTeX Journal 2016;34(3):45–67. Doi: 10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Acta Anaesthesiologica Taiwanica".equals(e.getTitle())).findAny().get()
),
// Type: "(1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get(),
" \n" +
" (3) Smith, B.; Jones, B.; Williams, J. Title of the Test Entry. BibTeX Journal 2016, 34 (3), 45–67. https://doi.org/10.1001/bla.blubb.\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "American Chemical Society".equals(e.getTitle())).findAny().get()
),
// Type: "1)"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get(),
" \n" +
" 3) Smith B., Jones B., Williams J., BibTeX Journal, 34, 45–67 (2016).\n" +
- " \n"
+ " \n",
+ STYLE_LIST.stream().filter(e -> "Chemical and Pharmaceutical Bulletin".equals(e.getTitle())).findAny().get()
),
// Type: "1"
Arguments.of(
- STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get(),
- " 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n"
+ " 3 B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal 34(3), 45–67 (2016).\n",
+ STYLE_LIST.stream().filter(e -> "American Institute of Physics 4th edition".equals(e.getTitle())).findAny().get()
)
);
}
@@ -587,19 +579,19 @@ static Stream rawNumericCitationProvider() {
* Tests if a citation (LaTeX "\cite") is converted into an in-text citation (LaTeX "\citet") as expected.
*/
@ParameterizedTest
- @MethodSource("provideCitations")
- void ChangeToInText(String input, String expected) {
+ @MethodSource
+ void ChangeToInText(String expected, String input) {
String actual = CSLFormatUtils.changeToInText(input);
assertEquals(expected, actual);
}
- private static Stream provideCitations() {
+ private static Stream ChangeToInText() {
return Stream.of(
// APA Style
- Arguments.of("(Smith, 2020)", "Smith (2020)"),
- Arguments.of("(Johnson & Brown, 2018)", "Johnson & Brown (2018)"),
- Arguments.of("(Williams et al., 2019)", "Williams et al. (2019)"),
+ Arguments.of("Smith (2020)", "(Smith, 2020)"),
+ Arguments.of("Johnson & Brown (2018)", "(Johnson & Brown, 2018)"),
+ Arguments.of("Williams et al. (2019)", "(Williams et al., 2019)"),
// MLA Style
Arguments.of("(Smith 20)", "(Smith 20)"),
@@ -612,9 +604,9 @@ private static Stream provideCitations() {
Arguments.of("(Williams et al. 2019)", "(Williams et al. 2019)"),
// Harvard Style
- Arguments.of("(Smith, 2020)", "Smith (2020)"),
- Arguments.of("(Johnson and Brown, 2018)", "Johnson and Brown (2018)"),
- Arguments.of("(Williams et al., 2019)", "Williams et al. (2019)"),
+ Arguments.of("Smith (2020)", "(Smith, 2020)"),
+ Arguments.of("Johnson and Brown (2018)", "(Johnson and Brown, 2018)"),
+ Arguments.of("Williams et al. (2019)", "(Williams et al., 2019)"),
// IEEE Style
Arguments.of("[1]", "[1]"),
@@ -622,15 +614,11 @@ private static Stream provideCitations() {
// Vancouver Style
Arguments.of("(1)", "(1)"),
- Arguments.of("(1,2)", "(1,2)", "Vancouver"),
+ Arguments.of("(1,2)", "(1,2)"),
// Nature Style
- Arguments.of("1", "1", "Nature"),
- Arguments.of("1,2", "1,2", "Nature"),
-
- // AMA Style
- Arguments.of("1", "1", "AMA"),
- Arguments.of("1,2", "1,2", "AMA")
+ Arguments.of("1", "1"),
+ Arguments.of("1,2", "1,2")
);
}
@@ -641,14 +629,14 @@ private static Stream provideCitations() {
* Precondition: This test assumes that the method {@link org.jabref.logic.citationkeypattern.BracketedPattern#authorsAlpha authorsAlpha} works as expected.
*/
@ParameterizedTest
- @MethodSource("provideBibEntries")
- void testGenerateAlphanumericCitation(List entries, String expected) {
+ @MethodSource
+ void generateAlphanumericCitationTest(String expected, List entries) {
BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(entries));
String actual = generateAlphanumericCitation(entries, context);
assertEquals(expected, actual);
}
- private static Stream provideBibEntries() {
+ private static Stream generateAlphanumericCitationTest() {
BibEntry entry1 = new BibEntry(StandardEntryType.Article)
.withField(StandardField.AUTHOR, "Garcia, Maria")
.withField(StandardField.TITLE, "Quantum Entanglement in Superconductors")
@@ -702,22 +690,22 @@ private static Stream provideBibEntries() {
return Stream.of(
// Entry with single author
- Arguments.of(List.of(entry1), "[Ga21]"),
+ Arguments.of("[Ga21]", List.of(entry1)),
// Entry with two authors
- Arguments.of(List.of(entry2), "[SJ20]"),
+ Arguments.of("[SJ20]", List.of(entry2)),
// Entry with three authors
- Arguments.of(List.of(entry3), "[JWL19]"),
+ Arguments.of("[JWL19]", List.of(entry3)),
// Entry with four authors
- Arguments.of(List.of(entry4), "[SJLW18]"),
+ Arguments.of("[SJLW18]", List.of(entry4)),
// Entry with five authors
- Arguments.of(List.of(entry5), "[GSJL17]"),
+ Arguments.of("[GSJL17]", List.of(entry5)),
// Multiple entries with varying number of authors
- Arguments.of(List.of(entry1, entry2, entry3, entry4, entry5), "[Ga21; SJ20; JWL19; SJLW18; GSJL17]")
+ Arguments.of("[Ga21; SJ20; JWL19; SJLW18; GSJL17]", List.of(entry1, entry2, entry3, entry4, entry5))
);
}
From f77c35edd8f5b04b4ed1560d5a5ea9cc488dd93d Mon Sep 17 00:00:00 2001
From: subhramit
Date: Wed, 21 Aug 2024 15:21:06 +0530
Subject: [PATCH 23/24] Swap arguments for CitationStyleTest
---
.../citationstyle/CitationStyleTest.java | 28 +++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
index d7a94725879..8423e534659 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleTest.java
@@ -56,7 +56,7 @@ void citationStylePresent(String cslFileName) {
}
static Stream citationStylePresent() {
- return java.util.stream.Stream.of(
+ return Stream.of(
Arguments.of("ieee.csl"),
Arguments.of("apa.csl"),
Arguments.of("vancouver.csl"),
@@ -67,7 +67,7 @@ static Stream citationStylePresent() {
@ParameterizedTest
@MethodSource
- void titleMatches(String cslFileName, String expectedTitle) {
+ void titleMatches(String expectedTitle, String cslFileName) {
Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
CitationStyle.StyleInfo styleInfo = new CitationStyle.StyleInfo(citationStyle.get().getTitle(), citationStyle.get().isNumericStyle());
assertEquals(expectedTitle, styleInfo.title());
@@ -75,29 +75,29 @@ void titleMatches(String cslFileName, String expectedTitle) {
static Stream titleMatches() {
return Stream.of(
- Arguments.of("ieee.csl", "IEEE"),
- Arguments.of("apa.csl", "American Psychological Association 7th edition"),
- Arguments.of("vancouver.csl", "Vancouver"),
- Arguments.of("chicago-author-date.csl", "Chicago Manual of Style 17th edition (author-date)"),
- Arguments.of("nature.csl", "Nature")
+ Arguments.of("IEEE", "ieee.csl"),
+ Arguments.of("American Psychological Association 7th edition", "apa.csl"),
+ Arguments.of("Vancouver", "vancouver.csl"),
+ Arguments.of("Chicago Manual of Style 17th edition (author-date)", "chicago-author-date.csl"),
+ Arguments.of("Nature", "nature.csl")
);
}
@ParameterizedTest
@MethodSource
- void numericPropertyMatches(String cslFileName, boolean expectedNumericNature) {
+ void numericPropertyMatches(boolean expectedNumericNature, String cslFileName) {
Optional citationStyle = CitationStyle.createCitationStyleFromFile(cslFileName);
CitationStyle.StyleInfo styleInfo = new CitationStyle.StyleInfo(citationStyle.get().getTitle(), citationStyle.get().isNumericStyle());
assertEquals(expectedNumericNature, styleInfo.isNumericStyle());
}
private static Stream numericPropertyMatches() {
- return java.util.stream.Stream.of(
- Arguments.of("ieee.csl", true),
- Arguments.of("apa.csl", false),
- Arguments.of("vancouver.csl", true),
- Arguments.of("chicago-author-date.csl", false),
- Arguments.of("nature.csl", true)
+ return Stream.of(
+ Arguments.of(true, "ieee.csl"),
+ Arguments.of(false, "apa.csl"),
+ Arguments.of(true, "vancouver.csl"),
+ Arguments.of(false, "chicago-author-date.csl"),
+ Arguments.of(true, "nature.csl")
);
}
}
From 2a611deffd61122e720c8f0344b95c7574be8bb8 Mon Sep 17 00:00:00 2001
From: subhramit
Date: Thu, 22 Aug 2024 02:12:09 +0530
Subject: [PATCH 24/24] Add comment to @Disabled
---
.../jabref/logic/citationstyle/CitationStyleGeneratorTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
index c3b02bf9c9a..3ee3a339fc0 100644
--- a/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
+++ b/src/test/java/org/jabref/logic/citationstyle/CitationStyleGeneratorTest.java
@@ -65,7 +65,7 @@ void aPACitation() {
* Alphanumeric citations are thus, currently manually generated by formatting (see {@link org.jabref.logic.openoffice.oocsltext.CSLFormatUtils#generateAlphanumericCitation(List, BibDatabaseContext) generateAlphaNumericCitation}).
*/
@Test
- @Disabled
+ @Disabled("Till alphanumeric citations are supported by citeproc-java")
void din1502AlphanumericInTextCitation() throws IOException {
context.setMode(BibDatabaseMode.BIBLATEX);
CitationStyle style = styleList.stream().filter(e -> "DIN 1505-2 (alphanumeric, Deutsch) - standard superseded by ISO-690".equals(e.getTitle())).findAny().get();