org.openxri.util
Class DOMUtils

java.lang.Object
  extended by org.openxri.util.DOMUtils

public class DOMUtils
extends java.lang.Object

Provides simple, standrard utilities for dealing with DOM. Parts of this code are based on code available from OpenSAML. See www.opensaml.org.

Author:
=chetan

Constructor Summary
DOMUtils()
           
 
Method Summary
static java.util.Date fromXMLDateTime(java.lang.String sTime)
          Converts the specified String in xsd:DateTime format (GMT) to a Java Date object
static org.apache.xerces.parsers.DOMParser getDOMParser()
          Returns a DOMParser object that can safely be used in the current thread.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node n)
          Gets the first child Element of the node, skipping any Text nodes such as whitespace.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node oNode, java.lang.String sNS, java.lang.String sTag)
          Gets the first child Element matching the NS and tag from the given node *
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node oNode)
          Gets the next sibling Element of the node.
static java.lang.String getText(org.w3c.dom.Node root)
          Gets the text string associated with a node
static boolean isElementNamed(org.w3c.dom.Element oElem, java.lang.String sNS, java.lang.String sTag)
          Checks if an element matches the given namespace and tag
static java.lang.String toString(org.w3c.dom.Document doc)
          Converts a Document into a formated XML string.
static java.lang.String toString(org.w3c.dom.Element oElt)
          This is a convenience method to pretty format an Element.
static java.lang.String toString(org.w3c.dom.Element oElt, boolean bIndent, boolean bOmitXMLDeclaration)
          Serializes the specified element.
static java.lang.String toString(org.w3c.dom.Element oElt, org.apache.xml.serialize.OutputFormat oFormat)
          Serializes the specified element.
static java.lang.String toXMLDateTime(java.util.Date oTime)
          Converts the Java Date object to a xsd:DateTime String in GMT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtils

public DOMUtils()
Method Detail

getDOMParser

public static org.apache.xerces.parsers.DOMParser getDOMParser()
Returns a DOMParser object that can safely be used in the current thread. This is done because newing a Xerces DOMParser object is expensive and parser instances are not thread safe.

Returns:
a reset DOMParser object

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node oNode,
                                                       java.lang.String sNS,
                                                       java.lang.String sTag)
Gets the first child Element matching the NS and tag from the given node *

Parameters:
oNode - The node to look under
sNS - The namespace URI of the element
sTag - The tag name of the element to locate
Returns:
The first child Element of oNode with the given ns and tag

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node oNode)
Gets the next sibling Element of the node. Skips over whitespace nodes;

Parameters:
oNode - The sibling to start searching from
Returns:
The next sibling Element of oNode

isElementNamed

public static boolean isElementNamed(org.w3c.dom.Element oElem,
                                     java.lang.String sNS,
                                     java.lang.String sTag)
Checks if an element matches the given namespace and tag


getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node n)
Gets the first child Element of the node, skipping any Text nodes such as whitespace.

Parameters:
n - The parent in which to search for children
Returns:
The first child Element of n, or null if none

toString

public static java.lang.String toString(org.w3c.dom.Element oElt)
This is a convenience method to pretty format an Element. The XML delcaration is included. If you want pretty printing, but not the XML delcaration (or visa-versa), please do not create another method here. Use the most flexible version that already exists.


toString

public static java.lang.String toString(org.w3c.dom.Element oElt,
                                        boolean bIndent,
                                        boolean bOmitXMLDeclaration)
Serializes the specified element.

Parameters:
oElt - - The element to serialize
bIndent - - Whether or not to pretty print
bOmitXMLDeclaration - - Whether or not to omit the XML preamble

toString

public static java.lang.String toString(org.w3c.dom.Element oElt,
                                        org.apache.xml.serialize.OutputFormat oFormat)
Serializes the specified element.

Parameters:
oElt - - The element to serialize
oFormat - - The output format to use

fromXMLDateTime

public static java.util.Date fromXMLDateTime(java.lang.String sTime)
                                      throws java.text.ParseException
Converts the specified String in xsd:DateTime format (GMT) to a Java Date object

Throws:
java.text.ParseException

toXMLDateTime

public static java.lang.String toXMLDateTime(java.util.Date oTime)
Converts the Java Date object to a xsd:DateTime String in GMT.


getText

public static java.lang.String getText(org.w3c.dom.Node root)
Gets the text string associated with a node

Parameters:
root - Node object from which text to be extracted.
Returns:
a string associated with the node

toString

public static java.lang.String toString(org.w3c.dom.Document doc)
Converts a Document into a formated XML string.

Parameters:
doc - Document to be converted into a string.
Returns:
a string representing the formated XML document


Copyright © 2005-2012. All Rights Reserved.