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(Properties properties)
Initialize the settings object using the given properties.
|
Settings(@NotNull 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(@NotNull String key)
Returns a list with the given key.
|
boolean |
getBoolean(@NotNull String key)
Returns a boolean value from the properties file.
|
boolean |
getBoolean(@NotNull 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(@NotNull String key)
Returns a value from the properties file as a File object.
|
@Nullable File |
getFile(@NotNull String key)
Returns a value from the properties file as a File object.
|
float |
getFloat(@NotNull 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(@NotNull String key)
Returns an int value from the properties file.
|
int |
getInt(@NotNull String key,
int defaultValue)
Returns an int value from the properties file.
|
long |
getLong(@NotNull String key)
Returns a long value from the properties file.
|
protected String |
getPrintableValue(@NotNull String key,
String value)
Obtains the printable/loggable value for a given key/value pair.
|
String |
getString(@NotNull String key)
Returns a value from the properties file.
|
String |
getString(@NotNull String key,
@Nullable String defaultValue)
Returns a value from the properties file.
|
File |
getTempDirectory()
Returns the temporary directory.
|
File |
getTempFile(@NotNull String prefix,
@NotNull String extension)
Generates a new temporary file name that is guaranteed to be unique.
|
protected void |
initMaskedKeys()
Initializes the masked keys collection.
|
void |
mergeProperties(@NotNull File filePath)
Merges a new properties file into the current properties.
|
void |
mergeProperties(@NotNull InputStream stream)
Merges a new properties file into the current properties.
|
void |
mergeProperties(@NotNull String filePath)
Merges a new properties file into the current properties.
|
void |
removeProperty(@NotNull String key)
Removes a property from the local properties collection.
|
void |
setArrayIfNotEmpty(@NotNull String key,
@Nullable List<String> value)
Sets a property value only if the array value is not null and not empty.
|
void |
setArrayIfNotEmpty(@NotNull String key,
@Nullable String[] value)
Sets a property value only if the array value is not null and not empty.
|
void |
setBoolean(@NotNull String key,
boolean value)
Sets a property value.
|
void |
setBooleanIfNotNull(@NotNull String key,
@Nullable Boolean value)
Sets a property value only if the value is not null.
|
void |
setFloat(@NotNull String key,
float value)
Sets a float property value.
|
void |
setInt(@NotNull String key,
int value)
Sets a property value.
|
void |
setIntIfNotNull(@NotNull String key,
@Nullable Integer value)
Sets a property value only if the value is not null.
|
void |
setString(@NotNull String key,
@NotNull String value)
Sets a property value.
|
void |
setStringIfNotEmpty(@NotNull String key,
@Nullable String value)
Sets a property value only if the value is not null and not empty.
|
void |
setStringIfNotNull(@NotNull String key,
@Nullable String value)
Sets a property value only if the value is not null.
|
public Settings()
public Settings(Properties properties)
properties - the properties to be used with this Settings instancepublic Settings(@NotNull
@NotNull 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 removedprotected String getPrintableValue(@NotNull @NotNull String key, String value)
key - the property keyvalue - the property valueprotected void initMaskedKeys()
initialize(java.lang.String) method because a caller may use the
mergeProperties(java.io.File) to add additional properties after
the call to initialize.public void setString(@NotNull
@NotNull String key,
@NotNull
@NotNull String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotNull(@NotNull
@NotNull String key,
@Nullable
@Nullable String value)
key - the key for the propertyvalue - the value for the propertypublic void setStringIfNotEmpty(@NotNull
@NotNull String key,
@Nullable
@Nullable String value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(@NotNull
@NotNull String key,
@Nullable
@Nullable String[] value)
key - the key for the propertyvalue - the value for the propertypublic void setArrayIfNotEmpty(@NotNull
@NotNull String key,
@Nullable
@Nullable List<String> value)
key - the key for the propertyvalue - the value for the propertypublic void setBoolean(@NotNull
@NotNull String key,
boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setBooleanIfNotNull(@NotNull
@NotNull String key,
@Nullable
@Nullable Boolean value)
key - the key for the propertyvalue - the value for the propertypublic void setFloat(@NotNull
@NotNull String key,
float value)
key - the key for the propertyvalue - the value for the propertypublic void setInt(@NotNull
@NotNull String key,
int value)
key - the key for the propertyvalue - the value for the propertypublic void setIntIfNotNull(@NotNull
@NotNull String key,
@Nullable
@Nullable Integer value)
key - the key for the propertyvalue - the value for the propertypublic void mergeProperties(@NotNull
@NotNull 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(@NotNull
@NotNull 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(@NotNull
@NotNull 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 properties@Nullable public @Nullable File getFile(@NotNull @NotNull String key)
key - the key to lookup within the properties fileprotected File getDataFile(@NotNull @NotNull String key)
This method will check the configured base directory and will use this as the base of the file path. Additionally, if the base directory begins with a leading "[JAR]\" sequence with the path to the folder containing the JAR file containing this class.
key - the key to lookup within the properties filepublic String getString(@NotNull @NotNull String key, @Nullable @Nullable String defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value for the requested propertypublic File getTempDirectory() throws IOException
IOException - if any.public String getString(@NotNull @NotNull String key)
key - the key to lookup within the properties filepublic String[] getArray(@NotNull @NotNull String key)
If the property is not set then null will be returned.
key - the key to get from this
Settings.null if the key wasn't present.public void removeProperty(@NotNull
@NotNull String key)
key - the property key to removepublic int getInt(@NotNull
@NotNull 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(@NotNull
@NotNull String key,
int defaultValue)
key - the key to lookup within the properties filedefaultValue - the default value to returnpublic long getLong(@NotNull
@NotNull 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(@NotNull
@NotNull 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(@NotNull
@NotNull String key,
boolean 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 float getFloat(@NotNull
@NotNull 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 java.io.IOException occurs of
course...public File getH2DataDirectory() throws IOException
IOException - is thrown if an java.io.IOException occurs of
course...public File getTempFile(@NotNull @NotNull String prefix, @NotNull @NotNull String extension) throws IOException
prefix - the prefix for the file name to generateextension - the extension of the generated file nameIOException - if any.Copyright © 2012–2020 OWASP. All rights reserved.