- Timestamp:
- 2011-10-31T19:07:04+01:00 (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/preferences.xsd
r3938 r4553 12 12 </choice> 13 13 </sequence> 14 <attribute name="version" type="string" /> 14 15 </complexType> 15 16 -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4512 r4553 385 385 final PrintWriter out = new PrintWriter(new OutputStreamWriter( 386 386 new FileOutputStream(prefFile + "_tmp"), "utf-8"), false); 387 for (final Entry<String, String> e : properties.entrySet()) { 388 String s = defaults.get(e.getKey()); 389 /* don't save default values */ 390 if(s == null || !s.equals(e.getValue())) { 391 out.println(e.getKey() + "=" + e.getValue()); 392 } 393 } 387 out.print(toXML(false)); 394 388 out.close(); 395 389 … … 438 432 } 439 433 440 public void load() throws IOException {434 public void load() throws Exception { 441 435 properties.clear(); 442 436 if(!Main.applet) { 443 437 final BufferedReader in = new BufferedReader(new InputStreamReader( 444 438 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8")); 445 int lineNumber = 0; 446 ArrayList<Integer> errLines = new ArrayList<Integer>(); 447 for (String line = in.readLine(); line != null; line = in.readLine(), lineNumber++) { 448 final int i = line.indexOf('='); 449 if (i == -1 || i == 0) { 450 errLines.add(lineNumber); 451 continue; 439 /* FIXME: TODO: remove old style config file end of 2012 */ 440 in.mark(1); 441 int v = in.read(); 442 in.reset(); 443 if(v == '<') { 444 fromXML(in); 445 } else { 446 int lineNumber = 0; 447 ArrayList<Integer> errLines = new ArrayList<Integer>(); 448 for (String line = in.readLine(); line != null; line = in.readLine(), lineNumber++) { 449 final int i = line.indexOf('='); 450 if (i == -1 || i == 0) { 451 errLines.add(lineNumber); 452 continue; 453 } 454 String key = line.substring(0,i); 455 String value = line.substring(i+1); 456 if (!value.isEmpty()) { 457 properties.put(key, value); 458 } 452 459 } 453 String key = line.substring(0,i); 454 String value = line.substring(i+1); 455 if (!value.isEmpty()) { 456 properties.put(key, value); 457 } 458 } 459 if (!errLines.isEmpty()) 460 throw new IOException(tr("Malformed config file at lines {0}", errLines)); 460 if (!errLines.isEmpty()) 461 throw new IOException(tr("Malformed config file at lines {0}", errLines)); 462 } 461 463 } 462 464 updateSystemProperties(); … … 525 527 try { 526 528 load(); 527 } catch ( IOException e) {529 } catch (Exception e) { 528 530 e.printStackTrace(); 529 531 File backupFile = new File(prefDir,"preferences.bak"); … … 1067 1069 StringBuilder b = new StringBuilder( 1068 1070 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 1069 "<preferences xmlns=\"http://josm.openstreetmap.de/preferences-1.0\">\n"); 1071 "<preferences xmlns=\"http://josm.openstreetmap.de/preferences-1.0\" version=\""+ 1072 Version.getInstance().getVersion() + "\">\n"); 1070 1073 for (Entry<String, String> p : properties.entrySet()) { 1071 1074 if (nopass && p.getKey().equals("osm-server.password")) { … … 1073 1076 } 1074 1077 String r = p.getValue(); 1075 if(r.contains("\u001e")) 1076 { 1077 b.append(" <collection key='"); 1078 b.append(XmlWriter.encode(p.getKey())); 1079 b.append("'>\n"); 1080 for (String val : r.split("\u001e", -1)) 1078 String s = defaults.get(p.getKey()); 1079 /* don't save default values */ 1080 if(s == null || !s.equals(r)) { 1081 if(r.contains("\u001e")) 1081 1082 { 1082 b.append(" <entry value='"); 1083 b.append(XmlWriter.encode(val)); 1083 b.append(" <collection key='"); 1084 b.append(XmlWriter.encode(p.getKey())); 1085 b.append("'>\n"); 1086 for (String val : r.split("\u001e", -1)) 1087 { 1088 b.append(" <entry value='"); 1089 b.append(XmlWriter.encode(val)); 1090 b.append("' />\n"); 1091 } 1092 b.append(" </collection>\n"); 1093 } 1094 else 1095 { 1096 b.append(" <tag key='"); 1097 b.append(XmlWriter.encode(p.getKey())); 1098 b.append("' value='"); 1099 b.append(XmlWriter.encode(p.getValue())); 1084 1100 b.append("' />\n"); 1085 1101 } 1086 b.append(" </collection>\n");1087 }1088 else1089 {1090 b.append(" <tag key='");1091 b.append(XmlWriter.encode(p.getKey()));1092 b.append("' value='");1093 b.append(XmlWriter.encode(p.getValue()));1094 b.append("' />\n");1095 1102 } 1096 1103 }
Note:
See TracChangeset
for help on using the changeset viewer.