Package org.jboss.util.xml
Class DOMUtils
- java.lang.Object
-
- org.jboss.util.xml.DOMUtils
-
public final class DOMUtils extends java.lang.Object
DOM2 utilites- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ThreadLocal
builderThreadLocal
private static java.lang.ThreadLocal
documentThreadLocal
private static org.jboss.logging.Logger
log
-
Constructor Summary
Constructors Modifier Constructor Description private
DOMUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyAttributes(org.w3c.dom.Element destElement, org.w3c.dom.Element srcElement)
Copy attributes between elementsstatic org.w3c.dom.Element
createElement(java.lang.String localPart)
Create an Element for a given namestatic org.w3c.dom.Element
createElement(java.lang.String localPart, java.lang.String prefix)
Create an Element for a given name and prefixstatic org.w3c.dom.Element
createElement(java.lang.String localPart, java.lang.String prefix, java.lang.String uri)
Create an Element for a given name, prefix and uristatic org.w3c.dom.Element
createElement(javax.xml.namespace.QName qname)
Create an Element for a given QNamestatic org.w3c.dom.Text
createTextNode(java.lang.String value)
Create a org.w3c.dom.Text nodestatic java.util.Map
getAttributes(org.w3c.dom.Element el)
static java.lang.String
getAttributeValue(org.w3c.dom.Element el, java.lang.String attrName)
Get the value from the given attributestatic java.lang.String
getAttributeValue(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
Get the value from the given attributestatic boolean
getAttributeValueAsBoolean(org.w3c.dom.Element el, java.lang.String attrName)
static boolean
getAttributeValueAsBoolean(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
static java.lang.Integer
getAttributeValueAsInteger(org.w3c.dom.Element el, java.lang.String attrName)
static java.lang.Integer
getAttributeValueAsInteger(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
static javax.xml.namespace.QName
getAttributeValueAsQName(org.w3c.dom.Element el, java.lang.String attrName)
static javax.xml.namespace.QName
getAttributeValueAsQName(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
static java.util.Iterator
getChildElements(org.w3c.dom.Node node)
Gets child elementsstatic java.util.Iterator
getChildElements(org.w3c.dom.Node node, java.lang.String nodeName)
Gets the child elements for a given local name without namespacestatic java.util.Iterator
getChildElements(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
Gets the child element for a given qnameprivate static java.util.Iterator
getChildElementsIntern(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
static javax.xml.parsers.DocumentBuilder
getDocumentBuilder()
static javax.xml.namespace.QName
getElementQName(org.w3c.dom.Element el)
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node node)
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node node, java.lang.String nodeName)
static org.w3c.dom.Element
getFirstChildElement(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
private static org.w3c.dom.Element
getFirstChildElementIntern(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
static org.w3c.dom.Document
getOwnerDocument()
static org.w3c.dom.Element
getParentElement(org.w3c.dom.Node node)
Gets parent element or null if there is nonestatic java.lang.String
getTextContent(org.w3c.dom.Node node)
Get the concatenated text content, or null.static java.lang.String
getTextContent(org.w3c.dom.Node node, boolean replaceProps)
Get the concatenated text content, or null.static boolean
hasChildElements(org.w3c.dom.Node node)
True if the node has child elementsstatic org.w3c.dom.Element
parse(java.io.InputStream xmlStream)
Parse the given XML stream and return the root Elementstatic org.w3c.dom.Element
parse(java.lang.String xmlString)
Parse the given XML string and return the root Elementstatic org.w3c.dom.Element
parse(org.xml.sax.InputSource source)
Parse the given input source and return the root Elementstatic javax.xml.namespace.QName
resolveQName(org.w3c.dom.Element el, java.lang.String qualifiedName)
Transform the giveen qualified name into a QName
-
-
-
Method Detail
-
getDocumentBuilder
public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
-
parse
public static org.w3c.dom.Element parse(java.lang.String xmlString) throws java.io.IOException
Parse the given XML string and return the root Element- Parameters:
xmlString
-- Returns:
- the element
- Throws:
java.io.IOException
-
parse
public static org.w3c.dom.Element parse(java.io.InputStream xmlStream) throws java.io.IOException
Parse the given XML stream and return the root Element- Parameters:
xmlStream
-- Returns:
- the element
- Throws:
java.io.IOException
-
parse
public static org.w3c.dom.Element parse(org.xml.sax.InputSource source) throws java.io.IOException
Parse the given input source and return the root Element- Parameters:
source
-- Returns:
- the element
- Throws:
java.io.IOException
-
createElement
public static org.w3c.dom.Element createElement(java.lang.String localPart)
Create an Element for a given name- Parameters:
localPart
-- Returns:
- the element
-
createElement
public static org.w3c.dom.Element createElement(java.lang.String localPart, java.lang.String prefix)
Create an Element for a given name and prefix- Parameters:
localPart
-prefix
-- Returns:
- the element
-
createElement
public static org.w3c.dom.Element createElement(java.lang.String localPart, java.lang.String prefix, java.lang.String uri)
Create an Element for a given name, prefix and uri- Parameters:
localPart
-prefix
-uri
-- Returns:
- the element
-
createElement
public static org.w3c.dom.Element createElement(javax.xml.namespace.QName qname)
Create an Element for a given QName- Parameters:
qname
-- Returns:
- the element
-
createTextNode
public static org.w3c.dom.Text createTextNode(java.lang.String value)
Create a org.w3c.dom.Text node- Parameters:
value
-- Returns:
- the text node
-
getElementQName
public static javax.xml.namespace.QName getElementQName(org.w3c.dom.Element el)
- Parameters:
el
-- Returns:
- the qname of the given node.
-
resolveQName
public static javax.xml.namespace.QName resolveQName(org.w3c.dom.Element el, java.lang.String qualifiedName)
Transform the giveen qualified name into a QName- Parameters:
el
-qualifiedName
-- Returns:
- the resolved name
-
getAttributeValue
public static java.lang.String getAttributeValue(org.w3c.dom.Element el, java.lang.String attrName)
Get the value from the given attribute- Parameters:
el
-attrName
-- Returns:
- null if the attribute value is empty or the attribute is not present
-
getAttributeValue
public static java.lang.String getAttributeValue(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
Get the value from the given attribute- Parameters:
el
-attrName
-- Returns:
- null if the attribute value is empty or the attribute is not present
-
getAttributeValueAsQName
public static javax.xml.namespace.QName getAttributeValueAsQName(org.w3c.dom.Element el, java.lang.String attrName)
- Parameters:
el
-attrName
-- Returns:
- the qname value from the given attribute
-
getAttributeValueAsQName
public static javax.xml.namespace.QName getAttributeValueAsQName(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the qname value from the given attribute
-
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(org.w3c.dom.Element el, java.lang.String attrName)
- Parameters:
el
-attrName
-- Returns:
- the boolean value from the given attribute
-
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the boolean value from the given attribute
-
getAttributeValueAsInteger
public static java.lang.Integer getAttributeValueAsInteger(org.w3c.dom.Element el, java.lang.String attrName)
- Parameters:
el
-attrName
-- Returns:
- the integer value from the given attribute
-
getAttributeValueAsInteger
public static java.lang.Integer getAttributeValueAsInteger(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the integer value from the given attribute
-
getAttributes
public static java.util.Map getAttributes(org.w3c.dom.Element el)
- Parameters:
el
-- Returns:
- the attributes as Map
-
copyAttributes
public static void copyAttributes(org.w3c.dom.Element destElement, org.w3c.dom.Element srcElement)
Copy attributes between elements- Parameters:
destElement
-srcElement
-
-
hasChildElements
public static boolean hasChildElements(org.w3c.dom.Node node)
True if the node has child elements- Parameters:
node
-- Returns:
- true when has child elements
-
getChildElements
public static java.util.Iterator getChildElements(org.w3c.dom.Node node)
Gets child elements- Parameters:
node
-- Returns:
- the iterator
-
getTextContent
public static java.lang.String getTextContent(org.w3c.dom.Node node)
Get the concatenated text content, or null.- Parameters:
node
-- Returns:
- getTextContent(node, false).
-
getTextContent
public static java.lang.String getTextContent(org.w3c.dom.Node node, boolean replaceProps)
Get the concatenated text content, or null.- Parameters:
node
- node to search for TEXT_NODE conentreplaceProps
- flag indicating if ${x} property refs should be replace- Returns:
- the text content
-
getFirstChildElement
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
- Parameters:
node
-- Returns:
- the first child element
-
getFirstChildElement
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node, java.lang.String nodeName)
- Parameters:
node
-nodeName
-- Returns:
- the first child element for a given local name without namespace
-
getFirstChildElement
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
- Parameters:
node
-nodeName
-- Returns:
- the first child element for a given qname
-
getFirstChildElementIntern
private static org.w3c.dom.Element getFirstChildElementIntern(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
-
getChildElements
public static java.util.Iterator getChildElements(org.w3c.dom.Node node, java.lang.String nodeName)
Gets the child elements for a given local name without namespace- Parameters:
node
-nodeName
-- Returns:
- the iterator
-
getChildElements
public static java.util.Iterator getChildElements(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
Gets the child element for a given qname- Parameters:
node
-nodeName
-- Returns:
- the iterator
-
getChildElementsIntern
private static java.util.Iterator getChildElementsIntern(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
-
getParentElement
public static org.w3c.dom.Element getParentElement(org.w3c.dom.Node node)
Gets parent element or null if there is none- Parameters:
node
-- Returns:
- the element
-
getOwnerDocument
public static org.w3c.dom.Document getOwnerDocument()
- Returns:
- the owner document that is associated with the current thread
-
-