|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<String,String>
org.opencms.configuration.CmsParameterConfiguration
public class CmsParameterConfiguration
Provides convenient access to configuration parameters.
Usually the parameters are configured in some sort of String based file,
either in an XML configuration, or in a .property file.
This wrapper allows accessing such String values directly
as int
, boolean
or other data types, without
worrying about the type conversion.
It can also read a configuration from a special property file format, which is explained here:
key = value
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.escaped = Hi\, what'up?
Nested Class Summary | |
---|---|
protected static class |
CmsParameterConfiguration.ParameterReader
Used to read parameter lines from a property file. |
protected static class |
CmsParameterConfiguration.ParameterTokenizer
This class divides property value into tokens separated by ",". |
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
static CmsParameterConfiguration |
EMPTY_PARAMETERS
An empty, immutable parameter configuration. |
Constructor Summary | |
---|---|
CmsParameterConfiguration()
Creates an empty parameter configuration. |
|
CmsParameterConfiguration(InputStream in)
Creates a parameter configuration from an input stream. |
|
CmsParameterConfiguration(Map<String,String> configuration)
Creates a parameter configuration from a Map of Strings. |
|
CmsParameterConfiguration(String file)
Creates a parameter wrapper by loading the parameters from the specified property file. |
Method Summary | |
---|---|
void |
add(String key,
String value)
Add a parameter to this configuration. |
Element |
appendToXml(Element parentNode)
Serializes this parameter configuration for the OpenCms XML configuration. |
Element |
appendToXml(Element parentNode,
List<String> parametersToIgnore)
Serializes this parameter configuration for the OpenCms XML configuration. |
void |
clear()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
protected static int |
countPreceding(String line,
int index,
char ch)
Counts the number of successive times 'ch' appears in the 'line' before the position indicated by the 'index'. |
protected static boolean |
endsWithSlash(String line)
Checks if the line ends with odd number of backslashes. |
Set<Map.Entry<String,String>> |
entrySet()
|
String |
get(Object key)
Returns the String associated with the given parameter. |
boolean |
getBoolean(String key,
boolean defaultValue)
Returns the boolean associated with the given parameter, or the default value in case there is no boolean value for this parameter. |
int |
getInteger(String key,
int defaultValue)
Returns the integer associated with the given parameter, or the default value in case there is no integer value for this parameter. |
List<String> |
getList(String key)
Returns the List of Strings associated with the given parameter, or an empty List in case there is no List of Strings for this parameter. |
List<String> |
getList(String key,
List<String> defaultValue)
Returns the List of Strings associated with the given parameter, or the default value in case there is no List of Strings for this parameter. |
Object |
getObject(String key)
Returns the raw Object associated with the given parameter, or null in case there is no Object for this parameter. |
String |
getString(String key,
String defaultValue)
Returns the String associated with the given parameter, or the given default value in case there is no value for this parameter. |
int |
hashCode()
|
Set<String> |
keySet()
|
void |
load(InputStream input)
Load the parameters from the given input stream, which must be in property file format. |
String |
put(String key,
String value)
Set a parameter for this configuration. |
void |
putAll(Map<? extends String,? extends String> other)
Merges this parameter configuration with the provided other parameter configuration. |
String |
remove(Object key)
Removes a parameter from this configuration. |
String |
toString()
|
protected static String |
unescape(String value)
Replaces escaped char sequences in the input value. |
static CmsParameterConfiguration |
unmodifiableVersion(CmsParameterConfiguration original)
Returns an unmodifiable version of this parameter configuration. |
Collection<String> |
values()
|
Methods inherited from class java.util.AbstractMap |
---|
clone, equals, isEmpty, size |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final CmsParameterConfiguration EMPTY_PARAMETERS
Constructor Detail |
---|
public CmsParameterConfiguration()
public CmsParameterConfiguration(InputStream in) throws IOException
in
- the input stream to create the parameter configuration from
IOException
- in case of errors loading the parameters from the input streampublic CmsParameterConfiguration(Map<String,String> configuration)
configuration
- the map of Strings to create the parameter configuration frompublic CmsParameterConfiguration(String file) throws IOException
file
- the path of the file to load
IOException
- in case of errors loading the parameters from the specified property fileMethod Detail |
---|
public static CmsParameterConfiguration unmodifiableVersion(CmsParameterConfiguration original)
original
- the configuration to make unmodifiable
protected static int countPreceding(String line, int index, char ch)
line
- the line to countindex
- the index position to startch
- the character to count
protected static boolean endsWithSlash(String line)
line
- the line to check
true
if the line ends with odd number of backslashesprotected static String unescape(String value)
value
- the value to unescape
public void add(String key, String value)
If the parameter already exists then the value will be added to the existing configuration entry and a List will be created for the values.
String values separated by a comma "," will NOT be tokenized when this method is used. To create a List of String values for a parameter, call this method multiple times with the same parameter name.
key
- the parameter to addvalue
- the value to addpublic Element appendToXml(Element parentNode)
For each parameter, a XML node like this
<param name="theName">theValue</param>
is generated and appended to the provided parent node.
parentNode
- the parent node where the parameter nodes are appended to
public Element appendToXml(Element parentNode, List<String> parametersToIgnore)
For each parameter, a XML node like this
<param name="theName">theValue</param>
is generated and appended to the provided parent node.
parentNode
- the parent node where the parameter nodes are appended toparametersToIgnore
- if not null
,
all parameters in this list are not written to the XML
public void clear()
clear
in interface Map<String,String>
clear
in class AbstractMap<String,String>
Map.clear()
public boolean containsKey(Object key)
containsKey
in interface Map<String,String>
containsKey
in class AbstractMap<String,String>
Map.containsKey(java.lang.Object)
public boolean containsValue(Object value)
containsValue
in interface Map<String,String>
containsValue
in class AbstractMap<String,String>
Map.containsValue(java.lang.Object)
public Set<Map.Entry<String,String>> entrySet()
entrySet
in interface Map<String,String>
entrySet
in class AbstractMap<String,String>
Map.entrySet()
public String get(Object key)
get
in interface Map<String,String>
get
in class AbstractMap<String,String>
key
- the parameter to look up the value for
public boolean getBoolean(String key, boolean defaultValue)
key
- the parameter to look up the value fordefaultValue
- the default value
public int getInteger(String key, int defaultValue)
key
- the parameter to look up the value fordefaultValue
- the default value
public List<String> getList(String key)
The list returned is a copy of the internal data of this object, and as such you may alter it freely.
key
- the parameter to look up the value for
public List<String> getList(String key, List<String> defaultValue)
The list returned is a copy of the internal data of this object, and as such you may alter it freely.
key
- the parameter to look up the value fordefaultValue
- the default value
public Object getObject(String key)
null
in case there is no Object for this parameter.
key
- the parameter to look up the value for
null
in case there is no Object for this parameter.public String getString(String key, String defaultValue)
key
- the parameter to look up the value fordefaultValue
- the default value
public int hashCode()
hashCode
in interface Map<String,String>
hashCode
in class AbstractMap<String,String>
Map.hashCode()
public Set<String> keySet()
keySet
in interface Map<String,String>
keySet
in class AbstractMap<String,String>
Map.keySet()
public void load(InputStream input) throws IOException
input
- the stream to load the input from
IOException
- in case of IO errors reading from the streampublic String put(String key, String value)
If the parameter already exists then the existing value will be replaced.
put
in interface Map<String,String>
put
in class AbstractMap<String,String>
key
- the parameter to setvalue
- the value to set
public void putAll(Map<? extends String,? extends String> other)
The difference form a simple Map<String, String>
is that for the parameter
configuration, the values of the keys in both maps are merged and kept in the Object store
as a List.
As result, this
configuration will be altered, the other configuration will
stay unchanged.
putAll
in interface Map<String,String>
putAll
in class AbstractMap<String,String>
other
- the other parameter configuration to merge this configuration withpublic String remove(Object key)
remove
in interface Map<String,String>
remove
in class AbstractMap<String,String>
key
- the parameter to removepublic String toString()
toString
in class AbstractMap<String,String>
java.util.Map#toString()
public Collection<String> values()
values
in interface Map<String,String>
values
in class AbstractMap<String,String>
Map.values()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |