org.apache.xerces.util

Class DOMUtil


public class DOMUtil
extends java.lang.Object

Some useful utility methods. This class was modified in Xerces2 with a view to abstracting as much as possible away from the representation of the underlying parsed structure (i.e., the DOM). This was done so that, if Xerces ever adopts an in-memory representation more efficient than the DOM (such as a DTM), we should easily be able to convert our schema parsing to utilize it.
Version:
$Id: DOMUtil.java 377647 2006-02-14 06:37:04Z mrglavas $

Constructor Summary

DOMUtil()
This class cannot be instantiated.

Method Summary

static void
copyInto(org.w3c.dom.Node src, org.w3c.dom.Node dest)
Copies the source tree into the specified place in a destination tree.
static org.w3c.dom.DOMException
createDOMException(short code, Throwable cause)
Creates a DOMException.
static org.w3c.dom.ls.LSException
createLSException(short code, Throwable cause)
Creates an LSException.
static String
getAnnotation(org.w3c.dom.Node node)
static org.w3c.dom.Attr
getAttr(org.w3c.dom.Element elem, String name)
static org.w3c.dom.Attr
getAttrNS(org.w3c.dom.Element elem, String nsUri, String localName)
static String
getAttrValue(org.w3c.dom.Element elem, String name)
static String
getAttrValueNS(org.w3c.dom.Element elem, String nsUri, String localName)
static org.w3c.dom.Attr[]
getAttrs(org.w3c.dom.Element elem)
static String
getChildText(org.w3c.dom.Node node)
Returns the concatenated child text of the specified node.
static org.w3c.dom.Document
getDocument(org.w3c.dom.Node node)
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node parent)
Finds and returns the first child element node.
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node parent, String elemName)
Finds and returns the first child node with the given name.
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node parent, String elemName, String attrName, String attrValue)
Finds and returns the first child node with the given name and attribute name, value pair.
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node parent, elemNames[] )
Finds and returns the first child node with the given name.
static org.w3c.dom.Element
getFirstChildElementNS(org.w3c.dom.Node parent, String uri, String localpart)
Finds and returns the first child node with the given qualified name.
static org.w3c.dom.Element
getFirstChildElementNS(org.w3c.dom.Node parent, String[][] elemNames)
Finds and returns the first child node with the given qualified name.
static org.w3c.dom.Element
getFirstVisibleChildElement(org.w3c.dom.Node parent)
Finds and returns the first visible child element node.
static org.w3c.dom.Element
getFirstVisibleChildElement(org.w3c.dom.Node parent, Hashtable hiddenNodes)
Finds and returns the first visible child element node.
static org.w3c.dom.Element
getLastChildElement(org.w3c.dom.Node parent)
Finds and returns the last child element node.
static org.w3c.dom.Element
getLastChildElement(org.w3c.dom.Node parent, String elemName)
Finds and returns the last child node with the given name.
static org.w3c.dom.Element
getLastChildElement(org.w3c.dom.Node parent, String elemName, String attrName, String attrValue)
Finds and returns the last child node with the given name and attribute name, value pair.
static org.w3c.dom.Element
getLastChildElement(org.w3c.dom.Node parent, elemNames[] )
Finds and returns the last child node with the given name.
static org.w3c.dom.Element
getLastChildElementNS(org.w3c.dom.Node parent, String uri, String localpart)
Finds and returns the last child node with the given qualified name.
static org.w3c.dom.Element
getLastChildElementNS(org.w3c.dom.Node parent, String[][] elemNames)
Finds and returns the last child node with the given qualified name.
static org.w3c.dom.Element
getLastVisibleChildElement(org.w3c.dom.Node parent)
Finds and returns the last visible child element node.
static org.w3c.dom.Element
getLastVisibleChildElement(org.w3c.dom.Node parent, Hashtable hiddenNodes)
Finds and returns the last visible child element node.
static String
getLocalName(org.w3c.dom.Node node)
returns local name of this element if not null, otherwise returns the name of the node
static String
getName(org.w3c.dom.Node node)
static String
getNamespaceURI(org.w3c.dom.Node node)
static org.w3c.dom.Element
getNextSiblingElement(org.w3c.dom.Node node)
Finds and returns the next sibling element node.
static org.w3c.dom.Element
getNextSiblingElement(org.w3c.dom.Node node, String elemName)
Finds and returns the next sibling node with the given name.
static org.w3c.dom.Element
getNextSiblingElement(org.w3c.dom.Node node, String elemName, String attrName, String attrValue)
Finds and returns the next sibling node with the given name and attribute name, value pair.
static org.w3c.dom.Element
getNextSiblingElement(org.w3c.dom.Node node, elemNames[] )
Finds and returns the next sibling node with the given name.
static org.w3c.dom.Element
getNextSiblingElementNS(org.w3c.dom.Node node, String uri, String localpart)
Finds and returns the next sibling node with the given qualified name.
static org.w3c.dom.Element
getNextSiblingElementNS(org.w3c.dom.Node node, String[][] elemNames)
Finds and returns the next sibling node with the given qualified name.
static org.w3c.dom.Element
getNextVisibleSiblingElement(org.w3c.dom.Node node)
static org.w3c.dom.Element
getNextVisibleSiblingElement(org.w3c.dom.Node node, Hashtable hiddenNodes)
static org.w3c.dom.Element
getParent(org.w3c.dom.Element elem)
static String
getPrefix(org.w3c.dom.Node node)
static org.w3c.dom.Element
getRoot(org.w3c.dom.Document doc)
static String
getSyntheticAnnotation(org.w3c.dom.Node node)
static String
getValue(org.w3c.dom.Attr attribute)
static boolean
isHidden(org.w3c.dom.Node node)
static boolean
isHidden(org.w3c.dom.Node node, Hashtable hiddenNodes)
static void
setHidden(org.w3c.dom.Node node)
static void
setHidden(org.w3c.dom.Node node, Hashtable hiddenNodes)
static void
setVisible(org.w3c.dom.Node node)
static void
setVisible(org.w3c.dom.Node node, Hashtable hiddenNodes)

