DODS 7.2 API

org.enhydra.dods.xml
Class XmlUtil

java.lang.Object
  extended by org.enhydra.dods.xml.XmlUtil

public class XmlUtil
extends java.lang.Object


Field Summary
protected  org.w3c.dom.Document document
           
protected  java.lang.String xmlFile
           
 
Constructor Summary
XmlUtil(java.lang.String xmlFile)
           
 
Method Summary
 int getNumberOfNodes(java.lang.String key)
          Return number of nodes defined by key parameter.
 int getNumberOfNodes(java.lang.String key, int[] levelNodes)
          Return number of nodes defined by key parameter.
static int getNumberOfNodes(java.lang.String xmlfile, java.lang.String key, int[] levelNodes)
          Return number of nodes defined by key parameter.
 java.lang.String getSingleAttribute(java.lang.String key)
          Return value of single text node defined by key parameter.
 java.lang.String getSingleAttribute(java.lang.String key, int[] levelNodes)
          Return value of attribute node defined by key parameter.
static java.lang.String getSingleAttribute(java.lang.String xmlfile, java.lang.String key, int[] levelNodes)
          Return value of node attribute defined by key parameter.
 java.lang.String getSingleTextNode(java.lang.String key)
          Return value of single text node defined by key parameter.
 java.lang.String getSingleTextNode(java.lang.String key, int[] levelNodes)
          Return value of single text node defined by key parameter.
static java.lang.String getSingleTextNode(java.lang.String xmlfile, java.lang.String key, int[] levelNodes)
          Return value of single text node defined by key parameter.
static void main(java.lang.String[] args)
           
 void setSingleAttribute(java.lang.String key, int[] levelNodes, java.lang.String value)
          Set value of attribute node defined by key parameter.
static void setSingleAttribute(java.lang.String xmlfile, java.lang.String key, int[] levelNodes, java.lang.String value, java.util.Properties prop)
          Set and save value of attribute node defined by key parameter.
 void store()
          Store DOM source in xml file.
 void store(java.util.Properties properties)
          Store DOM source in xml file.
 void store(java.lang.String fileName, java.util.Properties properties)
          Store DOM source in xml file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlFile

protected java.lang.String xmlFile

document

protected org.w3c.dom.Document document
Constructor Detail

XmlUtil

public XmlUtil(java.lang.String xmlFile)
        throws XmlUtilException
Throws:
XmlUtilException
Method Detail

store

public void store()
           throws XmlUtilException
Store DOM source in xml file.

Throws:
XmlUtilException

store

public void store(java.util.Properties properties)
           throws XmlUtilException
Store DOM source in xml file.

Parameters:
properties - Output properties for xml file.
Throws:
XmlUtilException

store

public void store(java.lang.String fileName,
                  java.util.Properties properties)
           throws XmlUtilException
Store DOM source in xml file.

Parameters:
properties - Output properties for xml file.
fileName - Output xml file name.
Throws:
XmlUtilException

getSingleTextNode

public java.lang.String getSingleTextNode(java.lang.String key)
                                   throws XmlUtilException
Return value of single text node defined by key parameter.

Parameters:
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
Returns:
Value of single text node defined by key parameter or null if tag doesn't exist.
Throws:
XmlUtilException

getSingleTextNode

public java.lang.String getSingleTextNode(java.lang.String key,
                                          int[] levelNodes)
                                   throws XmlUtilException
Return value of single text node defined by key parameter.

Parameters:
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Value of single text node defined by key parameter or null if tag doesn't exist.
Throws:
XmlUtilException

getSingleAttribute

public java.lang.String getSingleAttribute(java.lang.String key)
                                    throws XmlUtilException
Return value of single text node defined by key parameter.

Parameters:
key - Full name of tag attribute which is about to be read. The tags in the key are separated by "/". Name of the attribute is separated by "@" from tag name (e.g. /doml/database@templateset).
Returns:
Value of node attribute defined by key parameter or null if attribute doesn't exist.
Throws:
XmlUtilException

getSingleAttribute

public java.lang.String getSingleAttribute(java.lang.String key,
                                           int[] levelNodes)
                                    throws XmlUtilException
