|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.CompositeConfiguration
de.fu_berlin.ties.TiesConfiguration
public class TiesConfiguration
A composite configuration that allows to localize of keys and to querying types and descriptions of entries.
Nested Class Summary | |
---|---|
class |
TiesConfiguration.EntryDescriptor
An inner class wrapping descriptor information on an entry: type of the entry, whether it is optional or a list, a description of the entry. |
Field Summary | |
---|---|
static TiesConfiguration |
CONF
The main configuration object for TIES, loaded via TiesConfiguration(String) using "ties" as base name. |
static String |
CONF_DIR
The subdirectory in the class path containing config files. |
static String |
CONF_EXTENSION
The extension of config files in PropertiesConfiguration
format. |
static String |
CONFIG_GOAL_PREFIX
Configuration key prefix mapping goals to fully qualified class names. |
static String |
CONFIG_LANG
Special configuration key: the language of documents, using the ISO 639 language codes (2-letter codes where available, e.g. |
static String |
DESC_EXTENSION
The extension of descriptor configuration files (in PropertiesConfiguration format). |
static String |
XML_EXTENSION
The extension of config files in XML format. |
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
---|
END_TOKEN, START_TOKEN |
Constructor Summary | |
---|---|
TiesConfiguration()
Creates a new empty instance. |
|
TiesConfiguration(Configuration config,
Configuration desc)
Creates a new instance, delegating to addConfiguration(Configuration, Configuration) . |
|
TiesConfiguration(String baseName)
Creates a new instance, delegating to load(String) . |
Method Summary | |
---|---|
String |
adaptKey(String baseKey,
String suffix)
Creates a adapted (caller-specific) key by joining a base name with a suffix. |
void |
addConfiguration(Configuration config,
Configuration desc)
Adds a configuration and a corresponding descriptor config. |
void |
addDescriptorConfig(Configuration desc)
Adds a descriptor configuration that can be consulted to query the type and use of a entries. |
static boolean |
arrayIsEmpty(String[] array)
Utility method that thorougly checks whether a string array is empty. |
List<String> |
configureFromArgs(String[] args)
Modifies configuration properties from [+|-]key[=value]
pairs in a string array. |
void |
flatten(Configuration appender)
Copies all properties contained in this instance to a given configuration. |
TiesConfiguration.EntryDescriptor |
getDescriptor(String key)
Returns the descriptor for a given key, if any is given in the descriptor configuration. |
Object |
getProperty(String key)
Read a property from this configuration. |
String[] |
getStringArray(String key)
Get an array of strings associated with the given configuration key. |
static String |
joinKey(String prefix,
String suffix)
Creates a full key by joining a prefix and a suffix string, separated by the property delimiter. |
static boolean |
listIsEmpty(List list)
Utility method that thorougly checks whether a list is empty. |
void |
load(String baseName)
Loads configuration in PropertiesConfiguration or
XML
format. |
String |
localizeKey(String baseKey)
Creates a localized (language-specific) key by joining a base name with the configured language suffix (value mapped to the CONFIG_LANG } key (if this key doesn't exist, the language of
default locale used by the Java Virtual Machine is used). |
void |
modifyProperty(String keyValue,
boolean overwrite)
Modifies a configuration property, parsing a key[=value]
pair. |
static boolean |
propertyIsEmpty(Object object)
Utility method that thorougly checks whether a property (as returned by Configuration.getProperty(String) is empty. |
void |
save(File file)
Saves the contents of this configuration in a file, storing them in PropertiesConfiguration format. |
void |
save(String filename)
Saves the contents of this configuration in a file, storing them in PropertiesConfiguration format. |
SortedSet |
sortedKeys()
Returns the list of keys contained in this configuration, sorted in alphabetic order. |
SortedSet<Object> |
sortedKeys(boolean inclNotSet)
Returns the list of keys contained in this configuration, sorted in alphabetic order. |
Configuration |
subset(String prefix)
Create an Configuration object that is a subset of this one. |
Methods inherited from class org.apache.commons.configuration.CompositeConfiguration |
---|
addConfiguration, addPropertyDirect, clear, clearProperty, containsKey, getConfiguration, getInMemoryConfiguration, getKeys, getKeys, getList, getNumberOfConfigurations, isEmpty, removeConfiguration |
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, getList, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, interpolate, interpolateHelper, isThrowExceptionOnMissing, resolveContainerStore, setDelimiter, setProperty, setThrowExceptionOnMissing |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final TiesConfiguration CONF
TiesConfiguration(String)
using "ties" as base name.
You should NOT modify the configuration properties stored in this
object, especially since it is not fully thread-safe (unless you know
what you're doing and are sure there are no other objects around that
might try to access the configuration, e.g. at the begin of a
program's main
method).
public static final String CONF_DIR
public static final String CONF_EXTENSION
PropertiesConfiguration
format.
public static final String XML_EXTENSION
public static final String DESC_EXTENSION
PropertiesConfiguration
format).
public static final String CONFIG_GOAL_PREFIX
public static final String CONFIG_LANG
Constructor Detail |
---|
public TiesConfiguration()
public TiesConfiguration(Configuration config, Configuration desc)
addConfiguration(Configuration, Configuration)
.
config
- the initial configuration to wrapdesc
- the initial descriptor config to wrap (cf.
addDescriptorConfig(Configuration)
for the required contents)public TiesConfiguration(String baseName)
load(String)
.
baseName
- the base name of the configurationMethod Detail |
---|
public String adaptKey(String baseKey, String suffix)
baseKey
- the basic keysuffix
- the suffix of the key; if null
the
baseKey
is returned
CONFIG_LANG
key; resp. the base form if the full key doesn't exist or
suffix
is null
joinKey(String, String)
public static boolean arrayIsEmpty(String[] array)
true
in three cases:
null
;
null
or an empty or blank (only whitespace) string.
TiesConfiguration
to return a single-element list containing
only an empty string. Usually such a list should be treated as empty.
array
- the array to check
true
iff the list is empty as described abovepublic static boolean listIsEmpty(List list)
true
in three cases:
null
;
null
or an empty or blank (only whitespace) string.
TiesConfiguration
to return a single-element list containing
only an empty string. Usually such a list should be treated as empty.
list
- the list to check
true
iff the list is empty as described abovepublic static boolean propertyIsEmpty(Object object)
Configuration.getProperty(String)
is empty. It returns
true
in two cases:
null
;
TiesConfiguration
to return an empty string.
object
- the object to check
true
iff the object is empty as described abovepublic static String joinKey(String prefix, String suffix)
prefix
- the prefix of the keysuffix
- the suffix of the key
public void addConfiguration(Configuration config, Configuration desc)
config
- the configuration to adddesc
- the descriptor config to add (cf.
addDescriptorConfig(Configuration)
for the required contents)public void addDescriptorConfig(Configuration desc)
desc
- the descriptor configuration to addpublic List<String> configureFromArgs(String[] args) throws IllegalArgumentException
[+|-]key[=value]
pairs in a string array. Delegates to
modifyProperty(String, boolean)
for each array element
starting with "-" (using overwrite mode) or "+" (using append mode).
Other array elements are collected and returned.
args
- the array of strings to parse
IllegalArgumentException
- if one of the
[+|-]key[=value]
pairs doesn't contain a key ("=" is second
character)public TiesConfiguration.EntryDescriptor getDescriptor(String key)
key
- the key to describe
null
is none
is givenpublic Object getProperty(String key)
getProperty
in interface Configuration
getProperty
in class CompositeConfiguration
key
- key to use for mapping
public String[] getStringArray(String key)
getStringArray
in interface Configuration
getStringArray
in class CompositeConfiguration
key
- The configuration key
public void flatten(Configuration appender)
appender
- the configuration to append all properties topublic void load(String baseName)
PropertiesConfiguration
or
XML
format. Combines configuration properties from several resources if
they exist:
baseName.xml
resp.
baseName.cfg
in the current working
directory, if they exist and are readable filesbaseName.xml
resp.
baseName.cfg
in the user's home
directory, if they exist and are readable filesbaseName.cfg
in the conf
subdirectory in the classpath (e.g. from a jar file) -- this
classpath resource should always exist (otherwise an warning will be
logged and later errors are likely)For shared keys, the first match will be returned. If corresponding
baseName.desc
exists, they are assumed to
contain descriptors.
*.cfg and *.desc files must must use the
PropertiesConfiguration
format, *.xml files must use the
XML
format.
The last resource loaded form the classpath must use UTF-8 character set (otherwise it could not be shared between systems). The other *.cfg and *.desc (local files) are assumed to use the platform's default character set. The character set of XML files is determined in the standard way.
baseName
- the base name of the configurationpublic String localizeKey(String baseKey)
CONFIG_LANG
} key (if this key doesn't exist, the language of
default locale used by the Java Virtual Machine is used).
If the localized form of the key doesn't exist in the specified
configuration, the base form is returned instead. Implemented by
delegating to adaptKey(String, String)
.
baseKey
- the basic key
CONFIG_LANG
keypublic void modifyProperty(String keyValue, boolean overwrite) throws IllegalArgumentException
key[=value]
pair. Both key and value are trimmed. Boolean.TRUE
is used as
default value if the =value
part is omitted.
If "=" is the last character (empty value) and overwrite
is
true
, the property is removed from the configuration
(Configuration.clearProperty(java.lang.String)
).
keyValue
- the key=value
pair to parseoverwrite
- whether to overwrite (replacing old value: Configuration.setProperty(java.lang.String, java.lang.Object)
) or
add (append to list, Configuration.addProperty(java.lang.String, java.lang.Object)
) the
value
IllegalArgumentException
- if keyValue
doesn't contain
a key ("=" is first character)public void save(File file) throws ConfigurationException
PropertiesConfiguration
format. The platform's default
character set is used.
file
- the file to use
ConfigurationException
- if an I/O error occurs during savingpublic void save(String filename) throws ConfigurationException
PropertiesConfiguration
format. The platform's default
character set is used.
filename
- the name of the file
ConfigurationException
- if an I/O error occurs during savingpublic SortedSet sortedKeys()
sortedKeys(boolean)
, setting
inclNotSet
to false
.
public SortedSet<Object> sortedKeys(boolean inclNotSet)
inclNotSet
- if true
, keys that are not contained in
this configuration but that described in the
descriptor configuration
are also included
public Configuration subset(String prefix)
subset
in interface Configuration
subset
in class AbstractConfiguration
prefix
- The prefix used to select the properties
TiesConfiguration
instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |