In this class, empty PropertyConfigurations can be built, properties added and later saved. include statements are (obviously) not supported if you don't construct a PropertyConfiguration from a file.
The properties file syntax is explained here, basically it follows the syntax of the stream parsed by {@link java.util.Properties#load} andadds several useful extensions:
key <separator> value
. The separators accepted are '='
, ':'
and any white space character. Examples: key1 = value1 key2 : value2 key3 value3
key\:foo = bar
key = This property, has multiple, valueswill result in a property with three values. You can change the value delimiter using the
{@link AbstractConfiguration#setListDelimiter(char)}
method. Setting the delimiter to 0 will disable value splitting completely. {@link PropertiesConfigurationLayout}
object (see below) will try to preserve as much of the original format as possible, i.e. properties with multiple values defined on a single line will also be written back on a single line, and multiple occurrences of a single key will be written on multiple lines. If the addProperty()
method was called multiple times for adding multiple values to a property, these properties will per default be written on multiple lines in the output file, too. Some options of the PropertiesConfigurationLayout
class have influence on that behavior. Here is an example of a valid extended properties file:
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.escaped = Hi\, what'up? # properties can reference other properties base.prop = /base first.prop = ${base.prop}/first second.prop = ${first.prop}/second
A PropertiesConfiguration
object is associated with an instance of the {@link PropertiesConfigurationLayout}
class, which is responsible for storing the layout of the parsed properties file (i.e. empty lines, comments, and such things). The getLayout()
method can be used to obtain this layout object. With setLayout()
a new layout object can be set. This should be done before a properties file was loaded.
Note:Configuration objects of this type can be read concurrently by multiple threads. However if one of these threads modifies the object, synchronization has to be performed manually. @see java.util.Properties#load @author Stefano Mazzocchi @author Jon S. Stevens @author Dave Bryson @author Geir Magnusson Jr. @author Leon Messerschmidt @author Kent Johnson @author Daniel Rall @author Ilkka Priha @author Jason van Zyl @author Martin Poeschl @author Henning P. Schmiedehausen @author Eric Pugh @author Oliver Heger @author Emmanuel Bourg @version $Id: PropertiesConfiguration.java 727168 2008-12-16 21:44:29Z oheger $
In this class, empty PropertyConfigurations can be built, properties added and later saved. include statements are (obviously) not supported if you don't construct a PropertyConfiguration from a file.
The properties file syntax is explained here, basically it follows the syntax of the stream parsed by {@link java.util.Properties#load} andadds several useful extensions:
key <separator> value
. The separators accepted are {@code '='}, {@code ':'} and any whitespace character. Examples: key1 = value1 key2 : value2 key3 value3
key\:foo = bar
key = This property, has multiple, valueswill result in a property with three values. You can change the handling of delimiters using the {@link AbstractConfiguration#setListDelimiterHandler(ListDelimiterHandler)}method. Per default, list splitting is disabled.
Here is an example of a valid extended properties file:
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.escaped = Hi\, what'up? # properties can reference other properties base.prop = /base first.prop = ${base.prop}/first second.prop = ${first.prop}/second
A {@code PropertiesConfiguration} object is associated with aninstance of the {@link PropertiesConfigurationLayout} class,which is responsible for storing the layout of the parsed properties file (i.e. empty lines, comments, and such things). The {@code getLayout()}method can be used to obtain this layout object. With {@code setLayout()}a new layout object can be set. This should be done before a properties file was loaded.
Like other {@code Configuration} implementations, this class uses a{@code Synchronizer} object to control concurrent access. By choosing asuitable implementation of the {@code Synchronizer} interface, an instancecan be made thread-safe or not. Note that access to most of the properties typically set through a builder is not protected by the {@code Synchronizer}. The intended usage is that these properties are set once at construction time through the builder and after that remain constant. If you wish to change such properties during life time of an instance, you have to use the {@code lock()} and {@code unlock()} methods manually to ensure thatother threads see your changes. @see java.util.Properties#load @author Stefano Mazzocchi @author Jon S. Stevens @author Dave Bryson @author Geir Magnusson Jr. @author Leon Messerschmidt @author Kent Johnson @author Daniel Rall @author Ilkka Priha @author Jason van Zyl @author Martin Poeschl @author Henning P. Schmiedehausen @author Eric Pugh @author Emmanuel Bourg @version $Id: PropertiesConfiguration.java 1624601 2014-09-12 18:04:36Z oheger $
The Extended Properties syntax is explained here:
key = value
Here is an example of a valid extended properties file:
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.excaped = Hi\, what'up?@author Stefano Mazzocchi @author Jon S. Stevens @author Dave Bryson @author Geir Magnusson Jr. @author Leon Messerschmidt @author Kent Johnson @author Daniel Rall @author Ilkka Priha @author Jason van Zyl @author Martin Poeschl @version $Id: PropertiesConfiguration.java,v 1.2 2002/02/04 11:31:34 mpoeschl Exp $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|