Constructor Details

DOMUtil

protected DOMUtil()
This class cannot be instantiated.

Method Details

copyInto

public static void copyInto(org.w3c.dom.Node src,
                            org.w3c.dom.Node dest)
            throws org.w3c.dom.DOMException
Copies the source tree into the specified place in a destination tree. The source node and its children are appended as children of the destination node.

Note: This is an iterative implementation.


createDOMException

public static org.w3c.dom.DOMException createDOMException(short code,
                                                          Throwable cause)
Creates a DOMException. On J2SE 1.4 and above the cause for the exception will be set.

createLSException

public static org.w3c.dom.ls.LSException createLSException(short code,
                                                           Throwable cause)
Creates an LSException. On J2SE 1.4 and above the cause for the exception will be set.

getAnnotation

public static String getAnnotation(org.w3c.dom.Node node)

getAttr

public static org.w3c.dom.Attr getAttr(org.w3c.dom.Element elem,
                                       String name)

getAttrNS

public static org.w3c.dom.Attr getAttrNS(org.w3c.dom.Element elem,
                                         String nsUri,
                                         String localName)

getAttrValue

public static String getAttrValue(org.w3c.dom.Element elem,
                                  String name)

getAttrValueNS

public static String getAttrValueNS(org.w3c.dom.Element elem,
                                    String nsUri,
                                    String localName)

getAttrs

public static org.w3c.dom.Attr[] getAttrs(org.w3c.dom.Element elem)

getChildText

public static String getChildText(org.w3c.dom.Node node)
Returns the concatenated child text of the specified node. This method only looks at the immediate children of type Node.TEXT_NODE or the children of any child node that is of type Node.CDATA_SECTION_NODE for the concatenation.
Parameters:
node - The node to look at.

getDocument

public static org.w3c.dom.Document getDocument(org.w3c.dom.Node node)

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent)
Finds and returns the first child element node.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent,
                                                       String elemName)
Finds and returns the first child node with the given name.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent,
                                                       String elemName,
                                                       String attrName,
                                                       String attrValue)
Finds and returns the first child node with the given name and attribute name, value pair.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent,
                                                       elemNames[] )
Finds and returns the first child node with the given name.

getFirstChildElementNS

public static org.w3c.dom.Element getFirstChildElementNS(org.w3c.dom.Node parent,
                                                         String uri,
                                                         String localpart)
Finds and returns the first child node with the given qualified name.

getFirstChildElementNS

