atg.junit.nucleus
Class XmlUtils

java.lang.Object
  extended by atg.junit.nucleus.XmlUtils

public class XmlUtils
extends java.lang.Object

A utility class to help with common XML manipulation functions.

Version:
1.0

Constructor Summary
XmlUtils()
           
 
Method Summary
static java.lang.String getAttribute(org.w3c.dom.Node pNode, java.lang.String pName)
          gets the value of the named attribute.
static java.lang.String getAttribute(org.w3c.dom.Node pNode, java.lang.String pName, java.lang.String pDefault)
          returns the value of the named attribute, or the specified default if the attribute value is null.
static boolean getBooleanAttribute(org.w3c.dom.Node pNode, java.lang.String pName, boolean pDefault)
          returns the value of the named attribute as a boolean.
static java.lang.Boolean getBooleanAttribute(org.w3c.dom.Node pNode, java.lang.String pName, java.lang.Boolean pDefault)
          returns the value of the named attribute as a Boolean object.
static boolean getBooleanValue(java.lang.String pValue, java.lang.String pDescriptor, boolean pDefault)
          converts the specified value into a boolean.
static java.lang.Integer getIntegerAttribute(org.w3c.dom.Node pNode, java.lang.String pName, boolean pAllowNull)
          returns the value of the named attribute as an Integer object.
static java.lang.Integer getIntegerValue(java.lang.String pValue, java.lang.String pDescriptor, boolean pAllowNull)
          converts the specified String into an Integer.
static java.lang.Long getLongAttribute(org.w3c.dom.Node pNode, java.lang.String pName, boolean pAllowNull)
          returns the value of the named attribute as a Long object.
static java.lang.Long getLongValue(java.lang.String pValue, java.lang.String pDescriptor, boolean pAllowNull)
          converts the specified String into a Long.
static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Document pDocument, java.lang.String[] pChildren)
          retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.
static java.util.List<org.w3c.dom.Node> getNodes(java.io.File pXmlFile, boolean pValidateDoc, java.lang.String[] pChildren)
          retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.
static org.w3c.dom.NodeList getNodes(org.w3c.dom.Node pNode, java.lang.String pChild)
          returns the Element NodeList for the specified child of the parent Node.
static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node pNode, java.lang.String[] pChildren)
          retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.
static java.lang.String getNodeTextValue(org.w3c.dom.Node pElement)
          Returns the String value of the content of the Node specified.
static org.w3c.dom.Document initializeFile(java.io.File pXmlFile, boolean pValidateDoc)
          Initializes the XML file to be parsed and gets the Document tree for it.
static void main(java.lang.String[] pArgs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

initializeFile

public static org.w3c.dom.Document initializeFile(java.io.File pXmlFile,
                                                  boolean pValidateDoc)
                                           throws java.io.FileNotFoundException,
                                                  java.lang.Exception
Initializes the XML file to be parsed and gets the Document tree for it.

Parameters:
File - the XML file to parse
boolean - true if the file should be validated against its DTD; otherwise false.
Throws:
java.io.FileNotFoundException - if the specified file can not be located.
java.lang.Exception - if an error occurs parsing the file to a DOM.

getNodes

public static java.util.List<org.w3c.dom.Node> getNodes(java.io.File pXmlFile,
                                                        boolean pValidateDoc,
                                                        java.lang.String[] pChildren)
                                                 throws java.io.FileNotFoundException,
                                                        java.lang.Exception
retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.

Parameters:
File - the XML document in which to look
boolean - true if the file should be validated against its DTD; otherwise false.
String[] - the nested child nodes to retrieve. for example, if you specified an array { "foo", "bar", "flippy" } this method would return all 'flippy' Nodes for the XML document:
    <foo<
      <bar<
        <flippy .../<
        <flippy .../<
      </bar<
    </foo<
  
Returns:
List the requested child Nodes. an empty List if no child Nodes exist.
Throws:
java.io.FileNotFoundException - if the specified file can not be located.
java.lang.Exception - if an error occurs parsing the file to a DOM.

getNodes

public static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Document pDocument,
                                                        java.lang.String[] pChildren)
retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.

Parameters:
Document - the XML document parsed to a DOM
String[] - the nested child nodes to retrieve. for example, if you specified an array { "foo", "bar", "flippy" } this method would return all 'flippy' Nodes for the XML document:
    <foo<
      <bar<
        <flippy .../<
        <flippy .../<
      </bar<
    </foo<
  
Returns:
List the requested child Nodes. an empty List if no child Nodes exist. null if the specified Document was null.

getNodes

public static java.util.List<org.w3c.dom.Node> getNodes(org.w3c.dom.Node pNode,
                                                        java.lang.String[] pChildren)
retrieves the Node(s) represented within the DOM hierarchy at the location designated by the 'nested' child nodes.

Parameters:
Node - the Node at which to start searching
String[] - the nested child nodes to retrieve. for example, if you specified an array { "foo", "bar", "flippy" } this method would return all 'flippy' Nodes for the XML document:
    <foo<
      <bar<
        <flippy .../<
        <flippy .../<
      </bar<
    </foo<
  
