Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.chiba.xml.util
Class DOMUtil  view DOMUtil download DOMUtil.java

java.lang.Object
  extended byorg.chiba.xml.util.DOMUtil

public class DOMUtil
extends java.lang.Object


Constructor Summary
DOMUtil()
           
 
Method Summary
static void copyAttributes(org.w3c.dom.Element from, org.w3c.dom.Element to, org.w3c.dom.traversal.NodeFilter filter)
          copies all attributes from one Element to another
static int countChildElements(org.w3c.dom.Node node)
           
private static javax.xml.parsers.DocumentBuilder createDocumentBuilder(boolean namespaces, boolean validating)
           
static org.w3c.dom.Element findFirstChild(org.w3c.dom.Node parent, java.lang.String tagName)
          find the first child in a parent for a tagname part (only one the child level)
static org.w3c.dom.Element findFirstChildNS(org.w3c.dom.Node parent, java.lang.String nsuri, java.lang.String tagName)
          find the first child in a parent for a namespace uri and local name part (equals "/tagName[1]" in xpath)
static org.w3c.dom.Element findLastChild(org.w3c.dom.Node parent, java.lang.String tagName)
          find the last child in a parent for a tagname part
static org.w3c.dom.Element findLastChildNS(org.w3c.dom.Node parent, java.lang.String nsuri, java.lang.String tagName)
          find the last child in a parent for a namespace uri and local name part
static org.w3c.dom.Node findNthChildNS(org.w3c.dom.Node contextNode, java.lang.String nsuri, java.lang.String tag, int idx)
          find the nth child in a parent for a namespace uri and local name part (equals "/tagName[idx]" in xpath)
static org.w3c.dom.Element getChildElement(org.w3c.dom.Node start, java.lang.String name)
           
static java.util.List getChildElements(org.w3c.dom.Node start)
          returns a java.util.List of Elements which are children of the start Element.
static int getCurrentListPosition(org.w3c.dom.Node refNode, org.w3c.dom.NodeList list)
          returns an element's position in the given NodeList
static int getCurrentPosition(org.w3c.dom.Node refNode)
          returns an element's position in the list of its siblings.
static org.w3c.dom.Element getElementByAttributeValue(org.w3c.dom.Node start, java.lang.String tagName, java.lang.String attrName, java.lang.String attrValue)
          equivalent to the XPath expression './/tagName[@attrName='attrValue']'
static org.w3c.dom.Element getElementByAttributeValueNS(org.w3c.dom.Node start, java.lang.String tnuri, java.lang.String tagName, java.lang.String anuri, java.lang.String attrName, java.lang.String attrValue)
          equivalent to the XPath expression './/tnuri:tagName[@anuri:attrName='attrValue']'
static org.w3c.dom.Node getFirstChildByTagName(org.w3c.dom.Node contextNode, java.lang.String tag)
          returns the first child of the contextnode which has the specified tagname regardless of the depth in the tree.
static org.w3c.dom.Node getFirstChildByTagNameNS(org.w3c.dom.Node contextNode, java.lang.String nsuri, java.lang.String tag)
          returns the first child of the contextnode which has the specified tagname and namespace uri regardless of the depth in the tree.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node start)
          gets the first child of a node which is an element.
static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node start)
           
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
          Returns the next sibling element of the specified node.
static org.w3c.dom.Element getPreviousSiblingElement(org.w3c.dom.Node node)
          Returns the previous sibling element of the specified node.
static org.w3c.dom.Node getTextNode(org.w3c.dom.Node start)
          gets the first child of a node which is a text or cdata node.
static java.lang.String getTextNodeAsString(org.w3c.dom.Node start)
          returns the Text-Node child of Node 'start' as String.
static boolean hasChild(org.w3c.dom.Element start, java.lang.String name)
           
static boolean hasElementChildren(org.w3c.dom.Element element)
          just the same as hasNonWhitespaceChildren, but seen from a different perspective ;)
static boolean hasNonWhitespaceChildren(org.w3c.dom.Element element)
          check, if the passed element node has non-whitespace children.
static org.w3c.dom.Node importNode(org.w3c.dom.Document document, org.w3c.dom.Node toImport)
          This is a workaround for very strange behaviour of xerces-1.4.2 DOM importNode.
