spv.util
Class XMLUtilities

java.lang.Object
  extended by spv.util.XMLUtilities

public class XMLUtilities
extends java.lang.Object

Utililty methods to handle XML issues.

Version:
1.0 - 20Mar03
Author:
Ivo Busko (Space Telescope Science Institute)

Field Summary
private static java.lang.String DATE
           
private static java.lang.String VERSION
           
 
Constructor Summary
XMLUtilities()
           
 
Method Summary
static void BuildDOMElement(org.w3c.dom.Document document, com.sun.xml.tree.ElementNode parent, java.lang.String name, java.lang.String value)
          Builds a DOM element.
static java.util.Map BuildMapFromNode(org.w3c.dom.Node node)
          Builds a map with all the non-text (empty) child nodes in a parent node.
static java.util.List BuildNodeList(org.w3c.dom.Node node)
          Builds a list with all the non-text (empty) child nodes in a parent node.
static com.sun.xml.tree.ElementNode createRootElement(com.sun.xml.tree.XmlDocument document, java.lang.String name)
          Creates a root element.
static java.lang.String GetAttributeValueFromMap(java.util.Map map, java.lang.String name, java.lang.String attrname)
          Gets a named attribute from a node.
static boolean GetBooleanValueFromMap(java.util.Map map, java.lang.String name)
          Gets a boolean value from a map of nodes.
static double GetDoubleValueFromMap(java.util.Map map, java.lang.String name)
          Gets a double value from a map of nodes.
static int GetIntValueFromMap(java.util.Map map, java.lang.String name)
          Gets a integer value from a map of nodes.
static org.w3c.dom.Node GetNodeFromMap(java.util.Map map, java.lang.String name)
          Gets a named node from a map of nodes.
static java.lang.Object GetObjectFromMap(java.util.Map map, java.lang.String name, java.lang.String class_attr)
          Gets an object from a map of nodes.
static java.lang.String GetStringValueFromMap(java.util.Map map, java.lang.String name)
          Gets a string value from a map of nodes.
static org.w3c.dom.Document OpenXMLDocument(java.net.URL url)
          Creates Document instance from a URL.
static org.w3c.dom.Node validateDOMDocument(org.w3c.dom.Document document)
          Validates a DOM document.
static void writeXMLContext(com.sun.xml.tree.ElementNode root, java.lang.String fname)
          Writes a DOM tree to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

private static final java.lang.String VERSION
See Also:
Constant Field Values

DATE

private static final java.lang.String DATE
See Also:
Constant Field Values
Constructor Detail

XMLUtilities

public XMLUtilities()
Method Detail

OpenXMLDocument

public static org.w3c.dom.Document OpenXMLDocument(java.net.URL url)
Creates Document instance from a URL.

Parameters:
url - the URL
Returns:
the Document instance

writeXMLContext

public static void writeXMLContext(com.sun.xml.tree.ElementNode root,
                                   java.lang.String fname)
                            throws java.io.IOException
Writes a DOM tree to a file.

Parameters:
root - the root element node
fname - the file name
Throws:
java.io.IOException

createRootElement

public static com.sun.xml.tree.ElementNode createRootElement(com.sun.xml.tree.XmlDocument document,
                                                             java.lang.String name)
Creates a root element.

Parameters:
document - the XML document
name - the name of the root attribute
Returns:
the root element node

validateDOMDocument

public static org.w3c.dom.Node validateDOMDocument(org.w3c.dom.Document document)
                                            throws org.w3c.dom.DOMException,
                                                   java.lang.NullPointerException
Validates a DOM document.

For now, this method checks the version number inscribed by createRootElement and issues a warning if it differs from the current version. If the document is mal-formed, a fatal error can be generated.

The version checking warning is temporarily disabled in this version.

Parameters:
document - the document
Returns:
the root Node, or null if it fails to open the document.
Throws:
org.w3c.dom.DOMException - NullPointerException
java.lang.NullPointerException

BuildDOMElement

public static void BuildDOMElement(org.w3c.dom.Document document,
                                   com.sun.xml.tree.ElementNode parent,
                                   java.lang.String name,
                                   java.lang.String value)
Builds a DOM element.

Parameters:
document - the document where to build from
parent - the parent element
name - the name of the new element
value - the value of the new element

BuildMapFromNode

public static java.util.Map BuildMapFromNode(org.w3c.dom.Node node)
Builds a map with all the non-text (empty) child nodes in a parent node.

Parameters:
node - the parent node
Returns:
the map with the valid child nodes

BuildNodeList

public static java.util.List BuildNodeList(org.w3c.dom.Node node)
Builds a list with all the non-text (empty) child nodes in a parent node.

Parameters:
node - the parent node
Returns:
the list with the valid child nodes

GetNodeFromMap

public static org.w3c.dom.Node GetNodeFromMap(java.util.Map map,
                                              java.lang.String name)
Gets a named node from a map of nodes. If the supplied name is not found, a null is returned instead.

Parameters:
map - the node map
name - the name of the sought node
Returns:
the node, or null if name not found

GetAttributeValueFromMap

public static java.lang.String GetAttributeValueFromMap(java.util.Map map,
                                                        java.lang.String name,
                                                        java.lang.String attrname)
Gets a named attribute from a node.

Parameters:
map - the map where to get the node from
name - the node name
attrname - the attribute name
Returns:
the attribute value, or null if not found

GetStringValueFromMap

public static java.lang.String GetStringValueFromMap(java.util.Map map,
                                                     java.lang.String name)
Gets a string value from a map of nodes. If the supplied name is not found, null is returned instead.

Parameters:
map - the node map
name - the name of the sought node
Returns:
the string, or null if name not found

GetBooleanValueFromMap

public static boolean GetBooleanValueFromMap(java.util.Map map,
                                             java.lang.String name)
Gets a boolean value from a map of nodes. If the supplied name is not found, false is returned instead.

Parameters:
map - the node map
name - the name of the sought node
Returns:
the value, or false if name not found

GetIntValueFromMap

public static int GetIntValueFromMap(java.util.Map map,
                                     java.lang.String name)
Gets a integer value from a map of nodes. If the supplied name is not found, zero is returned instead.

Parameters:
map - the node map
name - the name of the sought node
Returns:
the value, or zero if name not found

GetDoubleValueFromMap

public static double GetDoubleValueFromMap(java.util.Map map,
                                           java.lang.String name)
Gets a double value from a map of nodes. If the supplied name is not found, NaN is returned instead.

Parameters:
map - the node map
name - the name of the sought node
Returns:
the value, or NaN if name not found

GetObjectFromMap

public static java.lang.Object GetObjectFromMap(java.util.Map map,
                                                java.lang.String name,
                                                java.lang.String class_attr)
Gets an object from a map of nodes.

Parameters:
map - the node map
name - the name of the sought node
class_attr - the class
Returns:
the value