Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions jabref
Submodule jabref added at bbb88c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public MediaType getMediaType() {
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) {
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
String command = queryParams.getCommand();

List<BibEntry> bibEntries = caywEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();
List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return "\\%s{%s}".formatted(command,
bibEntries.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface CAYWFormatter {

MediaType getMediaType();

String format(CAYWQueryParams caywQueryParams, List<CAYWEntry> caywEntries);
String format(CAYWQueryParams caywQueryParams, List<CAYWEntry> cawEntries);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class CiteFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "citep";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
String command = queryParams.getCommand();
if (command == null || command.isBlank()) {
command = "citep"; // default for citep
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'default for citep' is redundant and does not provide any additional information beyond what is clearly visible in the code itself.

}

List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return "\\%s{%s}".formatted(command,
bibEntries.stream()
.map(entry -> entry.getCitationKey().orElse(""))
.collect(Collectors.joining(",")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public FormatterService() {
this.formatters = new HashMap<>();
registerFormatter(new SimpleJsonFormatter());
registerFormatter(new BibLatexFormatter());
registerFormatter(new LatexFormatter());
registerFormatter(new CiteFormatter());
registerFormatter(new nabbingFormatter());
registerFormatter(new MMDFormatter());
registerFormatter(new PandocFormatter());
registerFormatter(new TypstFormatter());
registerFormatter(new SimpleJsonFormatter());
}

public void registerFormatter(CAYWFormatter formatter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class LatexFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "latex";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
String command = Optional.ofNullable(queryParams.getCommand())
.filter(cmd -> !cmd.isBlank())
.orElse("cite");

List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return "\\%s{%s}".formatted(command,
bibEntries.stream()
.map(entry -> entry.getCitationKey().orElse(""))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty string is used as a fallback for missing citation keys, which could lead to invalid LaTeX syntax. Should handle this case more explicitly or throw an exception.

.collect(Collectors.joining(",")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class MMDFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "mmd";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return bibEntries.stream()
.map(entry -> "[@"+ entry.getCitationKey().orElse("") + "]")
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class PandocFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "pandoc";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return bibEntries.stream()
.map(entry -> "[@"+ entry.getCitationKey().orElse("") + "]")
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public MediaType getMediaType() {
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) {
List<SimpleJson> simpleJsons = caywEntries.stream()
.map(caywEntry -> SimpleJson.fromBibEntry(caywEntry.bibEntry()))
.toList();
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
List<SimpleJson> simpleJsons = cawEntries.stream()
.map(caywEntry -> SimpleJson.fromBibEntry(caywEntry.bibEntry()))
.toList();
return gson.toJson(simpleJsons);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class TypstFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "typst";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return bibEntries.stream()
.map(entry -> "@" + entry.getCitationKey().orElse(""))
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jabref.http.server.cayw.format;

import java.util.List;
import java.util.stream.Collectors;

import org.jabref.http.server.cayw.CAYWQueryParams;
import org.jabref.http.server.cayw.gui.CAYWEntry;
import org.jabref.model.entry.BibEntry;

import jakarta.ws.rs.core.MediaType;
import org.jvnet.hk2.annotations.Service;

@Service
public class nabbingFormatter implements CAYWFormatter {

@Override
public String getFormatName() {
return "nabbing";
}

@Override
public MediaType getMediaType() {
return MediaType.TEXT_PLAIN_TYPE;
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> cawEntries) {
String command = queryParams.getCommand();
if (command == null || command.isBlank()) {
command = "citep"; // default for natbib
}

List<BibEntry> bibEntries = cawEntries.stream()
.map(CAYWEntry::bibEntry)
.toList();

return "\\%s{%s}".formatted(command,
bibEntries.stream()
.map(entry -> entry.getCitationKey().orElse(""))
.collect(Collectors.joining(",")));
}
}
Loading