Index: lutinutil/src/java/org/codelutin/option/Config.java
diff -u lutinutil/src/java/org/codelutin/option/Config.java:1.8 lutinutil/src/java/org/codelutin/option/Config.java:1.9
--- lutinutil/src/java/org/codelutin/option/Config.java:1.8 Mon Jan 7 21:19:21 2008
+++ lutinutil/src/java/org/codelutin/option/Config.java Tue Jan 8 01:15:43 2008
@@ -23,6 +23,7 @@
import static org.codelutin.i18n.I18n._;
import org.codelutin.util.ReflectUtil;
+import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -148,7 +149,7 @@
if (source == null) {
return;
}
- store(out, "save configuration [" + category + "] ");
+ store(out, null, "save configuration [" + category + "] ");
clearModified();
}
@@ -156,15 +157,24 @@
if (source == null) {
return;
}
+ // since config store file can contain more than one Config we must
+ // obtain first all
+ Properties props = new Properties();
+
+ BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));
+ props.load(in);
+ in.close();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(source));
- store(out, "save configuration [" + category + "] ");
+ store(out, props, "save configuration [" + category + "] ");
+ out.close();
clearModified();
}
+
public void saveSafely() {
try {
save();
} catch (IOException e) {
- log.warn(_("could not save config {0} for reason {1}",getCategory(),e.getMessage()),e);
+ log.warn(_("could not save config {0} for reason {1}", getCategory(), e.getMessage()), e);
}
}
@@ -464,10 +474,11 @@
* Unsafe data are not stored!
*
* @param out where to store
+ * @param props optional properties to save
* @param comments comment to add in file
* @throws IOException if any problem while saving
*/
- protected void store(OutputStream out, String comments) throws IOException {
+ protected void store(OutputStream out, Properties props, String comments) throws IOException {
getTmp().clear();
try {
if (!isEmpty()) {
@@ -475,6 +486,16 @@
Object val = key.getCurrentValue();
// a shame that Properties.store can only deal with String value
getTmp().put(key.getKey(), val == null ? "" : val.toString());
+ if (props != null) {
+ props.remove(key.getKey());
+ }
+ }
+ }
+ if (props != null) {
+ for (Map.Entry