Returns:
List the requested child Nodes. an empty List if no child Nodes exist.

getNodes

public static org.w3c.dom.NodeList getNodes(org.w3c.dom.Node pNode,
                                            java.lang.String pChild)
returns the Element NodeList for the specified child of the parent Node.

Parameters:
Node - the parent node
String - the name of the child node(s)
Returns:
NodeList the children of the parent Node. null if pChild or pNode is null.

getNodeTextValue

public static java.lang.String getNodeTextValue(org.w3c.dom.Node pElement)
Returns the String value of the content of the Node specified.

Parameters:
Node - the node whose content to get.
Returns:
String the value of the content of the Node. An empty String if the Node does not have any content.

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Node pNode,
                                            java.lang.String pName)
gets the value of the named attribute.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
Returns:
String the value of the attribute. null if the attribute is not defined or if a value has not been specified for it.

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Node pNode,
                                            java.lang.String pName,
                                            java.lang.String pDefault)
returns the value of the named attribute, or the specified default if the attribute value is null.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
String - the default value to return if a value does not exist for the specified attribute, or if the specified attribute is not defined in this Node.
Returns:
String the value of the attribute.

getIntegerAttribute

public static java.lang.Integer getIntegerAttribute(org.w3c.dom.Node pNode,
                                                    java.lang.String pName,
                                                    boolean pAllowNull)
                                             throws FileFormatException
returns the value of the named attribute as an Integer object.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
String - the default value to return if a value does not exist for the specified attribute, or if the specified attribute is not defined in this Node.
Returns:
Integer the value of the attribute. If pAllowNull is true and no value is specified for the attribute then null is returned.
Throws:
FileFormatException - if the value specified by the attribute can not be converted to an Integer, or if pAllowNull is false and no value was specified for the attribute.

getIntegerValue

public static java.lang.Integer getIntegerValue(java.lang.String pValue,
                                                java.lang.String pDescriptor,
                                                boolean pAllowNull)
                                         throws FileFormatException
converts the specified String into an Integer.

Parameters:
String - the value to convert.
String - a descriptor of what the value is for.
boolean - true if the input value can be null; otherwise false.
Returns:
Integer the Integer value of the String input value.
Throws:
FileFormatException - if the String can not be converted to an Integer or if it is null and pAllowNull is false.

getLongAttribute

public static java.lang.Long getLongAttribute(org.w3c.dom.Node pNode,
                                              java.lang.String pName,
                                              boolean pAllowNull)
                                       throws FileFormatException
returns the value of the named attribute as a Long object.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
String - the default value to return if a value does not exist for the specified attribute, or if the specified attribute is not defined in this Node.
Returns:
Long the value of the attribute. If pAllowNull is true and no value is specified for the attribute then null is returned.
Throws:
FileFormatException - if the value specified by the attribute can not be converted to a Long, or if pAllowNull is false and no value was specified for the attribute.

getLongValue

public static java.lang.Long getLongValue(java.lang.String pValue,
                                          java.lang.String pDescriptor,
                                          boolean pAllowNull)
                                   throws FileFormatException
converts the specified String into a Long.

Parameters:
String - the value to convert.
String - a descriptor of what the value is for.
boolean - true if the input value can be null; otherwise false.
Returns:
Long the Long value of the String input value.
Throws:
FileFormatException - if the String can not be converted to a Long or if it is null and pAllowNull is false.

getBooleanAttribute

public static boolean getBooleanAttribute(org.w3c.dom.Node pNode,
                                          java.lang.String pName,
                                          boolean pDefault)
                                   throws FileFormatException
returns the value of the named attribute as a boolean.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
boolean - the default value to return if a value does not exist for the specified attribute, or if the specified attribute is not defined in this Node.
Returns:
boolean the value of the attribute. If no value was specified for the attribute then the default value is returned.
Throws:
FileFormatException - if the value specified by the attribute can not be converted to a boolean.

getBooleanValue

public static boolean getBooleanValue(java.lang.String pValue,
                                      java.lang.String pDescriptor,
                                      boolean pDefault)
                               throws FileFormatException
converts the specified value into a boolean.

Parameters:
String - the value which should be converted.
String - a descriptor of what the value is for.
boolean - the default value to return if the specified value is null or empty.
Returns:
boolean the converted value. If the specified value was null or empty then the default value is returned.
Throws:
FileFormatException - if the specified value can not be converted to a boolean.

getBooleanAttribute

public static java.lang.Boolean getBooleanAttribute(org.w3c.dom.Node pNode,
                                                    java.lang.String pName,
                                                    java.lang.Boolean pDefault)
                                             throws FileFormatException
returns the value of the named attribute as a Boolean object.

Parameters:
Node - the node whose attribute should be retrieved.
String - the name of attribute whose value should be retrieved.
Boolean - the default value to return if a value does not exist for the specified attribute, or if the specified attribute is not defined in this Node.
Returns:
Boolean the value of the attribute. If no value was specified for the attribute then the default value is returned.
Throws:
FileFormatException - if the value specified by the attribute can not be converted to a boolean.

main

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


Copyright © 2009. All Rights Reserved.