|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.configuration.AbstractConfiguration org.apache.commons.configuration.BaseConfiguration org.apache.commons.configuration.AbstractFileConfiguration org.apache.commons.configuration.PropertiesConfiguration
This is the "classic" Properties loader which loads the values from a single or multiple files (which can be chained with "include =". All given path references are either absolute or relative to the file name supplied in the constructor.
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:
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? # properties can reference other properties base.prop = /base first.prop = ${base.prop}/first second.prop = ${first.prop}/second
Nested Class Summary | |
static class |
PropertiesConfiguration.PropertiesReader
This class is used to read properties lines. |
static class |
PropertiesConfiguration.PropertiesWriter
This class is used to write properties lines. |
Field Summary |
Fields inherited from class org.apache.commons.configuration.AbstractFileConfiguration |
autoSave, basePath, fileName, strategy |
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
END_TOKEN, START_TOKEN |
Constructor Summary | |
PropertiesConfiguration()
Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving(). |
|
PropertiesConfiguration(File file)
Creates and loads the extended properties from the specified file. |
|
PropertiesConfiguration(String fileName)
Creates and loads the extended properties from the specified file. |
|
PropertiesConfiguration(URL url)
Creates and loads the extended properties from the specified URL. |
Method Summary | |
String |
getHeader()
Return the comment header. |
static String |
getInclude()
Gets the property value for including other properties files. |
boolean |
getIncludesAllowed()
Reports the status of file inclusion. |
void |
load(Reader in)
Load the properties from the given reader. |
void |
save(Writer writer)
Save the configuration to the specified stream. |
void |
setBasePath(String basePath)
Extend the setBasePath method to turn includes on and off based on the existence of a base path. |
void |
setHeader(String header)
Set the comment header. |
static void |
setInclude(String inc)
Sets the property value for including other properties files. |
protected void |
setIncludesAllowed(boolean includesAllowed)
Controls whether additional files can be loaded by the include = |
protected static String |
unescapeJava(String str,
char delimiter)
Unescapes any Java literals found in the String to a
Writer . |
Methods inherited from class org.apache.commons.configuration.AbstractFileConfiguration |
addPropertyDirect, clearProperty, containsKey, getBasePath, getEncoding, getFile, getFileName, getKeys, getPath, getProperty, getReloadingStrategy, getURL, isAutoSave, isEmpty, load, load, load, load, load, load, possiblySave, reload, save, save, save, save, save, save, setAutoSave, setEncoding, setFile, setFileName, setPath, setReloadingStrategy, setURL |
Methods inherited from class org.apache.commons.configuration.BaseConfiguration |
clear |
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
addProperty, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, isThrowExceptionOnMissing, resolveContainerStore, setDelimiter, setProperty, setThrowExceptionOnMissing, subset |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.commons.configuration.Configuration |
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, setProperty, subset |
Constructor Detail |
public PropertiesConfiguration()
public PropertiesConfiguration(String fileName) throws ConfigurationException
fileName
- The name of the properties file to load.
ConfigurationException
- Error while loading the properties filepublic PropertiesConfiguration(File file) throws ConfigurationException
file
- The properties file to load.
ConfigurationException
- Error while loading the properties filepublic PropertiesConfiguration(URL url) throws ConfigurationException
url
- The location of the properties file to load.
ConfigurationException
- Error while loading the properties fileMethod Detail |
public static String getInclude()
public static void setInclude(String inc)
inc
- A String.protected void setIncludesAllowed(boolean includesAllowed)
includesAllowed
- includesAllowed True if Includes are allowed.public boolean getIncludesAllowed()
public String getHeader()
public void setHeader(String header)
public void load(Reader in) throws ConfigurationException
clear()
method is not called, so
the properties contained in the loaded file will be added to the
actual set of properties.
in
- An InputStream.
ConfigurationException
public void save(Writer writer) throws ConfigurationException
writer
- the output stream used to save the configuration
ConfigurationException
public void setBasePath(String basePath)
setBasePath
in interface FileConfiguration
setBasePath
in class AbstractFileConfiguration
basePath
- The new basePath to set.protected static String unescapeJava(String str, char delimiter)
Unescapes any Java literals found in the String
to a
Writer
.
str
- the String
to unescape, may be null
IllegalArgumentException
- if the Writer is null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |