Package org.jboss.security.util.xml
Class DOMUtils
- java.lang.Object
-
- org.jboss.security.util.xml.DOMUtils
-
public final class DOMUtils extends Object
DOM2 utilites- Version:
- $Revision$
- Author:
- Thomas.Diesler@jboss.org
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyAttributes(Element destElement, Element srcElement)
Copy attributes between elementsstatic Element
createElement(String localPart)
Create an Element for a given namestatic Element
createElement(String localPart, String prefix)
Create an Element for a given name and prefixstatic Element
createElement(String localPart, String prefix, String uri)
Create an Element for a given name, prefix and uristatic Element
createElement(QName qname)
Create an Element for a given QNamestatic Text
createTextNode(String value)
Create a org.w3c.dom.Text nodestatic Map
getAttributes(Element el)
static String
getAttributeValue(Element el, String attrName)
Get the value from the given attributestatic String
getAttributeValue(Element el, QName attrName)
Get the value from the given attributestatic boolean
getAttributeValueAsBoolean(Element el, String attrName)
static boolean
getAttributeValueAsBoolean(Element el, QName attrName)
static Integer
getAttributeValueAsInteger(Element el, String attrName)
static Integer
getAttributeValueAsInteger(Element el, QName attrName)
static QName
getAttributeValueAsQName(Element el, String attrName)
static QName
getAttributeValueAsQName(Element el, QName attrName)
static Iterator
getChildElements(Node node)
Gets child elementsstatic Iterator
getChildElements(Node node, String nodeName)
Gets the child elements for a given local name without namespacestatic Iterator
getChildElements(Node node, QName nodeName)
Gets the child element for a given qnamestatic DocumentBuilder
getDocumentBuilder()
static QName
getElementQName(Element el)
static Element
getFirstChildElement(Node node)
static Element
getFirstChildElement(Node node, String nodeName)
static Element
getFirstChildElement(Node node, QName nodeName)
static Document
getOwnerDocument()
static Element
getParentElement(Node node)
Gets parent element or null if there is nonestatic String
getTextContent(Node node)
Get the concatenated text content, or null.static String
getTextContent(Node node, boolean replaceProps)
Get the concatenated text content, or null.static boolean
hasChildElements(Node node)
True if the node has child elementsstatic Element
parse(InputStream xmlStream)
Parse the given XML stream and return the root Elementstatic Element
parse(String xmlString)
Parse the given XML string and return the root Elementstatic Element
parse(InputSource source)
Parse the given input source and return the root Elementstatic QName
resolveQName(Element el, String qualifiedName)
Transform the giveen qualified name into a QName
-
-
-
Method Detail
-
getDocumentBuilder
public static DocumentBuilder getDocumentBuilder()
-
parse
public static Element parse(String xmlString) throws IOException
Parse the given XML string and return the root Element- Parameters:
xmlString
-- Returns:
- the element
- Throws:
IOException
-
parse
public static Element parse(InputStream xmlStream) throws IOException
Parse the given XML stream and return the root Element- Parameters:
xmlStream
-- Returns:
- the element
- Throws:
IOException
-
parse
public static Element parse(InputSource source) throws IOException
Parse the given input source and return the root Element- Parameters:
source
-- Returns:
- the element
- Throws:
IOException
-
createElement
public static Element createElement(String localPart)
Create an Element for a given name- Parameters:
localPart
-- Returns:
- the element
-
createElement
public static Element createElement(String localPart, String prefix)
Create an Element for a given name and prefix- Parameters:
localPart
-prefix
-- Returns:
- the element
-
createElement
public static Element createElement(String localPart, String prefix, String uri)
Create an Element for a given name, prefix and uri- Parameters:
localPart
-prefix
-uri
-- Returns:
- the element
-
createElement
public static Element createElement(QName qname)
Create an Element for a given QName- Parameters:
qname
-- Returns:
- the element
-
createTextNode
public static Text createTextNode(String value)
Create a org.w3c.dom.Text node- Parameters:
value
-- Returns:
- the text node
-
getElementQName
public static QName getElementQName(Element el)
- Parameters:
el
-- Returns:
- the qname of the given node.
-
resolveQName
public static QName resolveQName(Element el, String qualifiedName)
Transform the giveen qualified name into a QName- Parameters:
el
-qualifiedName
-- Returns:
- the resolved name
-
getAttributeValue
public static String getAttributeValue(Element el, 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 String getAttributeValue(Element el, 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 QName getAttributeValueAsQName(Element el, String attrName)
- Parameters:
el
-attrName
-- Returns:
- the qname value from the given attribute
-
getAttributeValueAsQName
public static QName getAttributeValueAsQName(Element el, QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the qname value from the given attribute
-
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(Element el, String attrName)
- Parameters:
el
-attrName
-- Returns:
- the boolean value from the given attribute
-
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the boolean value from the given attribute
-
getAttributeValueAsInteger
public static Integer getAttributeValueAsInteger(Element el, String attrName)
- Parameters:
el
-attrName
-- Returns:
- the integer value from the given attribute
-
getAttributeValueAsInteger
public static Integer getAttributeValueAsInteger(Element el, QName attrName)
- Parameters:
el
-attrName
-- Returns:
- the integer value from the given attribute
-
getAttributes
public static Map getAttributes(Element el)
- Parameters:
el
-- Returns:
- the attributes as Map
-
copyAttributes
public static void copyAttributes(Element destElement, Element srcElement)
Copy attributes between elements- Parameters:
destElement
-srcElement
-
-
hasChildElements
public static boolean hasChildElements(Node node)
True if the node has child elements- Parameters:
node
-- Returns:
- true when has child elements
-
getChildElements
public static Iterator getChildElements(Node node)
Gets child elements- Parameters:
node
-- Returns:
- the iterator
-
getTextContent
public static String getTextContent(Node node)
Get the concatenated text content, or null.- Parameters:
node
-- Returns:
- getTextContent(node, false).
-
getTextContent
public static String getTextContent(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 Element getFirstChildElement(Node node)
- Parameters:
node
-- Returns:
- the first child element
-
getFirstChildElement
public static Element getFirstChildElement(Node node, String nodeName)
- Parameters:
node
-nodeName
-- Returns:
- the first child element for a given local name without namespace
-
getFirstChildElement
public static Element getFirstChildElement(Node node, QName nodeName)
- Parameters:
node
-nodeName
-- Returns:
- the first child element for a given qname
-
getChildElements
public static Iterator getChildElements(Node node, String nodeName)
Gets the child elements for a given local name without namespace- Parameters:
node
-nodeName
-- Returns:
- the iterator
-
getChildElements
public static Iterator getChildElements(Node node, QName nodeName)
Gets the child element for a given qname- Parameters:
node
-nodeName
-- Returns:
- the iterator
-
getParentElement
public static Element getParentElement(Node node)
Gets parent element or null if there is none- Parameters:
node
-- Returns:
- the element
-
getOwnerDocument
public static Document getOwnerDocument()
- Returns:
- the owner document that is associated with the current thread
-
-