You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2006/07/09 18:20:31 UTC

[jira] Commented: (CONFIGURATION-104) [configuration] Preserve file structure (line comments) when re-saving properties file

    [ http://issues.apache.org/jira/browse/CONFIGURATION-104?page=comments#action_12419922 ] 

Oliver Heger commented on CONFIGURATION-104:
--------------------------------------------

+1 for the idea of a Layout class that tries to obtain as much information as possible from the properties file. I would like to start with a rather simple one that can be enhanced step by step.

The collaboration between a PropertiesConfiguration object and its Layout object could be as follows:
- The load(Reader) method of PropertiesConfiguration delegates to the Layout object.
- The Layout object reads the file line by line and stores relevant information, e.g. about comments, in internal data structures.
- Extracted properties are added to the PropertiesConfiguration.
- The Layout object is also registered as event listener at its PropertiesConfiguration. If events are received, its content is updated accordingly.
- PropertiesConfiguration.save(Writer) again delegates to the Layout object for writing the data back to file.

So the interface of the layout class could roughly look as follows:

public class PropertiesConfigurationLayout implements ConfigurationListener
{
    /**
     * Creates a new instance and sets the associated configuration.
     */
    public PropertiesConfigurationLayou(PropertiesConfiguration config);

    /**
     * Reads in a properties file.
     */
    public void load(Reader in) throws ConfigurationException;

    /**
     * Writes the internal data into a properties file.
     */
    public void save(Writer out) throws ConfigurationException;

    // it would also be nice to have access to comments for properties
    
    /**
     * Returns the comment for the specified key.
     */
    public String getComment(String key);

    /**
     * Sets the comment for the specified key.
     */
    public void setComment(String key, String comment);

    /**
     * Returns the header comment.
     */
    public String getHeaderComment();

    /**
     * Sets the header comment.
     */
    public void setHeaderComment(String comment);
}

Any thoughts?


> [configuration] Preserve file structure (line comments) when re-saving properties file
> --------------------------------------------------------------------------------------
>
>          Key: CONFIGURATION-104
>          URL: http://issues.apache.org/jira/browse/CONFIGURATION-104
>      Project: Commons Configuration
>         Type: Bug

>  Environment: Operating System: other
> Platform: Other
>     Reporter: Oded Noam
>  Attachments: preserve-comments-patch, preserve-comments-patch-java1.3
>
> This bug applies when an application allows both manual editing of its 
> configuration files, and  manipulation of the configuration via software. When 
> saving the configuration file after changing, its file structure - file, 
> section and line comments - will all be lost. Next time a human tries to edit 
> the configuration file, all property documentation will be lost.
> I have created a fix for this problem, applicable to PropertiesConfiguration 
> and XMLPropertiesConfiguration. The fix allows these classes to preserve a 
> list of comment lines preceding each property line. By default, comments are 
> not preserved; in case the comment preservation is required, it should be 
> enabled prior to loading the configuration file using:
> AbstractFileConfiguration.setDefaultPreserveComments(true);
> The fix is implemented and tested, attached as a patch file to this bug.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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