-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Resources - /libraries - /libraries/{id} (both (embedded) BibTeX as string and CSL data) - Documentation / code style - Refined BibEntry class (JavaDoc, builder) - Comments to InternalField - move StyleTester to "test" module - package ...testutils/interactive... - Makes use of Jersey, Grizzly - Makes use of HK2 as dependency injection framework - Introduces "application/x-bibtex-library-csl+json" mimetype - Preparation for client/server sync (BibEntryDTO) - Minor - Made class "JabRefItemDataProvider" more visible - Encoding of a .bib file can now be asked for externally - Resorts modle-info.java - Fixes typo in NetworkTabViewModel - Installs SLF4J logging router: If a tool uses java commons logging, tinylog now also handles these logs
- Loading branch information
Showing
42 changed files
with
1,257 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
nav_order: 27 | ||
parent: Decision Records | ||
--- | ||
<!-- we need to disable MD025, because we use the different heading "ADR Template" in the homepage (see above) than it is foreseen in the template --> | ||
<!-- markdownlint-disable-next-line MD025 --> | ||
# Return BibTeX string and CSL Item JSON in the API | ||
|
||
## Context and Problem Statement | ||
|
||
In the context of an http server, when a http client `GETs` a JSON data structure containing BibTeX data, which format should that have? | ||
|
||
## Considered Options | ||
|
||
* Offer both, BibTeX string and CSL JSON | ||
* Return BibTeX as is as string | ||
* Convert BibTeX to JSON | ||
|
||
## Decision Outcome | ||
|
||
Chosen option: "Offer both, BibTeX string and CSL JSON", because there are many browser libraries out there being able to parse BibTeX. Thus, we don't need to convert it. | ||
|
||
## Pros and Cons of the Options | ||
|
||
### Offer both, BibTeX string and CSL JSON | ||
|
||
- Good, because this follows "Backend for Frontend" | ||
- Good, because Word Addin works seamless with the data provided (and does not need another dependency) | ||
- Good, because other clients can work with BibTeX data | ||
- Bad, because two serializations have to be kept | ||
|
||
### Return BibTeX as is as string | ||
|
||
- Good, because we don't need to think about any conversion | ||
- Bad, because it is unclear how to ship BibTeX data where the entry is dependent on | ||
- Bad, because client needs add additional parsing logic | ||
|
||
### Convert BibTeX to JSON | ||
|
||
More thought has to be done when converting to JSON. | ||
There seems to be a JSON format from [@citation-js/plugin-bibtex](https://www.npmjs.com/package/@citation-js/plugin-bibtex). | ||
We could do an additional self-made JSON format, but this increases the number of available JSON serializations for BibTeX. | ||
|
||
- Good, because it could flatten BibTeX data (example: `author = first # " and " # second`) | ||
- Bad, because conversion is difficult in BibTeX special cases. For instance, if Strings are used (example: `author = first # " and " # second`) and one doesn't want to flatten ("normalize") this. | ||
|
||
## More Information | ||
|
||
Existing JavaScript BibTeX libraries: | ||
|
||
* [bibtex-js](https://github.com/digitalheir/bibtex-js) | ||
* [bibtexParseJS](https://github.com/ORCID/bibtexParseJs) | ||
* [@citation-js/plugin-bibtex](https://www.npmjs.com/package/@citation-js/plugin-bibtex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.jabref.http; | ||
|
||
public class MediaType { | ||
public static final String BIBTEX = "application/x-bibtex"; | ||
public static final String JSON_CSL_ITEM = "application/x-bibtex-library-csl+json"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.jabref.http.dto; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
|
||
import org.jabref.logic.bibtex.BibEntryWriter; | ||
import org.jabref.logic.bibtex.FieldWriter; | ||
import org.jabref.logic.bibtex.FieldWriterPreferences; | ||
import org.jabref.logic.exporter.BibWriter; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.BibEntryTypesManager; | ||
import org.jabref.model.entry.SharedBibEntryData; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The data transfer object (DTO) for an BibEntry | ||
* | ||
* @param sharingMetadata the data used for sharing | ||
* @param userComments the comments before the BibTeX entry | ||
* @param citationKey the citation key (duplicated from BibEntry to ease processing by the client) | ||
* @param bibtex the BibEntry as BibTeX string (see ADR-0027 for more information, why we don't use a HashMap / JSON) | ||
*/ | ||
public record BibEntryDTO(SharedBibEntryData sharingMetadata, String userComments, String citationKey, String bibtex) implements Comparable<BibEntryDTO> { | ||
|
||
public static final Logger LOGGER = LoggerFactory.getLogger(BibEntryDTO.class); | ||
|
||
public BibEntryDTO(BibEntry bibEntry, BibDatabaseMode bibDatabaseMode, FieldWriterPreferences fieldWriterPreferences, BibEntryTypesManager bibEntryTypesManager) { | ||
this(bibEntry.getSharedBibEntryData(), | ||
bibEntry.getUserComments(), | ||
bibEntry.getCitationKey().orElse(""), | ||
convertToString(bibEntry, bibDatabaseMode, fieldWriterPreferences, bibEntryTypesManager) | ||
); | ||
} | ||
|
||
private static String convertToString(BibEntry entry, BibDatabaseMode bibDatabaseMode, FieldWriterPreferences fieldWriterPreferences, BibEntryTypesManager bibEntryTypesManager) { | ||
StringWriter rawEntry = new StringWriter(); | ||
BibWriter bibWriter = new BibWriter(rawEntry, "\n"); | ||
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), bibEntryTypesManager); | ||
try { | ||
bibtexEntryWriter.write(entry, bibWriter, bibDatabaseMode); | ||
} catch (IOException e) { | ||
LOGGER.warn("Problem creating BibTeX entry.", e); | ||
return "error"; | ||
} | ||
return rawEntry.toString(); | ||
} | ||
|
||
@Override | ||
public int compareTo(BibEntryDTO o) { | ||
int sharingComparison = sharingMetadata.compareTo(o.sharingMetadata); | ||
if (sharingComparison != 0) { | ||
return sharingComparison; | ||
} | ||
LOGGER.error("Comparing equal DTOs"); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("sharingMetadata", sharingMetadata) | ||
.add("userComments", userComments) | ||
.add("citationkey", citationKey) | ||
.add("bibtex", bibtex) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jabref.http.dto; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import org.glassfish.hk2.api.Factory; | ||
|
||
public class GsonFactory implements Factory<Gson> { | ||
@Override | ||
public Gson provide() { | ||
return new GsonBuilder() | ||
.setPrettyPrinting() | ||
.create(); | ||
} | ||
|
||
@Override | ||
public void dispose(Gson instance) { | ||
} | ||
} |
Oops, something went wrong.