Esri Geoportal Server
1.0

com.esri.gpt.framework.xml
Class DomUtil

java.lang.Object
  extended by com.esri.gpt.framework.xml.DomUtil

public class DomUtil
extends Object

XML Document utility functions.


Method Summary
static Node[] findChildren(Node parent, String childTagName)
          Finds the children of a parent node matching the supplied child tag name.
static Node findFirst(Node parent, String childTagName)
          Finds the first child of a parent node based upon the supplied tag name for the child.
static String getAttributeValue(NamedNodeMap nnm, String name)
          Returns an attribute value from a NamedNodeMap.
static String getTextContent(Node parentNode)
          Returns the text node content associated with a parent node.
static Document makeDomFromResourcePath(String path, boolean namespaceAware)
          Makes an XML document associated with a specified resource.
static Document makeDomFromSource(InputSource src, boolean namespaceAware)
          Makes an XML document based upon an input source.
static Document makeDomFromString(String xml, boolean namespaceAware)
          Makes an XML document from an XML string.
static Document newDocument()
          Creates an empty XML document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributeValue

public static String getAttributeValue(NamedNodeMap nnm,
                                       String name)
Returns an attribute value from a NamedNodeMap.

Parameters:
nnm - the NamedNodeMap of attributes
name - the name of the attribute to retrieve
Returns:
the attribute value (trimmed, never null)

getTextContent

public static String getTextContent(Node parentNode)
Returns the text node content associated with a parent node.
The text will be trimmed, a null will be returned as an empty string.

Parameters:
parentNode - the parent node for which text will be extracted
Returns:
the text

findChildren

public static Node[] findChildren(Node parent,
                                  String childTagName)
Finds the children of a parent node matching the supplied child tag name.
This is not recursive, only the immediate children are considered.

Parameters:
parent - the parent containing the children to find
childTagName - the tag name of the child to find
Returns:
an array of matching nodes

findFirst

public static Node findFirst(Node parent,
                             String childTagName)
Finds the first child of a parent node based upon the supplied tag name for the child.
This is not recursive, only the immediate children are considered.

Parameters:
parent - the parent of the child node to find
childTagName - the tag name for the node to find
Returns:
the located node

makeDomFromResourcePath

public static Document makeDomFromResourcePath(String path,
                                               boolean namespaceAware)
                                        throws ParserConfigurationException,
                                               SAXException,
                                               IOException
Makes an XML document associated with a specified resource.

Parameters:
path - the path for the resource (relative to WEB-INF/classes)
namespaceAware - true if the Document should be namespace aware.
Returns:
the XML document
Throws:
ParserConfigurationException - if a configuration exception occurs
SAXException - if an exception occurs during XML parsing
IOException - if an i/o exception occurs

makeDomFromSource

public static Document makeDomFromSource(InputSource src,
                                         boolean namespaceAware)
                                  throws ParserConfigurationException,
                                         SAXException,
                                         IOException
Makes an XML document based upon an input source.

Parameters:
src - the InputSource
namespaceAware - true if the Document should be namespace aware
Returns:
the XML document
Throws:
ParserConfigurationException - if a configuration exception occurs
SAXException - if an exception occurs during XML parsing
IOException - if an i/o exception occurs

makeDomFromString

public static Document makeDomFromString(String xml,
                                         boolean namespaceAware)
                                  throws ParserConfigurationException,
                                         SAXException,
                                         IOException
Makes an XML document from an XML string.

Parameters:
xml - the xml string
namespaceAware - true if the Document should be namespace aware.
Returns:
the XML document
Throws:
ParserConfigurationException - if a configuration exception occurs
SAXException - if an exception occurs during XML parsing
IOException - if an i/o exception occurs

newDocument

public static Document newDocument()
                            throws ParserConfigurationException,
                                   SAXException,
                                   IOException
Creates an empty XML document.

Returns:
the new document
Throws:
ParserConfigurationException - if a configuration exception occurs
SAXException - if an exception occurs during XML parsing
IOException - if an i/o exception occurs

Esri Geoportal Server
1.0

Copyright 2011 Environmental Systems Research Institute. All rights reserved. Use is subject to license terms.