org.enhydra.barracuda.core.util.dom
Class DOMUtil

java.lang.Object
  |
  +--org.enhydra.barracuda.core.util.dom.DOMUtil

public class DOMUtil
extends java.lang.Object

DOM related utility functions.


Constructor Summary
DOMUtil()
           
 
Method Summary
static org.w3c.dom.Text findFirstText(org.w3c.dom.Node node)
          Find the first text descendent node of an element.
static org.w3c.dom.Text getFirstText(org.w3c.dom.Node node)
          Gets the first text descendent node of an element.
static java.lang.String getID(org.w3c.dom.Node node)
          Given a Node name, return the "id" attribute if it exists.
static java.lang.String getID(org.w3c.dom.Node node, java.lang.String nullResponse)
          Given a Node name, return the "id" attribute if it exists.
protected static void print(java.io.OutputStream out, java.lang.String s)
           
static void printStackTrace(org.w3c.dom.Node node)
          utility method to recursively print the stack trace for a DOM Node
static void printStackTrace(org.w3c.dom.Node node, int depth, java.io.OutputStream out)
          utility method to recursively print the stack trace for a DOM Node Bounds:
If depth < 0, the method returns immediately
static void removeAllTextNodes(org.w3c.dom.Node node)
          Remove all text nodes below this node
static org.w3c.dom.Node setTextInNode(org.w3c.dom.Node node, java.lang.String text, boolean allowMarkupInText)
          Automatically set text in a Node.
 
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

findFirstText

public static org.w3c.dom.Text findFirstText(org.w3c.dom.Node node)
Find the first text descendent node of an element. This recursively looks more than one level to search for text in font nodes, etc.

Parameters:
node - The starting node for the search.
Returns:
The text node or null if not found.

getFirstText

public static org.w3c.dom.Text getFirstText(org.w3c.dom.Node node)
Gets the first text descendent node of an element. This recursively looks more than one level to search for text in font nodes, etc. Throws a DOMException if the Text object is not found.

Parameters:
node - The starting node for the search.
Returns:
The text node or null if not found.
Throws:
org.w3c.dom.DOMException - if the Text object is not found

setTextInNode

public static org.w3c.dom.Node setTextInNode(org.w3c.dom.Node node,
                                             java.lang.String text,
                                             boolean allowMarkupInText)
Automatically set text in a Node. Basically we find the first Text node beneath the current node and replace it with a CDATASection for the incoming text. All other Text nodes are removed. Throws a DOMException if it's illegal to add a Text child to the particular node.

Parameters:
node - the starting node for the search.
Returns:
the updated node
Throws:
org.w3c.dom.DOMException - if the Text object is not found

removeAllTextNodes

public static void removeAllTextNodes(org.w3c.dom.Node node)
Remove all text nodes below this node

Parameters:
node - The starting node for the search.

getID

public static java.lang.String getID(org.w3c.dom.Node node)
Given a Node name, return the "id" attribute if it exists. If it does not exist, return null instead. This is basically just a convenience method to cast the node to element and return the id from that.

Parameters:
node - the node name in question
Returns:
the id value for the given node, if it exists. null if doesn't

getID

public static java.lang.String getID(org.w3c.dom.Node node,
                                     java.lang.String nullResponse)
Given a Node name, return the "id" attribute if it exists. If it does not exist, return nullResponse instead. This is basically just a convenience method to cast the node to element and return the id from that.

Parameters:
node - the node name in question
nullResponse - the response to be returned if the id attribute does not exist
Returns:
the id value for the given node, if it exists. null if doesn't

printStackTrace

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

utility method to recursively print the stack trace for a DOM Node


printStackTrace

public static void printStackTrace(org.w3c.dom.Node node,
                                   int depth,
                                   java.io.OutputStream out)

utility method to recursively print the stack trace for a DOM Node

Bounds:
If depth < 0, the method returns immediately

Parameters:
out - OutputStream to print to

print

protected static void print(java.io.OutputStream out,
                            java.lang.String s)


Copyright © 2001 Enhydra.org