Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Changed

- The CSL preview styles now also support displaying data from cross references entries that are linked via the `crossref` field [#7378](https://github.com/JabRef/jabref/issues/7378)
- We made the Search button in Web Search wider. We also skewed the panel titles to the left [#8397](https://github.com/JabRef/jabref/issues/8397)

### Fixed
Expand All @@ -21,8 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Removed



- We removed the option to copy CSL Citation styles data as `XSL_FO`, `ASCIIDOC`, and `RTF` as these haven not been working since a long time and are no longe rsupported in the external library used for processing the styles [#7378](https://github.com/JabRef/jabref/issues/7378)



Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ public enum StandardActions implements Action {
COPY_CITE_KEY(Localization.lang("Copy \\cite{citation key}"), KeyBinding.COPY_CITE_CITATION_KEY),
COPY_KEY_AND_TITLE(Localization.lang("Copy citation key and title"), KeyBinding.COPY_CITATION_KEY_AND_TITLE),
COPY_KEY_AND_LINK(Localization.lang("Copy citation key and link"), KeyBinding.COPY_CITATION_KEY_AND_LINK),
COPY_CITATION_HTML(Localization.lang("Copy citation") + " (HTML)", KeyBinding.COPY_PREVIEW),
COPY_CITATION_MORE(Localization.lang("Copy citation") + "..."),
COPY_CITATION_TEXT("Text"),
COPY_CITATION_RTF("RTF"),
COPY_CITATION_ASCII_DOC("AsciiDoc"),
COPY_CITATION_XSLFO("XSL-FO"),
COPY_CITATION_HTML(Localization.lang("Copy citation (html)"), KeyBinding.COPY_PREVIEW),
COPY_CITATION_TEXT(Localization.lang("Copy citation (text)")),
COPY_CITATION_PREVIEW(Localization.lang("Copy preview"), KeyBinding.COPY_PREVIEW),
EXPORT_TO_CLIPBOARD(Localization.lang("Export to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD),
EXPORT_SELECTED_TO_CLIPBOARD(Localization.lang("Export selected entries to clipboard"), IconTheme.JabRefIcons.EXPORT_TO_CLIPBOARD),
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,9 @@ private static Menu createCopySubMenu(ActionFactory factory,
// the submenu will behave dependent on what style is currently selected (citation/preview)
PreviewPreferences previewPreferences = preferencesService.getPreviewPreferences();
if (previewPreferences.getSelectedPreviewLayout() instanceof CitationStylePreviewLayout) {
copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)));
Menu copyCitationMenu = factory.createMenu(StandardActions.COPY_CITATION_MORE);
copyCitationMenu.getItems().addAll(
factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)),
factory.createMenuItem(StandardActions.COPY_CITATION_RTF, new CopyCitationAction(CitationStyleOutputFormat.RTF, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)),
factory.createMenuItem(StandardActions.COPY_CITATION_ASCII_DOC, new CopyCitationAction(CitationStyleOutputFormat.ASCII_DOC, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)),
factory.createMenuItem(StandardActions.COPY_CITATION_XSLFO, new CopyCitationAction(CitationStyleOutputFormat.XSL_FO, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)));
copySpecialMenu.getItems().add(copyCitationMenu);
copySpecialMenu.getItems().addAll(
factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)),
factory.createMenuItem(StandardActions.COPY_CITATION_TEXT, new CopyCitationAction(CitationStyleOutputFormat.TEXT, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)));
} else {
copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, taskExecutor, previewPreferences)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.gui.util.BackgroundTask;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void setValues() {

BackgroundTask.wrap(CitationStyle::discoverCitationStyles)
.onSuccess(styles -> styles.stream()
.map(CitationStylePreviewLayout::new)
.map(style-> new CitationStylePreviewLayout(style, Globals.entryTypesManager))
.filter(style -> chosenListProperty.getValue().filtered(item ->
item.getName().equals(style.getName())).isEmpty())
.sorted(Comparator.comparing(PreviewLayout::getName))
Expand Down
46 changes: 2 additions & 44 deletions src/main/java/org/jabref/gui/preview/CopyCitationAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private List<String> generateCitations() throws IOException {
}

if (styleSource != null) {
return CitationStyleGenerator.generateCitations(selectedEntries, styleSource, outputFormat);
return CitationStyleGenerator.generateCitations(selectedEntries, styleSource, outputFormat, stateManager.getActiveDatabase().get(), Globals.entryTypesManager);
} else {
return generateTextBasedPreviewLayoutCitations();
}
Expand Down Expand Up @@ -126,46 +126,6 @@ protected static ClipboardContent processText(List<String> citations) {
return content;
}

/**
* Converts the citations into the RTF format.
*/
protected static ClipboardContent processRtf(List<String> citations) {
String result = "{\\rtf" + OS.NEWLINE +
String.join(CitationStyleOutputFormat.RTF.getLineSeparator(), citations) +
"}";
ClipboardContent content = new ClipboardContent();
content.putString(result);
content.putRtf(result);
return content;
}

/**
* Inserts each citation into a XLSFO body and copies it to the clipboard
*/
protected static ClipboardContent processXslFo(List<String> citations) {
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + OS.NEWLINE +
"<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">" + OS.NEWLINE +
" <fo:layout-master-set>" + OS.NEWLINE +
" <fo:simple-page-master master-name=\"citations\">" + OS.NEWLINE +
" <fo:region-body/>" + OS.NEWLINE +
" </fo:simple-page-master>" + OS.NEWLINE +
" </fo:layout-master-set>" + OS.NEWLINE +
" <fo:page-sequence master-reference=\"citations\">" + OS.NEWLINE +
" <fo:flow flow-name=\"xsl-region-body\">" + OS.NEWLINE + OS.NEWLINE;

result += String.join(CitationStyleOutputFormat.XSL_FO.getLineSeparator(), citations);

result += OS.NEWLINE +
" </fo:flow>" + OS.NEWLINE +
" </fo:page-sequence>" + OS.NEWLINE +
"</fo:root>" + OS.NEWLINE;

ClipboardContent content = new ClipboardContent();
content.putString(result);
content.put(ClipBoardManager.XML, result);
return content;
}

/**
* Inserts each citation into a HTML body and copies it to the clipboard
*/
Expand Down Expand Up @@ -197,9 +157,7 @@ private void setClipBoardContent(List<String> citations) {
ClipboardContent content;
switch (outputFormat) {
case HTML -> content = processHtml(citations);
case RTF -> content = processRtf(citations);
case XSL_FO -> content = processXslFo(citations);
case ASCII_DOC, TEXT -> content = processText(citations);
case TEXT -> content = processText(citations);
default -> {
LOGGER.warn("unknown output format: '" + outputFormat + "', processing it via the default.");
content = processText(citations);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void update() {
ExporterFactory.entryNumber = 1; // Set entry number in case that is included in the preview layout.

BackgroundTask
.wrap(() -> layout.generatePreview(entry.get(), database.getDatabase()))
.wrap(() -> layout.generatePreview(entry.get(), database))
.onRunning(() -> setPreviewText("<i>" + Localization.lang("Processing %0", Localization.lang("Citation Style")) + ": " + layout.getDisplayName() + " ..." + "</i>"))
.onSuccess(this::setPreviewText)
.onFailure(exception -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/bst/BstPreviewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter;
import org.jabref.logic.layout.format.RemoveTilde;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

import org.slf4j.Logger;
Expand Down Expand Up @@ -42,7 +42,7 @@ public BstPreviewLayout(Path path) {
}

@Override
public String generatePreview(BibEntry originalEntry, BibDatabase database) {
public String generatePreview(BibEntry originalEntry, BibDatabaseContext databaseContext) {
if (error != null) {
return error;
}
Expand Down
31 changes: 24 additions & 7 deletions src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.Month;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
Expand Down Expand Up @@ -49,9 +54,10 @@ public class CSLAdapter {
/**
* Creates the bibliography of the provided items. This method needs to run synchronized because the underlying
* CSL engine is not thread-safe.
* @param databaseContext {@link BibDatabaseContext} is used to be able to resolve fields and their aliases
*/
public synchronized List<String> makeBibliography(List<BibEntry> bibEntries, String style, CitationStyleOutputFormat outputFormat) throws IOException, IllegalArgumentException {
dataProvider.setData(bibEntries);
public synchronized List<String> makeBibliography(List<BibEntry> bibEntries, String style, CitationStyleOutputFormat outputFormat, BibDatabaseContext databaseContext, BibEntryTypesManager entryTypesManager) throws IOException, IllegalArgumentException {
dataProvider.setData(bibEntries, databaseContext, entryTypesManager);
initialize(style, outputFormat);
cslInstance.registerCitationItems(dataProvider.getIds());
final Bibliography bibliography = cslInstance.makeBibliography();
Expand Down Expand Up @@ -86,18 +92,26 @@ private void initialize(String newStyle, CitationStyleOutputFormat newFormat) th
private static class JabRefItemDataProvider implements ItemDataProvider {

private final List<BibEntry> data = new ArrayList<>();
private BibDatabaseContext bibDatabaseContext;
private BibEntryTypesManager entryTypesManager;

/**
* Converts the {@link BibEntry} into {@link CSLItemData}.
*/
private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry) {
private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager) {

String citeKey = bibEntry.getCitationKey().orElse("");
BibTeXEntry bibTeXEntry = new BibTeXEntry(new Key(bibEntry.getType().getName()), new Key(citeKey));

// Not every field is already generated into latex free fields
RemoveNewlinesFormatter removeNewlinesFormatter = new RemoveNewlinesFormatter();
for (Field key : bibEntry.getFieldMap().keySet()) {
bibEntry.getField(key)

Optional<BibEntryType> entryType = entryTypesManager.enrich(bibEntry.getType(), bibDatabaseContext.getMode());

Set<Field> fields = entryType.map(BibEntryType::getAllFields).orElse(bibEntry.getFields());

for (Field key : fields) {
bibEntry.getResolvedFieldOrAlias(key, bibDatabaseContext.getDatabase())
.map(removeNewlinesFormatter::format)
.map(LatexToUnicodeAdapter::format)
.ifPresent(value -> {
Expand All @@ -106,21 +120,24 @@ private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry) {
value = bibEntry.getMonth().map(Month::getShortName).orElse(value);
}
bibTeXEntry.addField(new Key(key.getName()), new DigitStringValue(value));

});
}
return BIBTEX_CONVERTER.toItemData(bibTeXEntry);
}

public void setData(List<BibEntry> data) {
public void setData(List<BibEntry> data, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager) {
this.data.clear();
this.data.addAll(data);
this.bibDatabaseContext = bibDatabaseContext;
this.entryTypesManager = entryTypesManager;
}

@Override
public CSLItemData retrieveItem(String id) {
return data.stream()
.filter(entry -> entry.getCitationKey().orElse("").equals(id))
.map(JabRefItemDataProvider::bibEntryToCSLItemData)
.map(entry -> JabRefItemDataProvider.bibEntryToCSLItemData(entry, bibDatabaseContext, entryTypesManager))
.findFirst().orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public class CitationStyleCache {
private PreviewLayout citationStyle;
private final LoadingCache<BibEntry, String> citationStyleCache;

public CitationStyleCache(BibDatabaseContext database) {
public CitationStyleCache(BibDatabaseContext databaseContext) {
citationStyleCache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(new CacheLoader<BibEntry, String>() {
@Override
public String load(BibEntry entry) {
if (citationStyle != null) {
return citationStyle.generatePreview(entry, database.getDatabase());
return citationStyle.generatePreview(entry, databaseContext);
} else {
return "";
}
}
});
database.getDatabase().registerListener(new BibDatabaseEntryListener());
databaseContext.getDatabase().registerListener(new BibDatabaseEntryListener());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.List;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;

import org.jbibtex.TokenMgrException;
import org.slf4j.Logger;
Expand All @@ -24,40 +26,40 @@ private CitationStyleGenerator() {
}

/**
* Generates a Citation based on the given entry and style
* Generates a Citation based on the given entry and style with a default {@link BibDatabaseContext}
*
* @implNote the citation is generated using JavaScript which may take some time, better call it from outside the main Thread
*/
protected static String generateCitation(BibEntry entry, CitationStyle style) {
return generateCitation(entry, style.getSource(), CitationStyleOutputFormat.HTML);
protected static String generateCitation(BibEntry entry, CitationStyle style, BibEntryTypesManager entryTypesManager) {
return generateCitation(entry, style.getSource(), entryTypesManager);
}

/**
* Generates a Citation based on the given entry and style
* Generates a Citation based on the given entry and style with a default {@link BibDatabaseContext}
*
* @implNote the citation is generated using JavaScript which may take some time, better call it from outside the main Thread
*/
protected static String generateCitation(BibEntry entry, String style) {
return generateCitation(entry, style, CitationStyleOutputFormat.HTML);
protected static String generateCitation(BibEntry entry, String style, BibEntryTypesManager entryTypesManager) {
return generateCitation(entry, style, CitationStyleOutputFormat.HTML, new BibDatabaseContext(), entryTypesManager);
}

/**
* Generates a Citation based on the given entry, style, and output format
*
* @implNote the citation is generated using JavaScript which may take some time, better call it from outside the main Thread
*/
public static String generateCitation(BibEntry entry, String style, CitationStyleOutputFormat outputFormat) {
return generateCitations(Collections.singletonList(entry), style, outputFormat).stream().findFirst().orElse("");
public static String generateCitation(BibEntry entry, String style, CitationStyleOutputFormat outputFormat, BibDatabaseContext databaseContext, BibEntryTypesManager entryTypesManager) {
return generateCitations(Collections.singletonList(entry), style, outputFormat, databaseContext, entryTypesManager).stream().findFirst().orElse("");
}

/**
* Generates the citation for multiple entries at once.
*
* @implNote The citations are generated using JavaScript which may take some time, better call it from outside the main thread.
*/
public static List<String> generateCitations(List<BibEntry> bibEntries, String style, CitationStyleOutputFormat outputFormat) {
public static List<String> generateCitations(List<BibEntry> bibEntries, String style, CitationStyleOutputFormat outputFormat, BibDatabaseContext databaseContext, BibEntryTypesManager entryTypesManager) {
try {
return CSL_ADAPTER.makeBibliography(bibEntries, style, outputFormat);
return CSL_ADAPTER.makeBibliography(bibEntries, style, outputFormat, databaseContext, entryTypesManager);
} catch (IllegalArgumentException e) {
LOGGER.error("Could not generate BibEntry citation. The CSL engine could not create a preview for your item.", e);
return Collections.singletonList(Localization.lang("Cannot generate preview based on selected citation style."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

public enum CitationStyleOutputFormat {

ASCII_DOC("asciidoc", ""),
HTML("html", OS.NEWLINE + "<br>" + OS.NEWLINE),
RTF("rtf", "\\line" + OS.NEWLINE),
TEXT("text", ""),
XSL_FO("fo", OS.NEWLINE);
TEXT("text", "");

private final String format;
private final String lineSeparator;
Expand Down
Loading