Skip to content

Commit

Permalink
Fix serialization of newlines for meta data and custom entry types
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard committed Dec 4, 2015
1 parent 6dce25b commit c3a756e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,18 @@ public void writeMetaData(Writer out) throws IOException {

// if there is something to write, initially append two newlines
boolean somethingToWrite = sortedKeys.size() > 0 && groupsRoot != null && groupsRoot.getChildCount() > 0;
if (somethingToWrite) {
out.write(Globals.NEWLINE);
out.write(Globals.NEWLINE);
}

for (String key : sortedKeys) {

StringBuffer sb = new StringBuffer();
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);
Vector<String> orderedData = metaData.get(key);
sb.append("@comment{").append(META_FLAG).append(key).append(":");
for (int j = 0; j < orderedData.size(); j++) {
sb.append(StringUtil.quote(orderedData.elementAt(j), ";", '\\')).append(";");
}
sb.append("}");
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);

out.write(sb.toString());
}
Expand All @@ -283,15 +280,18 @@ public void writeMetaData(Writer out) throws IOException {
if ((groupsRoot != null) && (groupsRoot.getChildCount() > 0)) {
StringBuffer sb = new StringBuffer();
// write version first
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);
sb.append("@comment{").append(META_FLAG).append("groupsversion:");
sb.append("" + VersionHandling.CURRENT_VERSION + ";");
sb.append("}");
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);

out.write(sb.toString());

// now write actual groups
sb = new StringBuffer();
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);
sb.append("@comment{").append(META_FLAG).append("groupstree:");
sb.append(Globals.NEWLINE);
// GroupsTreeNode.toString() uses "\n" for separation
Expand All @@ -303,8 +303,6 @@ public void writeMetaData(Writer out) throws IOException {
sb.append(Globals.NEWLINE);
}
sb.append("}");
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);
out.write(sb.toString());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/exporter/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ public static SaveSession saveDatabase(BibtexDatabase database,
if (type instanceof CustomEntryType) {
CustomEntryType tp = (CustomEntryType) type;
CustomEntryTypesManager.save(tp, writer);
writer.write(Globals.NEWLINE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ public static void saveCustomEntryTypes(JabRefPreferences prefs) {
}

public static void save(CustomEntryType entry, Writer out) throws IOException {
out.write(Globals.NEWLINE + Globals.NEWLINE);
out.write("@comment{");
out.write(CustomEntryType.ENTRYTYPE_FLAG);
out.write(entry.getName());
out.write(": req[");
out.write(entry.getRequiredFieldsString());
out.write("] opt[");
out.write(String.join(";", entry.getOptionalFields()));
out.write("]}" + Globals.NEWLINE);
out.write("]}");
}

public static CustomEntryType parseEntryType(String comment) {
Expand Down

0 comments on commit c3a756e

Please sign in to comment.