This is a patch to add a custom header to .properties files and match the features of the ExtendedProperties class so that it can be deprecated. I preferred using a get/setHeader instead of a header parameter on the save method, this will spare the hassle of carrying the header every time the configuration has to be saved.

Emmanuel Bourg

Index: src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 BasePropertiesConfiguration.java
--- src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  23 Dec 
2003 15:09:05 -0000      1.1.1.1
+++ src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java  30 Dec 
2003 12:15:38 -0000
@@ -54,6 +54,7 @@
  * <http://www.apache.org/>.
  */
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -61,6 +62,7 @@
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.io.Reader;
+import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 
 import java.util.Date;
@@ -164,6 +166,9 @@
     /** Allow file inclusion or not */
     private boolean includesAllowed = false;
 
+    /** Comment header of the .properties file */
+    private String header;
+
     /**
      * This is the name of the property that can point to other
      * properties file for including other properties files.
@@ -276,6 +281,17 @@
         File file = new File(filename);
         PropertiesWriter out = new PropertiesWriter(file);
 
+        if (header != null)
+        {
+            BufferedReader reader = new BufferedReader(new StringReader(header));
+            String line;
+            while ((line = reader.readLine()) != null)
+            {
+                out.writeComment(line);
+            }
+            out.write("\n");
+        }
+
         out.writeComment("written by PropertiesConfiguration");
         out.writeComment(new Date().toString());
 
@@ -331,6 +347,21 @@
     public boolean getIncludesAllowed()
     {
         return this.includesAllowed;
+    }
+
+
+    /**
+     * Return the comment header.
+     */
+    public String getHeader() {
+        return header;
+    }
+
+    /**
+     * Set the comment header.
+     */
+    public void setHeader(String header) {
+        this.header = header;
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to