Class DOMUtils


  • public class DOMUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      DOMUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanString​(java.lang.String orig)  
      static int countKids​(org.w3c.dom.Element elem, short nodeType)
      Count number of children of a certain type of the given element.
      static org.w3c.dom.Element findChildElementWithAttribute​(org.w3c.dom.Element elem, java.lang.String attrName, java.lang.String attrValue)
      Return the first child element of the given element which has the given attribute with the given value.
      static java.lang.String getAttribute​(org.w3c.dom.Element el, java.lang.String attrName)
      Returns the value of an attribute of an element.
      static java.lang.String getAttribute​(org.w3c.dom.Element el, java.lang.String attrName, java.util.List remainingAttrs)
      Returns the value of an attribute of an element.
      static java.lang.String getAttributeNS​(org.w3c.dom.Element el, java.lang.String namespaceURI, java.lang.String localPart)
      Returns the value of an attribute of an element.
      static java.util.List getAttributes​(org.w3c.dom.Element el)
      Returns a list of attributes of an element.
      static java.lang.String getChildCharacterData​(org.w3c.dom.Element parentEl)
      Concat all the text and cdata node children of this elem and return the resulting text.
      static org.w3c.dom.Element getFirstChildElement​(org.w3c.dom.Element elem)
      Return the first child element of the given element.
      static java.lang.String getNamespaceURIFromPrefix​(org.w3c.dom.Node context, java.lang.String prefix)
      Given a prefix and a node, return the namespace URI that the prefix has been associated with.
      static org.w3c.dom.Element getNextSiblingElement​(org.w3c.dom.Element elem)
      Return the next sibling element of the given element.
      static java.lang.String getPrefix​(java.lang.String namespaceURI, Definition def)  
      static javax.xml.namespace.QName getQName​(java.lang.String prefixedValue, org.w3c.dom.Element contextEl, Definition def)  
      static javax.xml.namespace.QName getQualifiedAttributeValue​(org.w3c.dom.Element el, java.lang.String attrName, java.lang.String elDesc, boolean isRequired, Definition def)
      This method should be used for elements that support extension attributes because it does not track the remaining attributes to test for unexpected attributes.
      static javax.xml.namespace.QName getQualifiedAttributeValue​(org.w3c.dom.Element el, java.lang.String attrName, java.lang.String elDesc, boolean isRequired, Definition def, java.util.List remainingAttrs)
      This method should be used for elements that do not support extension attributes because it tracks the remaining attributes so that eventually any unexpected attributes can be identified.
      static java.lang.String getQualifiedValue​(java.lang.String namespaceURI, java.lang.String localPart, Definition def)  
      static void printAttribute​(java.lang.String name, java.lang.String value, java.io.PrintWriter pw)  
      static void printQualifiedAttribute​(java.lang.String name, javax.xml.namespace.QName value, Definition def, java.io.PrintWriter pw)  
      static void printQualifiedAttribute​(javax.xml.namespace.QName name, java.lang.String value, Definition def, java.io.PrintWriter pw)
      Prints attributes with qualified names.
      static void printQualifiedAttribute​(javax.xml.namespace.QName name, javax.xml.namespace.QName value, Definition def, java.io.PrintWriter pw)  
      static void registerUniquePrefix​(java.lang.String prefix, java.lang.String namespaceURI, Definition def)  
      static void throwWSDLException​(org.w3c.dom.Element location)  
      • Methods inherited from class java.lang.Object

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

      • DOMUtils

        public DOMUtils()
    • Method Detail

      • getAttributes

        public static java.util.List getAttributes​(org.w3c.dom.Element el)
        Returns a list of attributes of an element. Returns an empty list if the element has no attributes. Does not include namespace declarations.
        Parameters:
        el - Element whose attributes are returned
        Returns:
        the List of Attr
      • getAttribute

        public static java.lang.String getAttribute​(org.w3c.dom.Element el,
                                                    java.lang.String attrName)
        Returns the value of an attribute of an element. Returns null if the attribute is not found (whereas Element.getAttribute returns "" if an attrib is not found). This method should be used for elements that support extension attributes because it does not track unexpected attributes.
        Parameters:
        el - Element whose attrib is looked for
        attrName - name of attribute to look for
        Returns:
        the attribute value
      • getAttribute

        public static java.lang.String getAttribute​(org.w3c.dom.Element el,
                                                    java.lang.String attrName,
                                                    java.util.List remainingAttrs)
        Returns the value of an attribute of an element. Returns null if the attribute is not found (whereas Element.getAttribute returns "" if an attrib is not found). This method should be used for elements that do not support extension attributes because it tracks the element's remaining attributes so that eventually any unexpected attributes can be identified.
        Parameters:
        el - Element whose attrib is looked for
        attrName - name of attribute to look for
        remainingAttrs - List of remaining attributes
        Returns:
        the attribute value
      • getAttributeNS

        public static java.lang.String getAttributeNS​(org.w3c.dom.Element el,
                                                      java.lang.String namespaceURI,
                                                      java.lang.String localPart)
        Returns the value of an attribute of an element. Returns null if the attribute is not found (whereas Element.getAttributeNS returns "" if an attrib is not found).
        Parameters:
        el - Element whose attrib is looked for
        namespaceURI - namespace URI of attribute to look for
        localPart - local part of attribute to look for
        Returns:
        the attribute value
      • getChildCharacterData

        public static java.lang.String getChildCharacterData​(org.w3c.dom.Element parentEl)
        Concat all the text and cdata node children of this elem and return the resulting text.
        Parameters:
        parentEl - the element whose cdata/text node values are to be combined.
        Returns:
        the concatanated string.
      • getFirstChildElement

        public static org.w3c.dom.Element getFirstChildElement​(org.w3c.dom.Element elem)
        Return the first child element of the given element. Null if no children are found.
        Parameters:
        elem - Element whose child is to be returned
        Returns:
        the first child element.
      • getNextSiblingElement

        public static org.w3c.dom.Element getNextSiblingElement​(org.w3c.dom.Element elem)
        Return the next sibling element of the given element. Null if no more sibling elements are found.
        Parameters:
        elem - Element whose sibling element is to be returned
        Returns:
        the next sibling element.
      • findChildElementWithAttribute

        public static org.w3c.dom.Element findChildElementWithAttribute​(org.w3c.dom.Element elem,
                                                                        java.lang.String attrName,
                                                                        java.lang.String attrValue)
        Return the first child element of the given element which has the given attribute with the given value.
        Parameters:
        elem - the element whose children are to be searched
        attrName - the attrib that must be present
        attrValue - the desired value of the attribute
        Returns:
        the first matching child element.
      • countKids

        public static int countKids​(org.w3c.dom.Element elem,
                                    short nodeType)
        Count number of children of a certain type of the given element.
        Parameters:
        elem - the element whose kids are to be counted
        Returns:
        the number of matching kids.
      • getNamespaceURIFromPrefix

        public static java.lang.String getNamespaceURIFromPrefix​(org.w3c.dom.Node context,
                                                                 java.lang.String prefix)
        Given a prefix and a node, return the namespace URI that the prefix has been associated with. This method is useful in resolving the namespace URI of attribute values which are being interpreted as QNames. If prefix is null, this method will return the default namespace.
        Parameters:
        context - the starting node (looks up recursively from here)
        prefix - the prefix to find an xmlns:prefix=uri for
        Returns:
        the namespace URI or null if not found
      • getQName

        public static javax.xml.namespace.QName getQName​(java.lang.String prefixedValue,
                                                         org.w3c.dom.Element contextEl,
                                                         Definition def)
                                                  throws WSDLException
        Throws:
        WSDLException
      • registerUniquePrefix

        public static void registerUniquePrefix​(java.lang.String prefix,
                                                java.lang.String namespaceURI,
                                                Definition def)
      • getQualifiedAttributeValue

        public static javax.xml.namespace.QName getQualifiedAttributeValue​(org.w3c.dom.Element el,
                                                                           java.lang.String attrName,
                                                                           java.lang.String elDesc,
                                                                           boolean isRequired,
                                                                           Definition def)
                                                                    throws WSDLException
        This method should be used for elements that support extension attributes because it does not track the remaining attributes to test for unexpected attributes.
        Throws:
        WSDLException
      • getQualifiedAttributeValue

        public static javax.xml.namespace.QName getQualifiedAttributeValue​(org.w3c.dom.Element el,
                                                                           java.lang.String attrName,
                                                                           java.lang.String elDesc,
                                                                           boolean isRequired,
                                                                           Definition def,
                                                                           java.util.List remainingAttrs)
                                                                    throws WSDLException
        This method should be used for elements that do not support extension attributes because it tracks the remaining attributes so that eventually any unexpected attributes can be identified.
        Throws:
        WSDLException
      • throwWSDLException

        public static void throwWSDLException​(org.w3c.dom.Element location)
                                       throws WSDLException
        Throws:
        WSDLException
      • printAttribute

        public static void printAttribute​(java.lang.String name,
                                          java.lang.String value,
                                          java.io.PrintWriter pw)
      • printQualifiedAttribute

        public static void printQualifiedAttribute​(javax.xml.namespace.QName name,
                                                   java.lang.String value,
                                                   Definition def,
                                                   java.io.PrintWriter pw)
                                            throws WSDLException
        Prints attributes with qualified names.
        Throws:
        WSDLException
      • printQualifiedAttribute

        public static void printQualifiedAttribute​(javax.xml.namespace.QName name,
                                                   javax.xml.namespace.QName value,
                                                   Definition def,
                                                   java.io.PrintWriter pw)
                                            throws WSDLException
        Throws:
        WSDLException
      • printQualifiedAttribute

        public static void printQualifiedAttribute​(java.lang.String name,
                                                   javax.xml.namespace.QName value,
                                                   Definition def,
                                                   java.io.PrintWriter pw)
                                            throws WSDLException
        Throws:
        WSDLException
      • getQualifiedValue

        public static java.lang.String getQualifiedValue​(java.lang.String namespaceURI,
                                                         java.lang.String localPart,
                                                         Definition def)
                                                  throws WSDLException
        Throws:
        WSDLException
      • cleanString

        public static java.lang.String cleanString​(java.lang.String orig)