Class CmsParameterStore
- java.lang.Object
-
- org.opencms.configuration.CmsParameterStore
-
public class CmsParameterStore extends java.lang.Object
Class for accessing global 'weighted' configuration parameters defined in parameter files in the VFS. Used as a singleton.Parameter files are XML configuration files that contain a list of named, string-valued configuration parameters, optionally with a numeric weight. The weight can be set individually for each parameter, or globally for a whole parameter file, but individual weights override parameter file weights. The schema for these is defined in org/opencm/configuration/paramfile.dtd.
To register a parameter file in OpenCms, its path must be listed as a value of the 'paramfile' module parameter for an installed module. The module parameter can be set on multiple modules, and may also contain multiple paths separated by commas.
When retrieving a value that is defined in multiple parameter files, the one with the highest weight wins. If there are multiple instances with the same weight, which one of them wins is implementation dependent.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsParameterStore.WeightedValue
An individual weighted parameter value, with a 'source' attribute for better debuggability.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
A_NAME
XML attribute name.static java.lang.String
A_WEIGHT
XML attribute name.static double
DEFAULT_WEIGHT
Default weight, if not defined in parameter file.static java.lang.String
N_PARAM
XML node name.static java.lang.String
PARAM_PARAMFILE
Module parameter for registering parameter files.
-
Constructor Summary
Constructors Constructor Description CmsParameterStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CmsParameterStore
getInstance()
Gets the global instance.java.lang.String
getValue(CmsObject cms, java.lang.String key)
Gets the string value with the maximal weight for the parameter with the given key.CmsParameterStore.WeightedValue
getWeightedValue(CmsObject cms, java.lang.String key)
Finds the value with the maximal weight for the given key.static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue>
parse(byte[] data, java.lang.String source)
Helper method for parsing a parameter file from a byte array.static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue>
parse(org.dom4j.Element rootElem, java.lang.String source)
Parses a parameter file from an XML element.static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue>
parse(CmsObject cms, java.lang.String path)
Helper method for parsing a parameter file from a VFS resource.
-
-
-
Field Detail
-
A_NAME
public static final java.lang.String A_NAME
XML attribute name.- See Also:
- Constant Field Values
-
A_WEIGHT
public static final java.lang.String A_WEIGHT
XML attribute name.- See Also:
- Constant Field Values
-
DEFAULT_WEIGHT
public static final double DEFAULT_WEIGHT
Default weight, if not defined in parameter file.- See Also:
- Constant Field Values
-
N_PARAM
public static final java.lang.String N_PARAM
XML node name.- See Also:
- Constant Field Values
-
PARAM_PARAMFILE
public static final java.lang.String PARAM_PARAMFILE
Module parameter for registering parameter files.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsParameterStore
public CmsParameterStore()
-
-
Method Detail
-
getInstance
public static CmsParameterStore getInstance()
Gets the global instance.- Returns:
- the global instance
-
parse
public static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue> parse(byte[] data, java.lang.String source) throws CmsXmlException
Helper method for parsing a parameter file from a byte array.- Parameters:
data
- the binary data for the parameter filesource
- the source identifier- Returns:
- the of parameters
- Throws:
CmsXmlException
- if something goes wrong
-
parse
public static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue> parse(CmsObject cms, java.lang.String path) throws CmsException
Helper method for parsing a parameter file from a VFS resource.- Parameters:
cms
- the CmsObjectpath
- the path of the resource- Returns:
- the map of parameters
- Throws:
CmsException
- if something goes wrong
-
parse
public static java.util.Map<java.lang.String,CmsParameterStore.WeightedValue> parse(org.dom4j.Element rootElem, java.lang.String source)
Parses a parameter file from an XML element.- Parameters:
rootElem
- the root element of the XMLsource
- the source identifier- Returns:
- the parameter map
-
getValue
public java.lang.String getValue(CmsObject cms, java.lang.String key)
Gets the string value with the maximal weight for the parameter with the given key.- Parameters:
cms
- the CMS contextkey
- the key- Returns:
- the string value with maximal weight
-
getWeightedValue
public CmsParameterStore.WeightedValue getWeightedValue(CmsObject cms, java.lang.String key)
Finds the value with the maximal weight for the given key.- Parameters:
cms
- the CMS contextkey
- the parameter key- Returns:
- the value with the maximal weight
-
-