public class ConfigurationTools
extends java.lang.Object
Configurations from the
corresponding type to strings and back.| Constructor and Description |
|---|
ConfigurationTools() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkConfigurationForNulls(Configuration conf,
java.lang.StringBuilder sb,
java.lang.String[] keys)
Checks whether the given configuration contains every given key and if
every property is set.
|
static Triple<java.math.BigInteger,java.math.BigInteger,java.math.BigInteger> |
createKeyPair(int keySize)
Creates a RSA key pair and returns the modulus, the public and the private
exponent.
|
static boolean |
encryptPassword(Configuration conf,
java.lang.String key,
java.lang.String password,
java.util.logging.Logger logger,
java.io.PrintStream ps)
Encrypts the designated password and stores it under the designated configuration key name in
the designated configuration.
|
static java.lang.String |
encryptPassword(java.lang.String password)
Encrypts the designated password string with the public key of the
AristaFlow configuration framework and encodes the resulting string as
Base64 (non-strict since it does not contain line breaks).
|
static java.lang.String |
getConfigurationDump(Configuration conf)
Gets the complete content of the designated configuration as appropriately
formatted string.
|
protected static java.time.format.DateTimeFormatter |
getDateOptTimeFormatter(java.time.format.DateTimeFormatter timeElementFormatter)
Gets the formatter for a date with an optional time and an optional offset in a string.
|
protected static java.time.format.DateTimeFormatter |
getDateTimeFormatter(java.time.format.DateTimeFormatter dateTimeFormatter)
Gets the designated formatter initialised with default values for the temporal fields.
|
static java.util.List<java.lang.String> |
getList(Configuration conf,
java.lang.String key)
A convenience method for
ImmutableConfiguration.getList(String) that calls
getList on the designated configuration with the designated key and
converts the result to a list of strings or an empty list. |
static java.util.List<java.lang.String> |
getList(java.util.List<java.lang.Object> list)
Since the signature of
ImmutableConfiguration.getList(String) changed, we
could use this tool method to 'cast' the list of objects to a list of
strings. |
protected static java.time.format.DateTimeFormatter |
getTimeElementFormatterComma()
Gets a formatter for a time string using
, as decimal point for the fraction of a
second. |
protected static java.time.format.DateTimeFormatter |
getTimeElementFormatterDot()
Gets a formatter for a time string using
. |
protected static java.time.format.DateTimeFormatter |
getTimeFormatter(java.time.format.DateTimeFormatter timeElementFormatter)
Gets the formatter for a time with an optional offset in a string.
|
static boolean |
insertNewGsmKeyPair(Configuration conf,
int keySize,
java.lang.String modConfKey,
java.lang.String pubConfKey,
java.lang.String privConfKey,
java.util.logging.Logger logger,
java.io.PrintStream ps)
Creates a new RSA key pair for the global security manager and stores it in the designated
configuration using the appropriate configuration variables (modulus, public and private
exponent).
|
static CompositeConfiguration |
newCompositeConfiguration(Configuration inMemoryConf)
Creates a new
CompositeConfiguration allowing to combine several configurations. |
static DatabaseConfiguration |
newDatabaseConfiguration(javax.sql.DataSource dataSource,
java.lang.String tableName,
java.lang.String keyColumn,
java.lang.String valueColumn)
Creates a new
DatabaseConfiguration using the designated table and columns to
store the configuration in the designated data source. |
static MapConfiguration |
newMapConfiguration(java.util.Map<java.lang.String,java.lang.String> values)
Creates a new
AbstractConfiguration containing the designated values (if
provided). |
static MapConfiguration |
newMapConfiguration(java.util.Map<java.lang.String,java.lang.String> values,
boolean handleListDelimiters)
Creates a new
AbstractConfiguration containing the designated values (if
provided). |
static PropertiesConfiguration |
newPropertiesConfiguration()
Creates a new empty
PropertiesConfiguration. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.io.File file)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated file. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.io.File file,
java.util.logging.Logger autosaveLogger)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated file. |
static PropertiesConfiguration |
newPropertiesConfiguration(java.io.InputStream is)
Creates a new
PropertiesConfiguration containing the contents of the designated
input stream. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.lang.String file)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated file. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.lang.String file,
java.util.logging.Logger autosaveLogger)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated file. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.net.URL url)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated URL. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.net.URL url,
java.io.InputStream is)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated input stream. |
static PropertiesFileConfiguration |
newPropertiesConfiguration(java.net.URL url,
java.util.logging.Logger autosaveLogger)
Creates a new
PropertiesFileConfiguration containing the contents of the
designated URL. |
static java.lang.Boolean |
parseBoolean(java.lang.String booleanValue)
Parses the designated string and returns the corresponding boolean value.
|
static java.lang.String[] |
parseCSVString(java.lang.String csvString,
java.lang.String separator)
Splits the given CSV string around the designated separator and removes
whitespace at the start and end of each resulting token.
|
static java.util.Date |
parseDate(java.lang.String dateValue)
Parses the designated string and returns the corresponding date value or
null in case the value cannot be parsed or is not a valid
date. |
static java.lang.Double |
parseFloat(java.lang.String floatValue)
Parses the designated string and returns the corresponding float value or
null in case the value cannot be parsed or is not a valid
float. |
static java.lang.Long |
parseInteger(java.lang.String integerValue)
Parses the designated string and returns the corresponding integer value or
null in case the value cannot be parsed or is not a valid
integer. |
static java.lang.String |
parsePassword(Configuration configuration,
java.lang.String propertyName)
Parses the property's value in the designated configuration as a string,
decodes and decrypts it and returns the resulting string.
|
static java.lang.String |
parsePassword(java.lang.String password)
Parses the property's value in the designated configuration as a string,
decodes and decrypts it and returns the resulting string.
|
static java.lang.String |
parsePasswordTolerant(Configuration configuration,
java.lang.String propertyName)
Parses the property's value in the designated configuration as a string,
decodes and decrypts it and returns the resulting string.
|
static java.lang.String |
parsePasswordTolerant(java.lang.String password)
Parses the property's value in the designated configuration as a string,
decodes and decrypts it and returns the resulting string.
|
static byte[] |
parseUDT(java.lang.String udtValue)
Parses the designated string and returns the corresponding UDT-value (as
byte-array) or
null in case the value cannot be parsed or is
not a valid byte[]. |
static java.net.URI |
parseURI(Configuration configuration,
java.lang.String propertyName)
Parses the property's value in the given configuration and returns it as a
URI. |
static java.net.URI |
parseURI(java.lang.String uriValue)
Parses the designated string and returns the corresponding URI or
null in case the value cannot be parsed or is not a valid URI. |
static boolean |
propertyPresent(Configuration configuration,
java.lang.String key)
Checks whether the value for the designated key in the designated
configuration is not null and if it is a string, it is not the empty
string.
|
static boolean |
propertyValuePresent(Configuration configuration,
java.lang.String key)
Checks whether the value for the designated key in the designated
configuration is not null and not the empty string.
|
static boolean |
stringValid(java.lang.String validString)
Checks whether the designated string is not null and not the empty string.
|
static java.lang.String |
toString(boolean booleanValue)
Converts the designated boolean value to a string for usage in
configurations when manually editing these.
|
static java.lang.String |
toString(byte[] udtValue)
Converts the designated byte[] to a string for usage in configurations when
manually editing these.
|
static java.lang.String |
toString(java.util.Date dateValue)
Converts the designated date to a string for usage in configurations when
manually editing these.
|
static java.lang.String |
toString(double floatValue)
Converts the designated float value to a string for usage in
configurations when manually editing these.
|
static java.lang.String |
toString(long integerValue)
Converts the designated integer value to a string for usage in
configurations when manually editing these.
|
static java.lang.String |
toString(java.net.URI uriValue)
Converts the designated URI to a string for usage in configurations when
manually editing these.
|
public static java.lang.Boolean parseBoolean(java.lang.String booleanValue)
toString(boolean) to convert a boolean value to a string.booleanValue - The string representation of a boolean value to be
converted.null in
case the string is null.public static java.lang.String toString(boolean booleanValue)
Configuration-interface directly,
the conversion will be handled internally. parseBoolean(String) to convert a string back to a boolean.booleanValue - The boolean value to be represented as a string.public static java.lang.Long parseInteger(java.lang.String integerValue)
null in case the value cannot be parsed or is not a valid
integer. Use toString(long) to convert an integer value to a
string.integerValue - The string representation of an integer value to be
converted.null in
case the designated string cannot be parsed to a valid integer.public static java.lang.String toString(long integerValue)
Configuration-interface directly,
the conversion will be handled internally. parseInteger(String) to convert a string back to an integer.integerValue - The integer value to be represented as a string.public static java.lang.Double parseFloat(java.lang.String floatValue)
null in case the value cannot be parsed or is not a valid
float. Use toString(double) to convert a float value to a string.floatValue - The string representation of a float value to be
converted.null in
case the designated string cannot be parsed to a valid float.public static java.lang.String toString(double floatValue)
Configuration-interface directly,
the conversion will be handled internally. parseFloat(String) to convert a string back to a float.floatValue - The float value to be represented as a string.public static java.net.URI parseURI(java.lang.String uriValue)
null in case the value cannot be parsed or is not a valid URI.
Use toString(URI) to convert a URI to a string.uriValue - The string representation of the URI to be converted.null in case
the designated string cannot be parsed to a valid URI.public static java.lang.String toString(java.net.URI uriValue)
Configuration-interface directly,
the conversion will be handled internally. parseURI(String) to convert a string back to a URI.uriValue - The URI to be represented as a string.NullArgumentException - If the designated URI is null,
a NullArgumentException will be thrown.public static java.util.Date parseDate(java.lang.String dateValue)
null in case the value cannot be parsed or is not a valid
date. Use toString(Date) to convert a date value to a string.
The following grammar is used for parsing:
datetime = date-opt-time | time
date-opt-time = date-element ['T' [time-element] [offset]]
date-element = yyyy ['-' MM ['-' dd]]
time = 'T' time-element [offset]
time-element = HH [':' mm [':' ss [fraction]]]
fraction = ('.' | ',') digit+
offset = 'Z' | (('+' | '-') HH [':' mm [':' ss [('.' | ',') SSS]]])
If the string representation does not contain a time zone or zone offset, UTC will be assumed.dateValue - The string representation of a date value to be converted.null in
case the designated string cannot be parsed to a valid date.protected static java.time.format.DateTimeFormatter getDateTimeFormatter(java.time.format.DateTimeFormatter dateTimeFormatter)
dateTimeFormatter - The date time formatter missing default values for the temporal
fields.protected static java.time.format.DateTimeFormatter getTimeFormatter(java.time.format.DateTimeFormatter timeElementFormatter)
timeElementFormatter - The formatter for the time element part.protected static java.time.format.DateTimeFormatter getDateOptTimeFormatter(java.time.format.DateTimeFormatter timeElementFormatter)
timeElementFormatter - The formatter for the time element part.protected static java.time.format.DateTimeFormatter getTimeElementFormatterDot()
. as decimal point for the fraction of a
second.. as decimal point for the fraction of
a second.protected static java.time.format.DateTimeFormatter getTimeElementFormatterComma()
, as decimal point for the fraction of a
second., as decimal point for the fraction of
a second.public static java.lang.String toString(java.util.Date dateValue)
Configuration-interface directly,
the conversion will be handled internally. parseDate(String) to convert a string back to a date.dateValue - The date to be represented as a string.NullArgumentException - If the designated date is null,
a NullArgumentException will be thrown.public static byte[] parseUDT(java.lang.String udtValue)
null in case the value cannot be parsed or is
not a valid byte[]. Use toString(byte[]) to convert a byte-array
to a string.udtValue - The string representation of the UDT-value to be converted or null
if the designated string is null.null in case
the designated string cannot be parsed to a valid UDT-value.public static java.lang.String toString(byte[] udtValue)
throws java.io.IOException
Configuration-interface directly,
the conversion will be handled internally. parseUDT(String) to convert a string back to an UDT-value.udtValue - The UDT-value to be represented as a string.NullArgumentException - If the designated UDT-value is
null, a NullArgumentException will be
thrown.java.io.IOException - If there are problems encoding the designated UDT value to Base64, an
IOException will be thrown.public static final boolean stringValid(java.lang.String validString)
validString - The string to check.validString != null && validString.length() > 0public static final boolean propertyValuePresent(Configuration configuration, java.lang.String key)
configuration - The configuration which contain a value for the
designated key (or not).key - The key for which to check the value of the property.stringValid(configuration.getProperty(key))public static final boolean propertyPresent(Configuration configuration, java.lang.String key)
configuration - The configuration which contain a value for the
designated key (or not).key - The key for which to check the value of the property.propertyValuePresent(configuration.getString(key)) or a non-string
is != null.public static final boolean checkConfigurationForNulls(Configuration conf, java.lang.StringBuilder sb, java.lang.String[] keys)
conf - The configuration that should be checked.sb - The string builder where the missing keys are appended, if not
null.keys - The configuration keys that should be checked.public static java.lang.String[] parseCSVString(java.lang.String csvString,
java.lang.String separator)
csvString - The string representing the multi-valued string.separator - The string which separates the values of the property.public static java.net.URI parseURI(Configuration configuration, java.lang.String propertyName)
URI. The property is expected to be set and of the correct type.configuration - the configuration containing the property valuepropertyName - the name of property whose value should be parsedURI or null in case
the property value could not be parsed as URI.public static java.lang.String getConfigurationDump(Configuration conf)
conf - The configuration for which to get the complete content.public static Triple<java.math.BigInteger,java.math.BigInteger,java.math.BigInteger> createKeyPair(int keySize) throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
keySize - The size of the key to create.java.security.NoSuchAlgorithmException - If no RSA algorithm can be found, a
NoSuchAlgorithmException will be thrown.java.security.spec.InvalidKeySpecException - If the key spec for the private RSA key
cannot be found, an InvalidKeySpecException will be
thrown.public static boolean insertNewGsmKeyPair(Configuration conf, int keySize, java.lang.String modConfKey, java.lang.String pubConfKey, java.lang.String privConfKey, java.util.logging.Logger logger, java.io.PrintStream ps)
conf - The configuration in which to store the key pair attributes.keySize - The size of the RSA key.modConfKey - The name of the configuration key with which to store the modulus of the key
pair.pubConfKey - The name of the configuration key with which to store the public exponent of
the key pair.privConfKey - The name of the configuration key with which to store the private exponent
of the key pair.logger - The logger to track the progress and problems. This may be null.ps - A print stream to track the progress and problems. This may be null.public static java.lang.String encryptPassword(java.lang.String password)
throws java.security.GeneralSecurityException
password - The password string to encrypt and encode.java.security.GeneralSecurityException - If there are problems encrypting the
password, a GeneralSecurityException will be thrown.public static boolean encryptPassword(Configuration conf, java.lang.String key, java.lang.String password, java.util.logging.Logger logger, java.io.PrintStream ps)
conf - The configuration in which to store the password and from which to optionally read
the password.key - The configuration key name under which to store the password and optionally with
which to read the password.password - The password to be encrypted and stored in the designated configuration. If
this is null, the password will be read with the designated configuration
key name from the designated configuration.logger - The logger to track the progress and problems. This may be null.ps - A print stream to track the progress and problems. This may be null.public static final java.lang.String parsePassword(Configuration configuration, java.lang.String propertyName) throws java.security.GeneralSecurityException
configuration - The configuration containing the property valuepropertyName - The name of property of which the value should be
parsed and decrypted.String or the empty string in case the password is
empty.java.security.GeneralSecurityException - If there are problems decrypting the
property value, a GeneralSecurityException will be
thrown.public static final java.lang.String parsePassword(java.lang.String password)
throws java.security.GeneralSecurityException
password - The encrypted password.String or the empty string in case the password is
empty.java.security.GeneralSecurityException - If there are problems decrypting the
property value, a GeneralSecurityException will be
thrown.public static final java.lang.String parsePasswordTolerant(Configuration configuration, java.lang.String propertyName)
configuration - The configuration containing the property valuepropertyName - The name of property of which the value should be
parsed and decrypted or simply returned.String or the property value directly in case it
cannot be decrypted.public static final java.lang.String parsePasswordTolerant(java.lang.String password)
password - The possibly encrypted password.public static java.util.List<java.lang.String> getList(Configuration conf, java.lang.String key)
ImmutableConfiguration.getList(String) that calls
getList on the designated configuration with the designated key and
converts the result to a list of strings or an empty list.conf - The configuration from which to retrieve the list.key - The configuration key.public static java.util.List<java.lang.String> getList(java.util.List<java.lang.Object> list)
ImmutableConfiguration.getList(String) changed, we
could use this tool method to 'cast' the list of objects to a list of
strings.list - A list of objects.public static MapConfiguration newMapConfiguration(java.util.Map<java.lang.String,java.lang.String> values)
AbstractConfiguration containing the designated values (if
provided).values - The values to be in the base configuration or null for an empty
configuration.public static MapConfiguration newMapConfiguration(java.util.Map<java.lang.String,java.lang.String> values, boolean handleListDelimiters)
AbstractConfiguration containing the designated values (if
provided).values - The values to be in the base configuration or null for an empty
configuration.handleListDelimiters - Whether to handle list delimiters within strings.public static PropertiesConfiguration newPropertiesConfiguration()
PropertiesConfiguration.public static PropertiesConfiguration newPropertiesConfiguration(java.io.InputStream is) throws ConfigurationException
PropertiesConfiguration containing the contents of the designated
input stream.is - The input stream to read into the new properties configuration or null
for an empty configuration.ConfigurationException - If creating the configuration or loading from the stream fails,
a ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.net.URL url, java.io.InputStream is) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated input stream.url - The URL specifying the properties file. This is merely for information purpose. If
you do not have an URL use newPropertiesConfiguration(InputStream).is - The input stream to read the configuration from.ConfigurationException - If creating the configuration or loading from the stream fails,
a ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.lang.String file) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated file.file - The file to read into the new properties configuration or null for an
empty configuration.ConfigurationException - If creating the configuration or loading the file fails, a
ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.lang.String file, java.util.logging.Logger autosaveLogger) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated file.file - The file to read into the new properties configuration or null for an
empty configuration.autosaveLogger - Whether to automatically save changes to the underlying file. If so,
problems will be logged to this logger. Use null to not automatically
save changes.ConfigurationException - If creating the configuration or loading the file fails, a
ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.io.File file) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated file.file - The file to read into the new properties configuration or null for an
empty configuration.ConfigurationException - If creating the configuration or loading the file fails, a
ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.io.File file, java.util.logging.Logger autosaveLogger) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated file.file - The file to read into the new properties configuration or null for an
empty configuration.autosaveLogger - Whether to automatically save changes to the underlying file. If so,
problems will be logged to this logger. Use null to not automatically
save changes.ConfigurationException - If creating the configuration or loading the file fails, a
ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.net.URL url) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated URL.url - The URL which to read into the new properties configuration or null for
an empty configuration.ConfigurationException - If creating the configuration or loading from the URL fails, a
ConfigurationException will be thrown.public static PropertiesFileConfiguration newPropertiesConfiguration(java.net.URL url, java.util.logging.Logger autosaveLogger) throws ConfigurationException
PropertiesFileConfiguration containing the contents of the
designated URL.url - The URL which to read into the new properties configuration or null for
an empty configuration.autosaveLogger - Whether to automatically save changes to the underlying file. If so,
problems will be logged to this logger. Use null to not automatically
save changes.ConfigurationException - If creating the configuration or loading from the URL fails, a
ConfigurationException will be thrown.public static DatabaseConfiguration newDatabaseConfiguration(javax.sql.DataSource dataSource, java.lang.String tableName, java.lang.String keyColumn, java.lang.String valueColumn) throws ConfigurationException
DatabaseConfiguration using the designated table and columns to
store the configuration in the designated data source. This is a simple database configuration
as provided by Commons Configuration, that is, the existence of the table is not handled. If
you want this, use
UrlConfigurationManager.newDatabaseConfiguration(Logger, de.aristaflow.adept2.base.dbaccess.JDBCDataSource, String, String, String).dataSource - The datasource which stores the configuration.tableName - The name of the table containing the configuration values.keyColumn - The name of the column containing the configuration keys.valueColumn - The name of the column containing the configuration values.ConfigurationException - If creating the configuration fails, a
ConfigurationException will be thrown.public static CompositeConfiguration newCompositeConfiguration(Configuration inMemoryConf)
CompositeConfiguration allowing to combine several configurations.
If a configuration is provided, this will be the in memory configuration in which all changes
of the returned composite configuration values will be stored.inMemoryConf - The in memory configuration in which all changes of the returned composite
configuration values will be stored. This may be null.