com.stratelia.webactiv.util
Class XMLConfigurationStore

java.lang.Object
  extended by com.stratelia.webactiv.util.XMLConfigurationStore
All Implemented Interfaces:
ConfigurationStore

public class XMLConfigurationStore
extends Object
implements ConfigurationStore

This object implements and extends the ConfigurationStore interface for XML files. As a ConfigurationStore, it imposes a standard structure on the grove that can be mapped 1-1 with properties, but it offers all necessary methods to handle arbitrary XML structures as well.

The standard structure is the following:
<param>
<param-name>
parameter name
</param-name>
<param-value>
parameter value
</param-value>
<param-description>
parameter description
</param-description>

The parameter description is any arbitrary string that could be used for instance as a tooltip text or a as a label for a configuration tool that should display the use of the given parameter.

Note that symbold such as < or & must be escaped properly when included in the parameter name, value or description.

Version:
Author:
jpouyadou

Constructor Summary
XMLConfigurationStore()
           
XMLConfigurationStore(File file, String rootString)
           
XMLConfigurationStore(String configFileName, InputStream configFileInputStream, String rootString)
          Creates new XMLConfigurationStore
 
Method Summary
 void appendChild(Node parent, Node child)
           
 Node createElement(String key)
           
 Node createTextNode(String value)
           
 Node findNode(Node node, String name)
           
 Node[] findNodes(Node node, String name)
          This method returns all children nodes (at any depth, that is, children, grazndchildren, and so on) from the node node whose name matches the name string.
 Node[] findNodes(String name)
           
 String get(String key, String defaultValue)
           
 String[] getAllNames()
          Returns all first level names from the configuration file
 String getAttributeValue(Node n, String attributeName)
          This method returns the value of an attribute of a given node.
 int getIntValue(String key)
          This method returns a long value for the given key.
 long getLongValue(String key)
          This method returns a long value for the given key.
 String getNodeValue(String nodename)
           
 String getProperty(String key)
           
 String getProperty(String key, String defaultValue)
          This method returns the value of a standard-format parameter, that is, it returns the text value of the param-value element that goes with the param-name for the key element.
 String getString(String key)
          This method is for compatibility with the ResourceLocator
 String[] getValues(String key)
          This method returns all values for a multi-valued key
 Node getXMLParamNode(String nodename)
           
 String getXMLParamValue(Node n, String entry, String key)
          This method returns the value of the node entry, starting from the node n.
 String[] getXMLParamValues(Node n, String entry, String key)
          This method returns the values of the node entry, starting from the node n.
 void put(String key, String value)
           
 void put(String key, String[] values)
           
 void putProperty(String key, String value)
           
 void putPropety(String key, String value)
           
 void replaceValue(Node n, String key, String value)
           
 void serialize()
           
 void setConfigFileName(String configfilename)
          This method sets the config file name.
 Node setRoot(String rootString)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLConfigurationStore

public XMLConfigurationStore(String configFileName,
                             InputStream configFileInputStream,
                             String rootString)
                      throws Exception
Creates new XMLConfigurationStore

Throws:
Exception

XMLConfigurationStore

public XMLConfigurationStore(File file,
                             String rootString)
                      throws Exception
Throws:
Exception

XMLConfigurationStore

public XMLConfigurationStore()
                      throws Exception
Throws:
Exception
Method Detail

setRoot

public Node setRoot(String rootString)

serialize

public void serialize()
               throws FileNotFoundException,
                      IOException
Specified by:
serialize in interface ConfigurationStore
Throws:
FileNotFoundException
IOException

setConfigFileName

public void setConfigFileName(String configfilename)
This method sets the config file name. Useful when the configuration store has been created empty, so that is has no associated file.


getNodeValue

public String getNodeValue(String nodename)

getXMLParamValue

public String getXMLParamValue(Node n,
                               String entry,
                               String key)
This method returns the value of the node entry, starting from the node n. It may consist of the concatenation of various text en entity reference child nodes.

This method returns null if the node wasn't found


getXMLParamValues

public String[] getXMLParamValues(Node n,
                                  String entry,
                                  String key)
This method returns the values of the node entry, starting from the node n. Each value may consist of the concatenation of various text en entity reference child nodes.

This method returns null if the node wasn't found


getXMLParamNode

public Node getXMLParamNode(String nodename)

getAttributeValue

public String getAttributeValue(Node n,
                                String attributeName)
This method returns the value of an attribute of a given node. If the attribute cannot be found of if the node is null, this method returns null.

Parameters:
n - the node where the attribute is stored
attributeName - the name of the attribute. Case sensitive.

putPropety

public void putPropety(String key,
                       String value)

putProperty

public void putProperty(String key,
                        String value)
Specified by:
putProperty in interface ConfigurationStore

replaceValue

public void replaceValue(Node n,
                         String key,
                         String value)

createElement

public Node createElement(String key)

createTextNode

public Node createTextNode(String value)

appendChild

public void appendChild(Node parent,
                        Node child)

put

public void put(String key,
                String value)
Specified by:
put in interface ConfigurationStore

put

public void put(String key,
                String[] values)

getProperty

public String getProperty(String key,
                          String defaultValue)
This method returns the value of a standard-format parameter, that is, it returns the text value of the param-value element that goes with the param-name for the key element. See the description of standard XML resources for details
If the key os not found, the defaultValue string is returned instead.

Specified by:
getProperty in interface ConfigurationStore

getProperty

public String getProperty(String key)
Specified by:
getProperty in interface ConfigurationStore

getString

public String getString(String key)
This method is for compatibility with the ResourceLocator

Specified by:
getString in interface ConfigurationStore

get

public String get(String key,
                  String defaultValue)
Specified by:
get in interface ConfigurationStore

getLongValue

public long getLongValue(String key)
                  throws XMLConfigurationException
This method returns a long value for the given key. It throws an XMLConfigurationException with the code KEY_NOT_FOUND if it cannot be found, or INVALID_VALUE if it cannot be converted to a long value.

Throws:
XMLConfigurationException

getIntValue

public int getIntValue(String key)
                throws XMLConfigurationException
This method returns a long value for the given key. It throws an XMLConfigurationException with the code KEY_NOT_FOUND if it cannot be found, or INVALID_VALUE if it cannot be converted to a long value.

Throws:
XMLConfigurationException

getValues

public String[] getValues(String key)
This method returns all values for a multi-valued key


findNode

public Node findNode(Node node,
                     String name)

findNodes

public Node[] findNodes(String name)

findNodes

public Node[] findNodes(Node node,
                        String name)
This method returns all children nodes (at any depth, that is, children, grazndchildren, and so on) from the node node whose name matches the name string. If node is null, the method returns null
If name is null or empty, the method returns null
If no children of the node node match the name string, the method returns null


getAllNames

public String[] getAllNames()
Returns all first level names from the configuration file

Specified by:
getAllNames in interface ConfigurationStore


Copyright © 2016 Silverpeas. All Rights Reserved.