Return value of attribute node defined by key parameter.

Parameters:
key - Full name of tag attribute which is about to be read. The tags in the key are separated by "/". Name of the attribute is separated by "@" from tag name (e.g. /doml/database@templateset).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Value of node attribute defined by key parameter or null if attribute doesn't exist.
Throws:
XmlUtilException

setSingleAttribute

public void setSingleAttribute(java.lang.String key,
                               int[] levelNodes,
                               java.lang.String value)
                        throws XmlUtilException
Set value of attribute node defined by key parameter.

Parameters:
key - Full name of tag attribute which is about to be read. The tags in the key are separated by "/". Name of the attribute is separated by "@" from tag name (e.g. /doml/database@templateset).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
value - New value of attribute node.
Throws:
XmlUtilException

getNumberOfNodes

public int getNumberOfNodes(java.lang.String key)
                     throws XmlUtilException
Return number of nodes defined by key parameter.

Parameters:
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
Returns:
Number of nodes defined by key parameter.
Throws:
XmlUtilException

getNumberOfNodes

public int getNumberOfNodes(java.lang.String key,
                            int[] levelNodes)
                     throws XmlUtilException
Return number of nodes defined by key parameter.

Parameters:
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Number of nodes defined by key parameter.
Throws:
XmlUtilException

getSingleTextNode

public static java.lang.String getSingleTextNode(java.lang.String xmlfile,
                                                 java.lang.String key,
                                                 int[] levelNodes)
                                          throws XmlUtilException
Return value of single text node defined by key parameter.

Parameters:
xmlfile - full path name of xml file which is about to be read.
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Value of single text node defined by key parameter or null if attribute doesn't exist. Example: In faculty.xml xmlfile: Zeljko Jelena Boris int levelNodes[] = {0,1,2}; getSingleTextNode("faculty.xml","/faculty/department/student/name",levelNodes) will produce: Boris The same result will produce: int levelNodes[] = {0,1,2,0};
Throws:
XmlUtilException

getSingleAttribute

public static java.lang.String getSingleAttribute(java.lang.String xmlfile,
                                                  java.lang.String key,
                                                  int[] levelNodes)
                                           throws XmlUtilException
Return value of node attribute defined by key parameter.

Parameters:
xmlfile - full path name of xml file which is about to be read.
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Value of node attribute defined by key parameter or null if attribute doesn't exist. Example: In faculty.xml xmlfile: Zeljko Jelena Boris int levelNodes[] = {0,1,0}; getSingleTextNode("faculty.xml","/faculty/department/student@index",levelNodes) will produce: 6403
Throws:
XmlUtilException

setSingleAttribute

public static void setSingleAttribute(java.lang.String xmlfile,
                                      java.lang.String key,
                                      int[] levelNodes,
                                      java.lang.String value,
                                      java.util.Properties prop)
                               throws XmlUtilException
Set and save value of attribute node defined by key parameter.

Parameters:
xmlfile - full path name of xml file which is about to be read.
key - Full name of tag attribute which is about to be read. The tags in the key are separated by "/". Name of the attribute is separated by "@" from tag name (e.g. /doml/database@templateset).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
value - New value of attribute node.
prop - Output properties for xml file.
Throws:
XmlUtilException

getNumberOfNodes

public static int getNumberOfNodes(java.lang.String xmlfile,
                                   java.lang.String key,
                                   int[] levelNodes)
                            throws XmlUtilException
Return number of nodes defined by key parameter.

Parameters:
xmlfile - full path name of xml file which is about to be read.
key - Full name of tag which is about to be read. The tags in the key are separated by "/" (e.g. /doml/database).
levelNodes - Array of ordinal numbers. There is one number for each tag level (starting from level 0). These numbers tell to which appearance of specific tag key tag belongs to. It is not necessary to provide all tag levels.
Returns:
Number of nodes defined by key parameter. Example: In faculty.xml xmlfile: Zeljko Jelena Boris int levelNodes[] = {0,1}; getSingleTextNode("faculty.xml","/faculty/department/student",levelNodes) will produce: 3
Throws:
XmlUtilException

main

public static void main(java.lang.String[] args)

DODS 7.2 API