public static org.w3c.dom.Element getFirstChildElementNS(org.w3c.dom.Node parent,
                                                         String[][] elemNames)
Finds and returns the first child node with the given qualified name.

getFirstVisibleChildElement

public static org.w3c.dom.Element getFirstVisibleChildElement(org.w3c.dom.Node parent)
Finds and returns the first visible child element node.

getFirstVisibleChildElement

public static org.w3c.dom.Element getFirstVisibleChildElement(org.w3c.dom.Node parent,
                                                              Hashtable hiddenNodes)
Finds and returns the first visible child element node.

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent)
Finds and returns the last child element node. Overload previous method for non-Xerces node impl.

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent,
                                                      String elemName)
Finds and returns the last child node with the given name.

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent,
                                                      String elemName,
                                                      String attrName,
                                                      String attrValue)
Finds and returns the last child node with the given name and attribute name, value pair.

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent,
                                                      elemNames[] )
Finds and returns the last child node with the given name.

getLastChildElementNS

public static org.w3c.dom.Element getLastChildElementNS(org.w3c.dom.Node parent,
                                                        String uri,
                                                        String localpart)
Finds and returns the last child node with the given qualified name.

getLastChildElementNS

public static org.w3c.dom.Element getLastChildElementNS(org.w3c.dom.Node parent,
                                                        String[][] elemNames)
Finds and returns the last child node with the given qualified name.

getLastVisibleChildElement

public static org.w3c.dom.Element getLastVisibleChildElement(org.w3c.dom.Node parent)
Finds and returns the last visible child element node.

getLastVisibleChildElement

public static org.w3c.dom.Element getLastVisibleChildElement(org.w3c.dom.Node parent,
                                                             Hashtable hiddenNodes)
Finds and returns the last visible child element node. Overload previous method for non-Xerces node impl

getLocalName

public static String getLocalName(org.w3c.dom.Node node)
returns local name of this element if not null, otherwise returns the name of the node

getName

public static String getName(org.w3c.dom.Node node)

getNamespaceURI

public static String getNamespaceURI(org.w3c.dom.Node node)

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
Finds and returns the next sibling element node.

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node,
                                                        String elemName)
Finds and returns the next sibling node with the given name.

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node,
                                                        String elemName,
                                                        String attrName,
                                                        String attrValue)
Finds and returns the next sibling node with the given name and attribute name, value pair. Since only elements have attributes, the node returned will be of type Node.ELEMENT_NODE.

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node,
                                                        elemNames[] )
Finds and returns the next sibling node with the given name.

getNextSiblingElementNS

public static org.w3c.dom.Element getNextSiblingElementNS(org.w3c.dom.Node node,
                                                          String uri,
                                                          String localpart)
Finds and returns the next sibling node with the given qualified name.

getNextSiblingElementNS

public static org.w3c.dom.Element getNextSiblingElementNS(org.w3c.dom.Node node,
                                                          String[][] elemNames)
Finds and returns the next sibling node with the given qualified name.

getNextVisibleSiblingElement

public static org.w3c.dom.Element getNextVisibleSiblingElement(org.w3c.dom.Node node)

getNextVisibleSiblingElement

public static org.w3c.dom.Element getNextVisibleSiblingElement(org.w3c.dom.Node node,
                                                               Hashtable hiddenNodes)

getParent

public static org.w3c.dom.Element getParent(org.w3c.dom.Element elem)

getPrefix

public static String getPrefix(org.w3c.dom.Node node)

getRoot

public static org.w3c.dom.Element getRoot(org.w3c.dom.Document doc)

getSyntheticAnnotation

public static String getSyntheticAnnotation(org.w3c.dom.Node node)

getValue

public static String getValue(org.w3c.dom.Attr attribute)

isHidden

public static boolean isHidden(org.w3c.dom.Node node)

isHidden

public static boolean isHidden(org.w3c.dom.Node node,
                               Hashtable hiddenNodes)

setHidden

public static void setHidden(org.w3c.dom.Node node)

setHidden

public static void setHidden(org.w3c.dom.Node node,
                             Hashtable hiddenNodes)

setVisible

public static void setVisible(org.w3c.dom.Node node)

setVisible

public static void setVisible(org.w3c.dom.Node node,
                              Hashtable hiddenNodes)

Copyright B) 1999-2006 The Apache Software Foundation. All Rights Reserved.