commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration PropertiesConfiguration.java
Date Mon, 03 Jan 2005 16:51:29 GMT
ebourg      2005/01/03 08:51:29

  Modified:    configuration/xdocs changes.xml
               configuration/src/java/org/apache/commons/configuration
                        PropertiesConfiguration.java
  Log:
  Added a comment header to PropertiesConfiguration (bug 26092).
  The header is not parsed when the file is loaded yet.
  
  Revision  Changes    Path
  1.80      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- changes.xml	3 Jan 2005 16:35:04 -0000	1.79
  +++ changes.xml	3 Jan 2005 16:51:29 -0000	1.80
  @@ -8,6 +8,10 @@
     <body>
   
       <release version="1.1-dev" date="in CVS">
  +      <action dev="ebourg" type="add" issue="26092">
  +        Added a comment header to PropertiesConfiguration. The header is not
  +        parsed when the file is loaded yet.
  +      </action>
         <action dev="ebourg" type="add">
           Added the setEncoding(String) and the getEncoding() methods to the
           FileConfiguration interface to control the encoding of the
  
  
  
  1.19      +40 -3     jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
  
  Index: PropertiesConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PropertiesConfiguration.java	3 Jan 2005 11:58:46 -0000	1.18
  +++ PropertiesConfiguration.java	3 Jan 2005 16:51:29 -0000	1.19
  @@ -22,6 +22,8 @@
   import java.io.LineNumberReader;
   import java.io.Reader;
   import java.io.Writer;
  +import java.io.StringReader;
  +import java.io.BufferedReader;
   import java.net.URL;
   import java.util.Date;
   import java.util.Iterator;
  @@ -141,6 +143,9 @@
       /** Allow file inclusion or not */
       private boolean includesAllowed = true;
   
  +    /** Comment header of the .properties file */
  +    private String header;
  +
       /**
        * Creates an empty PropertyConfiguration object which can be
        * used to synthesize a new Properties file by adding values and
  @@ -237,6 +242,26 @@
       }
   
       /**
  +     * Return the comment header.
  +     *
  +     * @since 1.1
  +     */
  +    public String getHeader()
  +    {
  +        return header;
  +    }
  +
  +    /**
  +     * Set the comment header.
  +     *
  +     * @since 1.1
  +     */
  +    public void setHeader(String header)
  +    {
  +        this.header = header;
  +    }
  +
  +    /**
        * Load the properties from the given input stream and using the specified
        * encoding.
        *
  @@ -306,8 +331,20 @@
           {
               PropertiesWriter out = new PropertiesWriter(writer, getDelimiter());
   
  +            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());
  +            out.write("\n");
   
               Iterator keys = getKeys();
               while (keys.hasNext())
  @@ -387,8 +424,8 @@
   
                   line = line.trim();
   
  -                if (StringUtils.isEmpty(line)
  -                        || (line.charAt(0) == '#'))
  +                // skip comments and empty lines
  +                if (StringUtils.isEmpty(line) || (line.charAt(0) == '#'))
                   {
                       continue;
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message