Package org.silverpeas.core.util
Class XmlSettingBundle
- java.lang.Object
-
- org.silverpeas.core.util.XmlSettingBundle
-
- All Implemented Interfaces:
SilverpeasBundle
- Direct Known Subclasses:
XmlSettingBundle.SettingSection
public class XmlSettingBundle extends Object implements SilverpeasBundle
A bundle of settings in XML used to configure some features in Silverpeas or the behaviour of an application.The settings in a such bundle are structured into a tree of setting sections and are schema or DTD free. Each non-leave node defines a setting section and the only constrain is how each setting is defined: by the XML element
param
that must be made up of the following leaf XML elements.param = param-name param-description? param-value+
with?
meaning zero element or more and+
meaning at least one element.The content of an XML bundle is cached but there is no expiration-based mechanism of this cache.
If the XML content of the bundle is malformed, then a
java.util.MissingResourceException
exception is thrown.- Author:
- miguel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmlSettingBundle.SettingSection
-
Constructor Summary
Constructors Modifier Constructor Description protected
XmlSettingBundle(String name, Function<String,InputStream> loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(String key)
Is this bundle contains the specified parameter?boolean
exists()
Is this bundle exists?List<XmlSettingBundle.SettingSection>
getAllSettingSection(String path)
Gets all the setting sections in this XML setting bundle that are all located at the specified path.String
getBaseBundleName()
What is the fully qualified name of this bundle.protected Node
getCurrentRootNode()
XmlSettingBundle.SettingSection
getSettingSection(String path)
Gets the first setting section in this XML setting bundle that is identified by the specified path.String
getString(String key)
Gets the value as a String of the parameter identified by the specified key.String[]
getStringArray(String key)
Gets all the values as a String of the parameter identified by the specified key.Set<String>
keySet()
Gets a set of all the parameter names defined in this bundle.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.util.SilverpeasBundle
getStringList, getStringList
-
-
-
-
Constructor Detail
-
XmlSettingBundle
protected XmlSettingBundle(String name, Function<String,InputStream> loader)
-
-
Method Detail
-
keySet
public Set<String> keySet()
Gets a set of all the parameter names defined in this bundle. Each parameter name is fully qualified: it is made up of the complete path from the root node down to the parameter, each node name separated by a dot. For example, if a param nameddriver
is defined in a sectionfoo
itself defined in the root nodeconfiguration
, then the fully qualified parameter will beconfiguration.toto.driver
.- Specified by:
keySet
in interfaceSilverpeasBundle
- Returns:
- a set of keys.
-
containsKey
public boolean containsKey(String key)
Is this bundle contains the specified parameter?- Specified by:
containsKey
in interfaceSilverpeasBundle
- Parameters:
key
- the absolute or relative fully qualified name of the parameter. It is made up of the path from the root node down to the parameter with the given name, each node separated by a dot. For example, if a parameter nameddriver
is defined in a sectionfoo
itself defined in the current root nodeconfiguration
, then the unique name will be either the absolute oneconfiguration.toto.driver
or the relative onetoto.driver
.- Returns:
- true if this bundle has the specified parameter, false otherwise.
-
getBaseBundleName
public String getBaseBundleName()
What is the fully qualified name of this bundle.- Specified by:
getBaseBundleName
in interfaceSilverpeasBundle
- Returns:
- the base bundle name (that is to say without the hierarchy path name that is handled
by
org.silverpeas.core.util.ResourceLocator
).
-
getString
public String getString(String key)
Gets the value as a String of the parameter identified by the specified key. The key is the fully qualified name of a parameter and should exist in the bundle otherwise ajava.util.MissingResourceException
exception is thrown.- Specified by:
getString
in interfaceSilverpeasBundle
- Parameters:
key
- the unique name of the parameter in this bundle. It is made up of the absolute or relative path from the root node down to the parameter, each node name separated by a dot. For example, if a parameter nameddriver
is defined in a sectionfoo
itself defined in the root nodeconfiguration
, then the unique name will be either the absolute oneconfiguration.toto.driver
or the relative onetoto.driver
.- Returns:
- the value of the data as a string of characters. If several values are defined for
the specified parameter, then returns null. In that case, use the
org.silverpeas.core.util.XmlSettingBundle#getStringArray
method. - Throws:
MissingResourceException
- if either the bundle doesn't exist or the key isn't defined in the bundle.
-
getStringArray
public String[] getStringArray(String key)
Gets all the values as a String of the parameter identified by the specified key. The key is the fully qualified name of a parameter and should exist in the bundle otherwise ajava.util.MissingResourceException
exception is thrown.- Parameters:
key
- the unique name of the parameter in this bundle. It is made up of the absolute or relative path from the root node down to the parameter, each node name separated by a dot. For example, if a parameter nameddriver
is defined in a sectionfoo
itself defined in the root nodeconfiguration
, then the unique name will be either the absolute oneconfiguration.toto.driver
or the relative onetoto.driver
.- Returns:
- the value of the data as a string of characters. If several values are defined for the specified parameter, then returns null.
- Throws:
MissingResourceException
- if either the bundle doesn't exist or the key isn't defined in the bundle.
-
exists
public boolean exists()
Is this bundle exists?- Specified by:
exists
in interfaceSilverpeasBundle
- Returns:
- true if this bundle exists, false otherwise.
-
getSettingSection
public XmlSettingBundle.SettingSection getSettingSection(String path)
Gets the first setting section in this XML setting bundle that is identified by the specified path. The section is itself an XML setting bundle whose the root node is set to the node located at the specified path. All the parameter queries will be then done from this new root node (id est from the section). The path must identify a section and not a parameter otherwise ajava.util.MissingResourceException
exception could be thrown.- Parameters:
path
- the path of an XML node that represents a configuration section that can contain subsections and parameters. The path is either absolute or relative to the current root node down to the node to return, each node name separated by a dot. For example, to get a sectionservices
in a nodefoo
itself defined in the current root nodeconfiguration
, then path could be either the absolute oneconfiguration.toto.services
or the relative onetoto.services
.- Returns:
- the asked XML setting section.
- Throws:
MissingResourceException
- if the specified node doesn't exist in the XML setting bundle or if the specified node represents a parameter and not a section.
-
getAllSettingSection
public List<XmlSettingBundle.SettingSection> getAllSettingSection(String path)
Gets all the setting sections in this XML setting bundle that are all located at the specified path. The sections are themselves an XML setting bundle whose the root node is set to a node located at the specified path. All the parameter queries will be then done from this new root node (id est from the section). The path must identify a section and not a parameter otherwise ajava.util.MissingResourceException
exception could be thrown.- Parameters:
path
- the path of the XML nodes that represent each of them a configuration section that can contain subsections and parameters. The path is either absolute or relative to the current root node down to the nodes to return, each node name separated by a dot. For example, to get all the sectionsservice
in a nodeservices
itself defined in the current root nodeconfiguration
, then the path could be either the absolute oneconfiguration.services.service
or the relative oneservices.service
.- Returns:
- a list of the asked XML setting sections.
- Throws:
MissingResourceException
- if no nodes at the specified path are found in the XML setting bundle or if the specified node represents a parameter and not a section.
-
getCurrentRootNode
protected Node getCurrentRootNode()
-
-