A helper class used by {@link PropertiesConfiguration} to keepthe layout of a properties file.
Instances of this class are associated with a {@code PropertiesConfiguration} object. They are responsible foranalyzing properties files and for extracting as much information about the file layout (e.g. empty lines, comments) as possible. When the properties file is written back again it should be close to the original.
The {@code PropertiesConfigurationLayout} object associated with a{@code PropertiesConfiguration} object can be obtained using the{@code getLayout()} method of the configuration. Then the methodsprovided by this class can be used to alter the properties file's layout.
Implementation note: This is a very simple implementation, which is far away from being perfect, i.e. the original layout of a properties file won't be reproduced in all cases. One limitation is that comments for multi-valued property keys are concatenated. Maybe this implementation can later be improved.
To get an impression how this class works consider the following properties file:
# A demo configuration file # for Demo App 1.42 # Application name AppName=Demo App # Application vendor AppVendor=DemoSoft # GUI properties # Window Color windowColors=0xFFFFFF,0x000000 # Include some setting include=settings.properties # Another vendor AppVendor=TestSoft
For this example the following points are relevant:
- The first two lines are set as header comment. The header comment is determined by the last blanc line before the first property definition.
- For the property {@code AppName} one comment line and oneleading blanc line is stored.
- For the property {@code windowColors} two comment lines and twoleading blanc lines are stored.
- Include files is something this class cannot deal with well. When saving the properties configuration back, the included properties are simply contained in the original file. The comment before the include property is skipped.
- For all properties except for {@code AppVendor} the "singleline" flag is set. This is relevant only for {@code windowColors}, which has multiple values defined in one line using the separator character.
- The {@code AppVendor} property appears twice. The comment linesare concatenated, so that {@code layout.getComment("AppVendor");} willresult in
Application vendor<CR>Another vendor
, with <CR>
meaning the line separator. In addition the "single line" flag is set to false for this property. When the file is saved, two property definitions will be written (in series).
@version $Id: PropertiesConfigurationLayout.java 1624601 2014-09-12 18:04:36Z oheger $
@since 1.3