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

java.lang.Object
  extended byorg.enhydra.barracuda.core.util.dom.DOMUtil

public class DOMUtil
extends Object

DOM related utility functions.


Constructor Summary
DOMUtil()
           
 
Method Summary
static Text findFirstText(Node node)
          Find the first text descendent node of an element.
static Text getFirstText(Node node)
          Gets the first text descendent node of an element.
static String getID(Node node)
          Given a Node name, return the "id" attribute if it exists.
static String getID(Node node, String nullResponse)
          Given a Node, return the "id" attribute if it exists.
protected static void print(OutputStream out, String s)
           
protected static void printChildMarkup(Node node, PrintWriter out, boolean isHtml, boolean skipComments, int depth)
           
static void printMarkup(Node node)
           
static void printMarkup(Node node, PrintWriter out, boolean isHtml, boolean skipComments, int depth)
           
static void printStackTrace(Node node)
          utility method to recursively print the stack trace for a DOM Node
static void printStackTrace(Node node, OutputStream out, int depth)
          utility method to recursively print the stack trace for a DOM Node Bounds:
If depth < 0, the method returns immediately
static void removeAllTextNodes(Node node)
          Remove all text nodes below this node
static Node setTextInNode(Node node, 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 Text findFirstText(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 Text getFirstText(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:
DOMException - if the Text object is not found

setTextInNode

public static Node setTextInNode(Node node,
                                 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.
text - the text to be set
allowMarkupInText - whether to allow markup in text to pass through unparsed
Returns:
the updated node
Throws:
DOMException - if the Text object is not found

removeAllTextNodes

public static void removeAllTextNodes(Node node)
Remove all text nodes below this node

Parameters:
node - The starting node for the search.

getID

public static String getID(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 String getID(Node node,
                           String nullResponse)
Given a Node, 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 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(Node node)

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


printStackTrace

public static void printStackTrace(Node node,
                                   OutputStream out,
                                   int depth)

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

Bounds:
If depth < 0, the method returns immediately

Parameters:
node - the node in question
out - OutputStream to print to
depth - inset depth at which to start printing

print

protected static void print(OutputStream out,
                            String s)

printMarkup

public static void printMarkup(Node node)

printMarkup

public static void printMarkup(Node node,
                               PrintWriter out,
                               boolean isHtml,
                               boolean skipComments,
                               int depth)

printChildMarkup

protected static void printChildMarkup(Node node,
                                       PrintWriter out,
                                       boolean isHtml,
                                       boolean skipComments,
                                       int depth)


Copyright © 2003 BarracudaMVC.org All Rights Reserved.