static void insertAfter(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
           
static boolean isNodeInNS(org.w3c.dom.Node nodeToCompare, java.lang.String nsuri, java.lang.String tagName)
           
static void moveChild(org.w3c.dom.NodeList nodelist, int index, int step)
          Moves a child the given index in a nodelist for a given number of steps.
static org.w3c.dom.Document newDocument(boolean isNamespaceAware, boolean isValidating)
           
static org.w3c.dom.Document parseInputStream(java.io.InputStream in, boolean namespaces, boolean validating)
           
static org.w3c.dom.Document parseXmlFile(java.io.File file, boolean namespaces, boolean validating)
           
static org.w3c.dom.Document parseXmlFile(java.lang.String fileName, boolean namespaces, boolean validating)
          parses a Xml-File on disk and returns the parsed DOM Document.
static void prettyPrintDOM(org.w3c.dom.Node node)
           
static void prettyPrintDOM(org.w3c.dom.Node node, java.io.OutputStream stream)
           
static java.util.List selectNodesByPath(org.w3c.dom.Node context, java.lang.String nsuri, java.lang.String bindingExpr)
          Selects a nodelist for a path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtil

public DOMUtil()
Method Detail

getChildElements

public static java.util.List getChildElements(org.w3c.dom.Node start)
returns a java.util.List of Elements which are children of the start Element.


hasChild

public static boolean hasChild(org.w3c.dom.Element start,
                               java.lang.String name)

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Node start,
                                                  java.lang.String name)

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node start)
gets the first child of a node which is an element. This avoids the whitespace problems when using org.w3c.dom.node.getFirstChild(). Whitespace-nodes may also appear as children, but normally are not what you're looking for.


getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node start)

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
Returns the next sibling element of the specified node.

If there is no such element, this method returns null.


getPreviousSiblingElement

public static org.w3c.dom.Element getPreviousSiblingElement(org.w3c.dom.Node node)
Returns the previous sibling element of the specified node.

If there is no such element, this method returns null.


getTextNode

public static org.w3c.dom.Node getTextNode(org.w3c.dom.Node start)
gets the first child of a node which is a text or cdata node.


getTextNodeAsString

public static java.lang.String getTextNodeAsString(org.w3c.dom.Node start)
returns the Text-Node child of Node 'start' as String. If no TextNode exists, null is returned.


getElementByAttributeValueNS

public static org.w3c.dom.Element getElementByAttributeValueNS(org.w3c.dom.Node start,
                                                               java.lang.String tnuri,
                                                               java.lang.String tagName,
                                                               java.lang.String anuri,
                                                               java.lang.String attrName,
                                                               java.lang.String attrValue)
equivalent to the XPath expression './/tnuri:tagName[@anuri:attrName='attrValue']'


getElementByAttributeValue

public static org.w3c.dom.Element getElementByAttributeValue(org.w3c.dom.Node start,
                                                             java.lang.String tagName,
                                                             java.lang.String attrName,
                                                             java.lang.String attrValue)
equivalent to the XPath expression './/tagName[@attrName='attrValue']'


getFirstChildByTagName

public static org.w3c.dom.Node getFirstChildByTagName(org.w3c.dom.Node contextNode,
                                                      java.lang.String tag)
returns the first child of the contextnode which has the specified tagname regardless of the depth in the tree.


getFirstChildByTagNameNS

public static org.w3c.dom.Node getFirstChildByTagNameNS(org.w3c.dom.Node contextNode,
                                                        java.lang.String nsuri,
                                                        java.lang.String tag)
returns the first child of the contextnode which has the specified tagname and namespace uri regardless of the depth in the tree.


selectNodesByPath

public static java.util.List selectNodesByPath(org.w3c.dom.Node context,
                                               java.lang.String nsuri,
                                               java.lang.String bindingExpr)
Selects a nodelist for a path. the path is a simple slash seperated path expression pointing to a node.

for a tree:


   
     
       
       
     
     
   
 
 ]]>
the path /a/b/c/d returns a list with the two <d> elements. the path /a/b/c returns a list with one path element.

the path is resolved always against a context node, and therefor may or may not begin with a slash.


moveChild

public static void moveChild(org.w3c.dom.NodeList nodelist,
                             int index,
                             int step)
