Class 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 elements
      static org.w3c.dom.Element createElement​(java.lang.String localPart)
      Create an Element for a given name
      static org.w3c.dom.Element createElement​(java.lang.String localPart, java.lang.String prefix)
      Create an Element for a given name and prefix
      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
      static org.w3c.dom.Element createElement​(javax.xml.namespace.QName qname)
      Create an Element for a given QName
      static org.w3c.dom.Text createTextNode​(java.lang.String value)
      Create a org.w3c.dom.Text node
      static 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 attribute
      static java.lang.String getAttributeValue​(org.w3c.dom.Element el, javax.xml.namespace.QName attrName)
      Get the value from the given attribute
      static 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 elements
      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
      static java.util.Iterator getChildElements​(org.w3c.dom.Node node, javax.xml.namespace.QName nodeName)
      Gets the child element for a given qname
      private 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 none
      static 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 elements
      static org.w3c.dom.Element parse​(java.io.InputStream xmlStream)
      Parse the given XML stream and return the root Element
      static org.w3c.dom.Element parse​(java.lang.String xmlString)
      Parse the given XML string and return the root Element
      static org.w3c.dom.Element parse​(org.xml.sax.InputSource source)
      Parse the given input source and return the root Element
      static javax.xml.namespace.QName resolveQName​(org.w3c.dom.Element el, java.lang.String qualifiedName)
      Transform the giveen qualified name into a QName
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static org.jboss.logging.Logger log
      • documentThreadLocal

        private static java.lang.ThreadLocal documentThreadLocal
      • builderThreadLocal

        private static java.lang.ThreadLocal builderThreadLocal
    • Constructor Detail

      • DOMUtils

        private DOMUtils()
    • 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 conent
        replaceProps - 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