-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added CiteFormatter and BibLatexFormatter for CAYW feature #13704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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("")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
@@ -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(","))); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.