org.apache.servicemix.common.util
Class DOMUtil

java.lang.Object
  extended by org.apache.servicemix.common.util.DOMUtil

public final class DOMUtil
extends java.lang.Object

A collection of W3C DOM helper methods.

Version:
$Revision: 564607 $

Method Summary
static void addChildElement(org.w3c.dom.Element element, java.lang.String name, java.lang.Object textValue)
           Adds the child element with the given text.
static java.lang.String asIndentedXML(org.w3c.dom.Node node)
           A helper method useful for debugging and logging which will convert the given DOM node into XML text.
static java.lang.String asXML(org.w3c.dom.Node node)
           A helper method useful for debugging and logging which will convert the given DOM node into XML text.
static void copyAttributes(org.w3c.dom.Element from, org.w3c.dom.Element to)
           Copy the attribues on one element to the other.
static javax.xml.namespace.QName createQName(org.w3c.dom.Element element, java.lang.String qualifiedName)
           Creates a QName instance from the given namespace context for the given qualifiedName.
static javax.xml.parsers.DocumentBuilder getBuilder()
           
static java.lang.String getElementText(org.w3c.dom.Element element)
           Returns the text of the element.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent)
           Gets the first child element.
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Element el)
           Gets the next sibling element.
static javax.xml.namespace.QName getQName(org.w3c.dom.Element el)
           Builds a QName from the element name.
static void moveContent(org.w3c.dom.Element from, org.w3c.dom.Element to)
           Moves the content of the given element to the given element.
static org.w3c.dom.Document newDocument()
           Returns a new document, ready to populate.
static java.lang.String recursiveGetAttributeValue(org.w3c.dom.Element element, java.lang.String attributeName)
           Recursive method to find a given attribute value.
static void releaseBuilder(javax.xml.parsers.DocumentBuilder builder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getElementText

public static java.lang.String getElementText(org.w3c.dom.Element element)

Returns the text of the element.

Parameters:
element - the element.
Returns:
the element text value.

moveContent

public static void moveContent(org.w3c.dom.Element from,
                               org.w3c.dom.Element to)

Moves the content of the given element to the given element.

Parameters:
from - the source element.
to - the destination element.

copyAttributes

public static void copyAttributes(org.w3c.dom.Element from,
                                  org.w3c.dom.Element to)

Copy the attribues on one element to the other.

Parameters:
from - the source element.
to - the destination element.

asXML

public static java.lang.String asXML(org.w3c.dom.Node node)
                              throws javax.xml.transform.TransformerException

A helper method useful for debugging and logging which will convert the given DOM node into XML text.

Parameters:
node - the node.
Returns:
a raw XML string representing the node.
Throws:
javax.xml.transform.TransformerException

asIndentedXML

public static java.lang.String asIndentedXML(org.w3c.dom.Node node)
                                      throws javax.xml.transform.TransformerException

A helper method useful for debugging and logging which will convert the given DOM node into XML text.

Parameters:
node - the node.
Returns:
a indented XML string representing the node.
Throws:
javax.xml.transform.TransformerException

addChildElement

public static void addChildElement(org.w3c.dom.Element element,
                                   java.lang.String name,
                                   java.lang.Object textValue)

Adds the child element with the given text.

Parameters:
element - the element where to add child.
name - the child elenemt name.
textValue - the child element text value.

createQName

public static javax.xml.namespace.QName createQName(org.w3c.dom.Element element,
                                                    java.lang.String qualifiedName)

Creates a QName instance from the given namespace context for the given qualifiedName.

Parameters:
element - the element to use as the namespace context.
qualifiedName - the fully qualified name.
Returns:
the QName which matches the qualifiedName.

recursiveGetAttributeValue

public static java.lang.String recursiveGetAttributeValue(org.w3c.dom.Element element,
                                                          java.lang.String attributeName)

Recursive method to find a given attribute value.

Parameters:
element - the element where to looking for attribute.
attributeName - the attribute name to look for.
Returns:
the value of the given attribute.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent)

Gets the first child element.

Parameters:
parent - the parent node.
Returns:
the first child element.

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Element el)

Gets the next sibling element.

Parameters:
el - the base element.
Returns:
the next sibling element.

getQName

public static javax.xml.namespace.QName getQName(org.w3c.dom.Element el)

Builds a QName from the element name.

Parameters:
el - the element.
Returns:
the QName for the given element.

getBuilder

public static javax.xml.parsers.DocumentBuilder getBuilder()
                                                    throws javax.xml.parsers.ParserConfigurationException
Throws:
javax.xml.parsers.ParserConfigurationException

releaseBuilder

public static void releaseBuilder(javax.xml.parsers.DocumentBuilder builder)

newDocument

public static org.w3c.dom.Document newDocument()
                                        throws javax.xml.parsers.ParserConfigurationException

Returns a new document, ready to populate.

Returns:
a ready to use Document.
Throws:
javax.xml.parsers.ParserConfigurationException


Copyright © 2005-2012 FuseSource. All Rights Reserved.