public class ExtendedProperties extends Properties
2) Allows specifying boolean properties in the form -key. Such format is equivalent to key=true.
3) Allows importing properties from external property files by means of the special key
import. E.g. specifying the property
import = a-property-file-name
results in automatically adding all properties defined in the specified property file
4) Allows declaring a property as read-only. In order to do that it is sufficient to end its key with a '!'. For example:
agentClass!=com.hp.agent.FooThe value of the property can be accessed including the '!' in the key or not indifferently
This class is designed to be usable in the restrictive J2ME CDC environment.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IMPORT_KEY |
Constructor and Description |
---|
ExtendedProperties()
Construct empty property collection.
|
ExtendedProperties(java.lang.String[] propesStr)
Construct a ExtendedProperties object from an array of stringified properties of the form
|
Modifier and Type | Method and Description |
---|---|
protected void |
addFromReader(java.io.Reader reader)
Add properties from Reader.
|
void |
addProperties(java.lang.String[] propsStr)
Add to this Properties object the stringified properties included in a given array.
|
protected void |
addProperty(java.lang.String propStr)
Add to this Properties object a stringified property of the form
key = value or -key
|
void |
copyProperties(ExtendedProperties source)
Copy a data from standard Properties.
|
java.lang.String |
doSubstitutions(java.lang.String anInputString)
Replace all substrings of the form ${xxx} with the property value
using the key xxx.
|
java.lang.String |
doSubstitutions(java.lang.String anInputString,
boolean allowUndefined)
Replace all substrings of the form ${xxx} with the property value
using the key xxx.
|
ExtendedProperties |
extractSubset(java.lang.String prefix)
Create a new Properties object by coping those
properties whose key begins with a particular prefix string.
|
java.lang.Object |
get(java.lang.Object aKey)
Get the object associated with a key.
|
boolean |
getBooleanProperty(java.lang.String aKey,
boolean aDefaultValue)
Extract a string value ("true" or "false") and convert it to
a boolean.
|
int |
getIntProperty(java.lang.String aKey,
int aDefaultValue)
Extract a string value and convert it to an integer.
|
protected java.lang.String |
getOneLine(java.io.Reader reader)
Get a logical line.
|
java.lang.String |
getProperty(java.lang.String aKey)
Override getProperty in base class so all occurances of
the form ${key} are replaced by their
associated value.
|
java.lang.String |
getProperty(java.lang.String aKey,
java.lang.String defaultValue)
Perform substitution when a value is fetched.
|
java.lang.String |
getPropertyIgnoreCase(java.lang.String aKey)
Use this method to fetch a property ignoring case of key.
|
java.lang.String |
getRawProperty(java.lang.String aKey)
Fetch property value for key which may contain strings
of the form ${key}.
|
protected int |
getSeparatorIndex(java.lang.String propStr)
Retrieve the position of the first valid key-value separator character ('=' or ':') in
a stringified property.
|
void |
list(java.io.PrintStream out)
List properties to provided PrintStream.
|
void |
load(java.io.InputStream inStream)
Add properties from a specified InputStream.
|
static void |
main(java.lang.String[] args)
For testing.
|
java.lang.Object |
put(java.lang.Object aKey,
java.lang.Object aValue)
Set property value to specified object.
|
protected java.lang.String |
readLine(java.io.Reader aReader)
Read one line from the Reader.
|
java.lang.Object |
renameKey(java.lang.String existingKey,
java.lang.String newKey)
Change key string associated with existing value.
|
void |
setBooleanProperty(java.lang.String aKey,
boolean aValue)
Store a boolean as a string ("true" or "false") with the specified key.
|
int |
setIntProperty(java.lang.String aKey,
int aValue)
Store an int as a string with the specified key.
|
java.lang.Object |
setPropertyIfNot(java.lang.String aKey,
java.lang.String value)
Set property value only if its not set already.
|
java.util.Enumeration |
sortedKeys()
Return a sorted enumeration of this properties keys.
|
void |
store(java.io.OutputStream out,
java.lang.String header)
Writes this property collection to the output stream in a format suitable for
loading into a Properties table using the load method.
|
java.lang.String[] |
toStringArray()
Create a String[] for the properties with one key=value pair per array entry.
|
protected java.lang.String |
valueFilter(java.lang.String key,
java.lang.String value)
Called by getProperty(key, default) to perform any post processing of the
value string.
|
load, store, toLeapProperties
list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML, stringPropertyNames
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, values
public static final java.lang.String IMPORT_KEY
public ExtendedProperties()
public ExtendedProperties(java.lang.String[] propesStr)
propesStr
- The applications original arguments.public static void main(java.lang.String[] args)
public void load(java.io.InputStream inStream) throws java.io.IOException
load
in class java.util.Properties
aFileName
- The name of the file.java.io.IOException
- if anything goes wrong.public void store(java.io.OutputStream out, java.lang.String header) throws java.io.IOException
store
in class java.util.Properties
out
- An output stream.header
- A description of the property list - may be null.java.io.IOException
- if anything goes wrong.public java.util.Enumeration sortedKeys()
public void addProperties(java.lang.String[] propsStr)
propsStr
- The array of stringified properties. If null, this method does nothing.protected void addProperty(java.lang.String propStr)
propStr
- The string representation of the property to be parsedprotected int getSeparatorIndex(java.lang.String propStr)
propStr
- The stringified property.public void copyProperties(ExtendedProperties source)
source
- The properties to copy from.public ExtendedProperties extractSubset(java.lang.String prefix)
prefix
- The prefix string. Ex: "server."public java.lang.Object get(java.lang.Object aKey)
get
in interface java.util.Map<java.lang.Object,java.lang.Object>
get
in class java.util.Hashtable<java.lang.Object,java.lang.Object>
aKey
- Key for desired property.public java.lang.Object put(java.lang.Object aKey, java.lang.Object aValue)
put
in interface java.util.Map<java.lang.Object,java.lang.Object>
put
in class java.util.Hashtable<java.lang.Object,java.lang.Object>
aKey
- The key used to store the data. The key may contain strings of
the form ${key} which will be evaluated first.aValue
- The object to be stored.public java.lang.String getProperty(java.lang.String aKey)
getProperty
in class java.util.Properties
aKey
- Key for desired property.public java.lang.String getProperty(java.lang.String aKey, java.lang.String defaultValue)
getProperty
in class java.util.Properties
aKey
- The property key.defaultValue
- Value to return if property not defined. May be null.
If non null it will be passes to valueFilter first.PropertiesException
- if circular definition.public java.lang.Object setPropertyIfNot(java.lang.String aKey, java.lang.String value)
aKey
- The key used to store the data. The key may contain strings of
the form ${key} which will be evaluated first.value
- The value to be stored.public java.lang.String getRawProperty(java.lang.String aKey)
aKey
- Key for desired property.public java.lang.String getPropertyIgnoreCase(java.lang.String aKey)
aKey
- The key of the environment property.protected java.lang.String valueFilter(java.lang.String key, java.lang.String value)
key
- The properties key.value
- The properties value.public int getIntProperty(java.lang.String aKey, int aDefaultValue)
aKey
- The key which will be used to fetch the attribute.aDefaultValue
- Specifies the default value for the int.public int setIntProperty(java.lang.String aKey, int aValue)
aKey
- The key which will be used to store the attribute.aValue
- The int value.public boolean getBooleanProperty(java.lang.String aKey, boolean aDefaultValue)
aKey
- The key which will be used to fetch the attribute.aDefaultValue
- Specifies the default value for the boolean.public void setBooleanProperty(java.lang.String aKey, boolean aValue)
aKey
- The key which will be used to store the attribute.aValue
- The boolean value.public java.lang.Object renameKey(java.lang.String existingKey, java.lang.String newKey)
existintKey
- The current key.newKey
- The new key.public java.lang.String doSubstitutions(java.lang.String anInputString)
anInputString
- The input string - may be null.public java.lang.String doSubstitutions(java.lang.String anInputString, boolean allowUndefined)
anInputString
- The input string - may be null.allowUndefined
- If true, undefined strings will remain as is,
if false, an exception will be thrown.protected void addFromReader(java.io.Reader reader) throws java.io.IOException
reader
- The buffered reader to read from.
to catch circular imports.java.io.IOException
- if anything goes wrong.protected java.lang.String getOneLine(java.io.Reader reader) throws java.io.IOException
reader
- The input reader to read.java.io.IOException
- if anything goes wrong.protected java.lang.String readLine(java.io.Reader aReader) throws java.io.IOException
aReader
- The Reader to read characters from.java.io.IOException
- if anything goes wrong.public void list(java.io.PrintStream out)
list
in class java.util.Properties
out
- The print stream.public java.lang.String[] toStringArray()