|
24 | 24 | import net.sf.jabref.logic.labelPattern.DatabaseLabelPattern; |
25 | 25 | import net.sf.jabref.model.database.BibDatabase; |
26 | 26 | import net.sf.jabref.sql.DBStrings; |
27 | | -import net.sf.jabref.logic.util.strings.StringUtil; |
28 | 27 |
|
29 | 28 | public class MetaData implements Iterable<String> { |
30 | 29 |
|
31 | 30 | public static final String META_FLAG = "jabref-meta: "; |
| 31 | + public static final String SAVE_ORDER_CONFIG = "saveOrderConfig"; |
32 | 32 | private static final String PREFIX_KEYPATTERN = "keypattern_"; |
33 | 33 | private static final String KEYPATTERNDEFAULT = "keypatterndefault"; |
34 | 34 | static final String DATABASE_TYPE = "DATABASE_TYPE"; |
| 35 | + public static final String GROUPSVERSION = "groupsversion"; |
| 36 | + public static final String GROUPSTREE = "groupstree"; |
| 37 | + public static final String GROUPS = "groups"; |
35 | 38 |
|
36 | 39 | private final Map<String, List<String>> metaData = new HashMap<>(); |
37 | 40 | private GroupTreeNode groupsRoot; |
@@ -70,16 +73,16 @@ public MetaData(Map<String, String> inData, BibDatabase db) { |
70 | 73 | } catch (IOException ex) { |
71 | 74 | System.err.println("Weird error while parsing meta data."); |
72 | 75 | } |
73 | | - if ("groupsversion".equals(entry.getKey())) { |
| 76 | + if (GROUPSVERSION.equals(entry.getKey())) { |
74 | 77 | if (!orderedData.isEmpty()) { |
75 | 78 | groupsVersionOnDisk = Integer.parseInt(orderedData.get(0)); |
76 | 79 | } |
77 | | - } else if ("groupstree".equals(entry.getKey())) { |
| 80 | + } else if (GROUPSTREE.equals(entry.getKey())) { |
78 | 81 | groupsTreePresent = true; |
79 | 82 | treeGroupsData = orderedData; // save for later user |
80 | 83 | // actual import operation is handled later because "groupsversion" |
81 | 84 | // tag might not yet have been read |
82 | | - } else if ("groups".equals(entry.getKey())) { |
| 85 | + } else if (GROUPS.equals(entry.getKey())) { |
83 | 86 | flatGroupsData = orderedData; |
84 | 87 | } else { |
85 | 88 | putData(entry.getKey(), orderedData); |
@@ -260,55 +263,6 @@ public void setGroups(GroupTreeNode root) { |
260 | 263 | groupTreeValid = true; |
261 | 264 | } |
262 | 265 |
|
263 | | - /** |
264 | | - * Writes all data to the specified writer, using each object's toString() |
265 | | - * method. |
266 | | - */ |
267 | | - public void writeMetaData(Writer out) throws IOException { |
268 | | - // write all meta data except groups |
269 | | - SortedSet<String> sortedKeys = new TreeSet<>(metaData.keySet()); |
270 | | - |
271 | | - for (String key : sortedKeys) { |
272 | | - |
273 | | - StringBuffer sb = new StringBuffer(); |
274 | | - sb.append(Globals.NEWLINE).append(Globals.NEWLINE); |
275 | | - List<String> orderedData = metaData.get(key); |
276 | | - sb.append("@comment{").append(META_FLAG).append(key).append(':'); |
277 | | - for (String data : orderedData) { |
278 | | - sb.append(StringUtil.quote(data, ";", '\\')).append(';'); |
279 | | - } |
280 | | - sb.append('}'); |
281 | | - |
282 | | - out.write(sb.toString()); |
283 | | - } |
284 | | - // write groups if present. skip this if only the root node exists |
285 | | - // (which is always the AllEntriesGroup). |
286 | | - if ((groupsRoot != null) && (groupsRoot.getChildCount() > 0)) { |
287 | | - StringBuffer sb = new StringBuffer(); |
288 | | - // write version first |
289 | | - sb.append(Globals.NEWLINE).append(Globals.NEWLINE); |
290 | | - sb.append("@comment{").append(META_FLAG).append("groupsversion:"); |
291 | | - sb.append(VersionHandling.CURRENT_VERSION).append(";}"); |
292 | | - |
293 | | - out.write(sb.toString()); |
294 | | - |
295 | | - // now write actual groups |
296 | | - sb = new StringBuffer(); |
297 | | - sb.append(Globals.NEWLINE).append(Globals.NEWLINE); |
298 | | - sb.append("@comment{").append(META_FLAG).append("groupstree:"); |
299 | | - sb.append(Globals.NEWLINE); |
300 | | - // GroupsTreeNode.toString() uses "\n" for separation |
301 | | - StringTokenizer tok = new StringTokenizer(groupsRoot.getTreeAsString(), Globals.NEWLINE); |
302 | | - while (tok.hasMoreTokens()) { |
303 | | - StringBuffer s = new StringBuffer(StringUtil.quote(tok.nextToken(), ";", '\\')).append(';'); |
304 | | - sb.append(s); |
305 | | - sb.append(Globals.NEWLINE); |
306 | | - } |
307 | | - sb.append('}'); |
308 | | - out.write(sb.toString()); |
309 | | - } |
310 | | - } |
311 | | - |
312 | 266 | /** |
313 | 267 | * Reads the next unit. Units are delimited by ';'. |
314 | 268 | */ |
|
0 commit comments