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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Entries with a single corporate author are now correclty exported to the corresponding `corporate` author field in MS-Office XML. [#1497](https://github.com/JabRef/jabref/issues/1497)
- Improved author handling in MS-Office Import/Export
- The `day` part of the biblatex `date` field is now exported to the corresponding `day` field in MS-Office XML. [#2691](https://github.com/JabRef/jabref/issues/2691)
- JabRef will now no longer delete meta data it does not know, but keeps such entrys and tries to keep their formatting as far as possible
- Single underscores are not converted during the LaTeX to unicode conversion, which does not follow the rules of LaTeX, but is what users require. [#2664](https://github.com/JabRef/jabref/issues/2664)
- The bibtexkey field is not converted to unicode

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/jabref/logic/exporter/MetaDataSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public static Map<String, String> getSerializedStringMap(MetaData metaData,
// Skip this if only the root node exists (which is always the AllEntriesGroup).
metaData.getGroups().filter(root -> root.getNumberOfChildren() > 0).ifPresent(
root -> serializedMetaData.put(MetaData.GROUPSTREE, serializeGroups(root)));

// finally add all unknown meta data items to the serialization map
Map<String, List<String>> unknownMetaData = metaData.getUnknownMetaData();
for(Map.Entry<String, List<String>> entry : unknownMetaData.entrySet()){
StringBuilder value = new StringBuilder();
value.append(OS.NEWLINE);
for(String line: entry.getValue()){
value.append(line.replaceAll(";", "\\\\;") + MetaData.SEPARATOR_STRING + OS.NEWLINE);
}
serializedMetaData.put(entry.getKey(), value.toString());
}

return serializedMetaData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public static MetaData parse(MetaData metaData, Map<String, String> data, Charac
case MetaData.SAVE_ORDER_CONFIG:
metaData.setSaveOrderConfig(SaveOrderConfig.parse(value));
break;
case "groupsversion":
case "groups":
// These keys were used in previous JabRef versions, we will not support them anymore -> ignored
break;
default:
// Keep meta data items that we do not know in the file
metaData.putUnkownMetaDataItem(entry.getKey(), value);
}
}
if (!defaultCiteKeyPattern.isEmpty() || !nonDefaultCiteKeyPatterns.isEmpty()) {
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/jabref/model/metadata/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class MetaData {
private boolean isProtected;
private String defaultFileDirectory;
private ContentSelectors contentSelectors = new ContentSelectors();

private Map<String, List<String>> unkownMetaData = new HashMap<>();

/**
* Constructs an empty metadata.
Expand Down Expand Up @@ -100,8 +100,8 @@ public AbstractBibtexKeyPattern getCiteKeyPattern(GlobalBibtexKeyPattern globalP
/**
* Updates the stored key patterns to the given key patterns.
*
* @param bibtexKeyPattern the key patterns to update to. <br />
* A reference to this object is stored internally and is returned at getCiteKeyPattern();
* @param bibtexKeyPattern the key patterns to update to. <br /> A reference to this object is stored internally and
* is returned at getCiteKeyPattern();
*/
public void setCiteKeyPattern(AbstractBibtexKeyPattern bibtexKeyPattern) {
Objects.requireNonNull(bibtexKeyPattern);
Expand Down Expand Up @@ -274,6 +274,17 @@ public Map<String, String> getUserFileDirectories() {
return Collections.unmodifiableMap(userFileDirectory);
}

public Map<String, List<String>> getUnknownMetaData() {
return Collections.unmodifiableMap(unkownMetaData);
}

public void putUnkownMetaDataItem(String key, List<String> value) {
Objects.requireNonNull(key);
Objects.requireNonNull(value);

unkownMetaData.put(key, value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,22 @@ public void roundtripWithUserCommentBeforeStringAndChange() throws Exception {
}
}

@Test
public void roundtripWithUnknownMetaData() throws Exception {
Path testBibtexFile = Paths.get("src/test/resources/testbib/unknownMetaData.bib");
Charset encoding = StandardCharsets.UTF_8;
ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, encoding));

SavePreferences preferences = new SavePreferences().withEncoding(encoding).withSaveInOriginalOrder(true);
BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData(),
new Defaults(BibDatabaseMode.BIBTEX));

StringSaveSession session = databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries(), preferences);
try (Scanner scanner = new Scanner(testBibtexFile,encoding.name())) {
assertEquals(scanner.useDelimiter("\\A").next(), session.getStringValue());
}
}

@Test
public void writeSavedSerializationOfEntryIfUnchanged() throws Exception {
BibEntry entry = new BibEntry();
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/testbib/unknownMetaData.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
% Encoding: UTF-8

@Article{author2017title,
author = {Author},
title = {Title},
journal = {Journal},
year = {2017},
groups = {group},
}

@Comment{jabref-meta: databaseType:bibtex;}

@Comment{jabref-meta: unkown:
0 AllEntriesGroup:;
1 ExplicitGroup:group\;0\;;
1 ExplicitGroup:anothergroup\;0\;;
}