ebourg      2004/06/15 03:12:29

  Modified:    configuration/src/java/org/apache/commons/configuration
                        BasePropertiesConfiguration.java
               configuration/xdocs changes.xml
               configuration/conf test.properties
               configuration/src/test/org/apache/commons/configuration
                        TestPropertiesConfiguration.java
  Log:
  Interpolation tokens in a PropertyConfiguration are now preserved on saving
  
  Revision  Changes    Path
  1.9       +18 -9     
jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java
  
  Index: BasePropertiesConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BasePropertiesConfiguration.java  3 Jun 2004 15:32:46 -0000       1.8
  +++ BasePropertiesConfiguration.java  15 Jun 2004 10:12:29 -0000      1.9
  @@ -27,6 +27,7 @@
   
   import java.util.Date;
   import java.util.Iterator;
  +import java.util.List;
   
   import org.apache.commons.lang.StringEscapeUtils;
   import org.apache.commons.lang.StringUtils;
  @@ -111,8 +112,7 @@
    *
    * @version $Id$
    */
  -public abstract class BasePropertiesConfiguration
  -    extends BasePathConfiguration
  +public abstract class BasePropertiesConfiguration extends BasePathConfiguration
   {
       /** Allow file inclusion or not */
       private boolean includesAllowed = false;
  @@ -239,7 +239,16 @@
                for (Iterator i = this.getKeys(); i.hasNext();)
                {
                        String key = (String) i.next();
  -                     out.writeProperty(key, this.getStringArray(key));
  +                Object value = getProperty(key);
  +
  +                if (value instanceof List)
  +                {
  +                    out.writeProperty(key, (List) value);
  +                }
  +                else
  +                {
  +                    out.writeProperty(key, value);
  +                }
                }
                out.flush();
                out.close();
  @@ -388,13 +397,13 @@
            * @param value
            * @exception IOException
            */
  -        public void writeProperty(String key, String value) throws IOException
  +        public void writeProperty(String key, Object value) throws IOException
           {
               write(key);
               write(" = ");
               if (value != null)
               {
  -                String v = StringEscapeUtils.escapeJava(value);
  +                String v = StringEscapeUtils.escapeJava(String.valueOf(value));
                   v = StringUtils.replace(v, String.valueOf(DELIMITER), "\\" + 
DELIMITER);
                   write(v);
               }
  @@ -408,11 +417,11 @@
            * @param key The key of the property
            * @param values The array of values of the property
            */
  -        public void writeProperty(String key, String[] values) throws IOException
  +        public void writeProperty(String key, List values) throws IOException
           {
  -            for (int i = 0; i < values.length; i++)
  +            for (int i = 0; i < values.size(); i++)
               {
  -                writeProperty(key, values[i]);
  +                writeProperty(key, values.get(i));
               }
           }
   
  
  
  
  1.20      +4 -1      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- changes.xml       4 May 2004 22:27:10 -0000       1.19
  +++ changes.xml       15 Jun 2004 10:12:29 -0000      1.20
  @@ -6,7 +6,10 @@
     </properties>
   
     <body>
  -    <release version="1.0-dev-4" date="">  
  +    <release version="1.0-dev-4" date="">
  +     <action dev="ebourg" type="fix">
  +        Tokens like ${ref} in a PropertyConfiguration are now properly saved 
(Bugzilla 29366).
  +     </action>
        <action dev="epugh" type="fix">
           SubsetConfiguration returns a List on getList().  AbstractConfiguration 
wouldn't properly
           deal with a List, only with a Container for getList()!  Thanks to jschaible 
for the unit test.
  
  
  
  1.5       +7 -5      jakarta-commons/configuration/conf/test.properties
  
  Index: test.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/conf/test.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- test.properties   3 Jun 2004 15:32:46 -0000       1.4
  +++ test.properties   15 Jun 2004 10:12:29 -0000      1.5
  @@ -1,7 +1,7 @@
   configuration.loaded = true
   
   packages = packagea
  -propertyInOrder=test.properties
  +propertyInOrder = test.properties
   
   include = include.properties
   
  @@ -14,13 +14,15 @@
   
   test.equals = value=one
   
  -test.empty=
  +test.empty =
   
   #
   # Test a property that uses a previous property
   #
  -base=base
  -base.reference=${base}extra
  +base = base
  +base.reference = ${base}extra
  +base.reference.array = ${base}extra
  +base.reference.array = ${base}extra
   
   #
   # Non String Properties
  @@ -54,4 +56,4 @@
   test.short.array = 2
   test.short.array = 3
   
  -test.overwrite       = 1
  \ No newline at end of file
  +test.overwrite = 1
  
  
  
  1.7       +11 -6     
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
  
  Index: TestPropertiesConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestPropertiesConfiguration.java  3 Jun 2004 15:32:46 -0000       1.6
  +++ TestPropertiesConfiguration.java  15 Jun 2004 10:12:29 -0000      1.7
  @@ -42,9 +42,12 @@
   
       public void testSave() throws Exception
       {
  -     if(testSavePropertiesFile.exists()){
  +     // remove the file previously saved if necessary
  +        if(testSavePropertiesFile.exists()){
                assertTrue(testSavePropertiesFile.delete());
        }
  +
  +        // add an array of strings to the configuration
        conf.addProperty("string", "value1");
           List list = new ArrayList();
           for (int i = 1; i < 5; i++)
  @@ -53,13 +56,15 @@
           }
           conf.addProperty("array", list);
   
  +        // save the configuration
           conf.save(testSavePropertiesFile.getAbsolutePath());
   
  +        // read the configuration and compare the properties
           PropertiesConfiguration checkConfig = new 
PropertiesConfiguration(testSavePropertiesFile.getAbsolutePath());
  -        for (Iterator i = conf.getKeys(); i.hasNext();){
  -             String key = (String)i.next();
  -             assertTrue(checkConfig.containsKey(key));
  -             assertEquals(conf.getString(key),checkConfig.getString(key));
  +        for (Iterator i = conf.getKeys(); i.hasNext();) {
  +             String key = (String) i.next();
  +             assertTrue("The saved configuration doesn't contain the key '" + key + 
"'", checkConfig.containsKey(key));
  +             assertEquals("Value of the '" + key + "' property", 
conf.getProperty(key), checkConfig.getProperty(key));
           }
       }
   
  
  
  

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

Reply via email to