Moves a child the given index in a nodelist for a given number of steps.


findLastChild

public static org.w3c.dom.Element findLastChild(org.w3c.dom.Node parent,
                                                java.lang.String tagName)
find the last child in a parent for a tagname part


findLastChildNS

public static org.w3c.dom.Element findLastChildNS(org.w3c.dom.Node parent,
                                                  java.lang.String nsuri,
                                                  java.lang.String tagName)
find the last child in a parent for a namespace uri and local name part


insertAfter

public static void insertAfter(org.w3c.dom.Node newChild,
                               org.w3c.dom.Node refChild)
                        throws org.w3c.dom.DOMException

findFirstChild

public static org.w3c.dom.Element findFirstChild(org.w3c.dom.Node parent,
                                                 java.lang.String tagName)
find the first child in a parent for a tagname part (only one the child level)


findFirstChildNS

public static org.w3c.dom.Element findFirstChildNS(org.w3c.dom.Node parent,
                                                   java.lang.String nsuri,
                                                   java.lang.String tagName)
find the first child in a parent for a namespace uri and local name part (equals "/tagName[1]" in xpath)


findNthChildNS

public static org.w3c.dom.Node findNthChildNS(org.w3c.dom.Node contextNode,
                                              java.lang.String nsuri,
                                              java.lang.String tag,
                                              int idx)
find the nth child in a parent for a namespace uri and local name part (equals "/tagName[idx]" in xpath)


prettyPrintDOM

public static void prettyPrintDOM(org.w3c.dom.Node node,
                                  java.io.OutputStream stream)
                           throws java.io.IOException

prettyPrintDOM

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

getCurrentPosition

public static int getCurrentPosition(org.w3c.dom.Node refNode)
returns an element's position in the list of its siblings.


getCurrentListPosition

public static int getCurrentListPosition(org.w3c.dom.Node refNode,
                                         org.w3c.dom.NodeList list)
returns an element's position in the given NodeList


isNodeInNS

public static boolean isNodeInNS(org.w3c.dom.Node nodeToCompare,
                                 java.lang.String nsuri,
                                 java.lang.String tagName)

newDocument

public static org.w3c.dom.Document newDocument(boolean isNamespaceAware,
                                               boolean isValidating)

copyAttributes

public static void copyAttributes(org.w3c.dom.Element from,
                                  org.w3c.dom.Element to,
                                  org.w3c.dom.traversal.NodeFilter filter)
copies all attributes from one Element to another


hasNonWhitespaceChildren

public static boolean hasNonWhitespaceChildren(org.w3c.dom.Element element)
check, if the passed element node has non-whitespace children.


hasElementChildren

public static boolean hasElementChildren(org.w3c.dom.Element element)
just the same as hasNonWhitespaceChildren, but seen from a different perspective ;)


importNode

public static org.w3c.dom.Node importNode(org.w3c.dom.Document document,
                                          org.w3c.dom.Node toImport)
This is a workaround for very strange behaviour of xerces-1.4.2 DOM importNode.


countChildElements

public static int countChildElements(org.w3c.dom.Node node)

parseXmlFile

public static org.w3c.dom.Document parseXmlFile(java.lang.String fileName,
                                                boolean namespaces,
                                                boolean validating)
                                         throws javax.xml.parsers.ParserConfigurationException,
                                                org.xml.sax.SAXException,
                                                java.io.IOException
parses a Xml-File on disk and returns the parsed DOM Document.


parseXmlFile

public static org.w3c.dom.Document parseXmlFile(java.io.File file,
                                                boolean namespaces,
                                                boolean validating)
                                         throws javax.xml.parsers.ParserConfigurationException,
                                                org.xml.sax.SAXException,
                                                java.io.IOException

parseInputStream

public static org.w3c.dom.Document parseInputStream(java.io.InputStream in,
                                                    boolean namespaces,
                                                    boolean validating)
                                             throws javax.xml.parsers.ParserConfigurationException,
                                                    org.xml.sax.SAXException,
                                                    java.io.IOException

createDocumentBuilder

private static javax.xml.parsers.DocumentBuilder createDocumentBuilder(boolean namespaces,
                                                                       boolean validating)
                                                                throws javax.xml.parsers.ParserConfigurationException