Class 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.
    • Method Detail

      • parse

        public static java.util.Map<java.lang.String,​CmsParameterStore.WeightedValueparse​(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 file
        source - the source identifier
        Returns:
        the of parameters
        Throws:
        CmsXmlException - if something goes wrong
      • parse

        public static java.util.Map<java.lang.String,​CmsParameterStore.WeightedValueparse​(CmsObject cms,
                                                                                                  java.lang.String path)
                                                                                           throws CmsException
        Helper method for parsing a parameter file from a VFS resource.
        Parameters:
        cms - the CmsObject
        path - 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.WeightedValueparse​(org.dom4j.Element rootElem,
                                                                                                  java.lang.String source)
        Parses a parameter file from an XML element.
        Parameters:
        rootElem - the root element of the XML
        source - 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 context
        key - the key
        Returns:
        the string value with maximal weight