public final class Settings extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Settings.KEYS
The collection of keys used within the properties file.
|
| Constructor and Description |
|---|
Settings()
Initialize the settings object.
|
Settings(String propertiesFilePath)
Initialize the settings object using the given properties file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Cleans up resources to prevent memory leaks.
|
void |
cleanup(boolean deleteTemporary)
Cleans up resources to prevent memory leaks.
|
String[] |
getArray(String key)
Returns a list with the given key.
|
boolean |
getBoolean(String key)
Returns a boolean value from the properties file.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Returns a boolean value from the properties file.
|
String |
getConnectionString(String connectionStringKey,
String dbFileNameKey)
Returns a connection string from the configured properties.
|
File |
getDataDirectory()
Retrieves the primary data directory that is used for caching web
content.
|
protected File |
getDataFile(String key)
Returns a value from the properties file as a File object.
|
File |
getFile(String key)
Returns a value from the properties file as a File object.
|
float |
getFloat(String key,
float defaultValue)
Returns a float value from the properties file.
|
File |
getH2DataDirectory()
Retrieves the H2 data directory - if the database has been moved to the
temp directory this method will return the temp directory.
|
int |
getInt(String key)
Returns an int value from the properties file.
|
int |
getInt(String key,
int defaultValue)
Returns an int value from the properties file.
|
long |
getLong(String key)
Returns a long value from the properties file.
|
String |
getString(String key)
Returns a value from the properties file.
|
String |
getString(String key,
String defaultValue)
Returns a value from the properties file.
|
File |
getTempDirectory()
Returns the temporary directory.
|
File |
getTempFile(String prefix,
String extension)
Generates a new temporary file name that is guaranteed to be unique.
|
void |
mergeProperties(File filePath)
Merges a new properties file into the current properties.
|
void |
mergeProperties(InputStream stream)
Merges a new properties file into the current properties.
|
void |
mergeProperties(String filePath)
Merges a new properties file into the current properties.
|
void |
removeProperty(String key)
Removes a property from the local properties collection.
|
void |
setArrayIfNotEmpty(String key,
List<String> value)
Sets a property value only if the array value is not null and not empty.
|
void |
setArrayIfNotEmpty(String key,
String[] value)
Sets a property value only if the array value is not null and not empty.
|
void |
setBoolean(String key,
boolean value)
Sets a property value.
|
void |
setBooleanIfNotNull(String key,
Boolean value)
Sets a property value only if the value is not null.
|
void |
setInt(String key,
int value)
Sets a property value.
|
void |
setIntIfNotNull(String key,
Integer value)
Sets a property value only if the value is not null.
|
void |
setString(String key,
String value)
Sets a property value.
|
void |
setStringIfNotEmpty(String key,
String value)
Sets a property value only if the value is not null and not empty.
|
void |
setStringIfNotNull(String key,
String value)
Sets a property value only if the value is not null.
|
public Settings()
public Settings(String propertiesFilePath)
propertiesFilePath - the path to the base properties file to loadpublic void cleanup()
public void cleanup(boolean deleteTemporary)
deleteTemporary - flag indicating whether any temporary directories
generated should be removedpublic void setString(String key, String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotNull(String key, String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotEmpty(String key, String value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(String key, String[] value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(String key, List<String> value)
key - the key for the propertyvalue - the value for the propertypublic void setBoolean(String key, boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setBooleanIfNotNull(String key, Boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setInt(String key, int value)
key - the key for the propertyvalue - the value for the propertypublic void setIntIfNotNull(String key, Integer value)
key - the key for the propertyvalue - the value for the propertypublic void mergeProperties(File filePath) throws FileNotFoundException, IOException
filePath - the path to the properties file to merge.FileNotFoundException - is thrown when the filePath points to a
non-existent fileIOException - is thrown when there is an exception loading/merging
the propertiespublic void mergeProperties(String filePath) throws FileNotFoundException, IOException
filePath - the path to the properties file to merge.FileNotFoundException - is thrown when the filePath points to a
non-existent fileIOException - is thrown when there is an exception loading/merging
the propertiespublic void mergeProperties(InputStream stream) throws IOException
stream - an Input Stream pointing at a properties file to mergeIOException - is thrown when there is an exception loading/merging
the propertiespublic File getFile(String key)
key - the key to lookup within the properties fileprotected File getDataFile(String key)
key - the key to lookup within the properties filepublic String getString(String key, String defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value for the requested propertypublic File getTempDirectory() throws IOException
IOException - thrown if the temporary directory does not
exist and cannot be createdpublic String getString(String key)
key - the key to lookup within the properties filepublic String[] getArray(String key)
null will be returned.key - the key to get from this Settings.null if the key wasn't present.public void removeProperty(String key)
key - the property key to removepublic int getInt(String key) throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving
the settingpublic int getInt(String key, int defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value to returnpublic long getLong(String key) throws InvalidSettingException
key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving
the settingpublic boolean getBoolean(String key) throws InvalidSettingException
-Dprop=value argument this method will return the value from
the system properties before the values in the contained configuration
file.key - the key to lookup within the properties fileInvalidSettingException - is thrown if there is an error retrieving
the settingpublic boolean getBoolean(String key, boolean defaultValue) throws InvalidSettingException
-Dprop=value argument this method will return the value from
the system properties before the values in the contained configuration
file.key - the key to lookup within the properties filedefaultValue - the default value to return if the setting does not
existInvalidSettingException - is thrown if there is an error retrieving
the settingpublic float getFloat(String key, float defaultValue)
-Dprop=value argument this method will return the value from
the system properties before the values in the contained configuration
file.key - the key to lookup within the properties filedefaultValue - the default value to return if the setting does not
existpublic String getConnectionString(String connectionStringKey, String dbFileNameKey) throws IOException, InvalidSettingException
connectionStringKey - the property file key for the connection
stringdbFileNameKey - the settings key for the db filenameIOException - thrown the data directory cannot be createdInvalidSettingException - thrown if there is an invalid settingpublic File getDataDirectory() throws IOException
IOException - is thrown if an IOException occurs of course...public File getH2DataDirectory() throws IOException
IOException - is thrown if an IOException occurs of course...public File getTempFile(String prefix, String extension) throws IOException
prefix - the prefix for the file name to generateextension - the extension of the generated file nameIOException - thrown if the temporary folder could not be
createdCopyright © 2012–2019 OWASP. All rights reserved.