org.ejen.util
Class DOMUtil

java.lang.Object
  |
  +--org.ejen.util.DOMUtil

public class DOMUtil
extends Object

DOM utility (static methods used in java code).

Version:
1.0
Author:
F. Wolff

Field Summary
static String S_PY_NAME
           
static String S_PY_PROPERTY_NODE_NAME
           
static String S_PY_VALUE
           
 
Constructor Summary
DOMUtil()
           
 
Method Summary
static Node createCDATANode(Document doc, Node parent, String nodeName, String nodeValue)
          Creates a new Node of name 'nodeName', in the 'doc' Document, child of the 'parent' Node, and fills it with a CDATA Node whose content is 'nodeValue'.
static Node createCDATANode(Document doc, String nodeName, String nodeValue)
          Creates a new Node of name 'nodeName', in the 'doc' Document, and fills it with a CDATA Node whose content is 'nodeValue'.
static Node createNode(Document doc, Node parent, String nodeName)
          Creates a new Node of name 'nodeName', in the 'doc' Document, child of the 'parent' Node.
static Node createTextNode(Document doc, String nodeName, String nodeValue)
          Creates a new Node of name 'nodeName', in the 'doc' Document, and fills it with a text Node whose content is 'nodeValue'.
static String getAttribute(Node n, String name)
          Returns a Node attribute value.
static Properties getChildProperties(Node n)
          Returns a set of properties from a given parent Node.
static Properties getChildProperties(Node parent, Properties props)
          Appends to an existing set of properties those found in a given parent Node.
static String[] getProperty(Node n)
          Returns a property as an array of two Strings.
static String getProperty(Node n, String name)
          Returns a property value.
static Document newDocument()
          Create a new Document object.
static Document parseXMLFile(String name)
          Parse a XML document file.
static Document parseXMLString(String xmlString)
          Parse a XML document String (using DEFAULT_XML_DATA_ENCODING encoding).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

S_PY_PROPERTY_NODE_NAME

public static final String S_PY_PROPERTY_NODE_NAME
See Also:
Constant Field Values

S_PY_NAME

public static final String S_PY_NAME
See Also:
Constant Field Values

S_PY_VALUE

public static final String S_PY_VALUE
See Also:
Constant Field Values
Constructor Detail

DOMUtil

public DOMUtil()
Method Detail

getAttribute

public static String getAttribute(Node n,
                                  String name)
Returns a Node attribute value.

Parameters:
n - the Node from which the attribute must be retreived.
name - the name of the attribute.
Returns:
the attribute value or null if there is no such attribute.

getProperty

public static String getProperty(Node n,
                                 String name)
Returns a property value.

The n parameter must have the following format:


  <property name="..." value="...">
 

Parameters:
n - the Node from which the property must be retreived.
name - the name of the property (ie: the value of the "name" attribute).
Returns:
the property value (ie: the value of the "value" attribute) or null if there is no such property.

getProperty

public static String[] getProperty(Node n)
Returns a property as an array of two Strings.

The n parameter must have the following format:


  <property name="..." value="...">
 

Parameters:
n - the Node from which the property must be retreived.
Returns:
the property name/value pair (ie: the value of the "name" attribute and the value of the "value" attribute) or null if there is no such property.

getChildProperties

public static Properties getChildProperties(Node n)
Returns a set of properties from a given parent Node.

Each child property must have the following format:


  <property name="..." value="...">
 

Other kind of child nodes are ignored.

Parameters:
n - the Node from which the child properties must be retreived.
Returns:
the set of child properties (empty if there is no child property).

getChildProperties

public static Properties getChildProperties(Node parent,
                                            Properties props)
Appends to an existing set of properties those found in a given parent Node.

Each child property must have the following format:


  <property name="..." value="...">
 

Other kind of child nodes are ignored.

Parameters:
props - the existing properties.
Returns:
the props parameter (with appended child properties).

newDocument

public static Document newDocument()
Create a new Document object.

Returns:
the new Document.
Throws:
WrappedRuntimeException - creation error.

parseXMLFile

public static Document parseXMLFile(String name)
Parse a XML document file.

Parameters:
name - the XML file name.
Returns:
the parsed Document object.
Throws:
WrappedRuntimeException - error (no such file, parse error).

parseXMLString

public static Document parseXMLString(String xmlString)
Parse a XML document String (using DEFAULT_XML_DATA_ENCODING encoding).

Parameters:
xmlString - the XML content String. If xmlString is null, the DEFAULT_XML_DATA is used.
Returns:
the parsed Document object.
Throws:
WrappedRuntimeException - error (parse error).

createNode

public static Node createNode(Document doc,
                              Node parent,
                              String nodeName)
Creates a new Node of name 'nodeName', in the 'doc' Document, child of the 'parent' Node.

Parameters:
doc - the owning Document of the new Node.
parent - the parent Node of the new Node.
nodeName - name of the Node to be created.
Returns:
the created Node.
Throws:
WrappedRuntimeException - DOM errors.

createCDATANode

public static Node createCDATANode(Document doc,
                                   Node parent,
                                   String nodeName,
                                   String nodeValue)
Creates a new Node of name 'nodeName', in the 'doc' Document, child of the 'parent' Node, and fills it with a CDATA Node whose content is 'nodeValue'.

Parameters:
doc - the owning Document of the new Node.
parent - the parent Node of the new Node.
nodeName - name of the Node to be created.
nodeValue - value of the CDATA Node to be created.
Returns:
the created Node (parent of the CDATA Node).
Throws:
WrappedRuntimeException - DOM errors.

createCDATANode

public static Node createCDATANode(Document doc,
                                   String nodeName,
                                   String nodeValue)
Creates a new Node of name 'nodeName', in the 'doc' Document, and fills it with a CDATA Node whose content is 'nodeValue'.

Parameters:
doc - the owning Document of the new Node.
nodeName - name of the Node to be created.
nodeValue - value of the CDATA Node to be created.
Returns:
the created Node (parent of the CDATA Node).
Throws:
WrappedRuntimeException - DOM errors.

createTextNode

public static Node createTextNode(Document doc,
                                  String nodeName,
                                  String nodeValue)
Creates a new Node of name 'nodeName', in the 'doc' Document, and fills it with a text Node whose content is 'nodeValue'.

Parameters:
doc - the owning Document of the new Node.
nodeName - name of the Node to be created.
nodeValue - value of the text Node to be created.
Returns:
the created Node (parent of the text Node).
Throws:
WrappedRuntimeException - DOM errors.