Class DOMUtil


  • public class DOMUtil
    extends Object
    Since:
    0.1
    Author:
    Igor Farinic, Radovan Semancik
    • Field Detail

      • LOGGER

        public static final Trace LOGGER
      • XSI_TYPE

        public static final QName XSI_TYPE
      • XSI_NIL

        public static final QName XSI_NIL
      • XSD_SCHEMA_ELEMENT

        public static final QName XSD_SCHEMA_ELEMENT
      • XSD_ANNOTATION_ELEMENT

        public static final QName XSD_ANNOTATION_ELEMENT
      • XSD_APPINFO_ELEMENT

        public static final QName XSD_APPINFO_ELEMENT
      • XSD_DOCUMENTATION_ELEMENT

        public static final QName XSD_DOCUMENTATION_ELEMENT
      • XSD_IMPORT_ELEMENT

        public static final QName XSD_IMPORT_ELEMENT
      • XSD_INCLUDE_ELEMENT

        public static final QName XSD_INCLUDE_ELEMENT
      • XSD_ATTR_TARGET_NAMESPACE

        public static final QName XSD_ATTR_TARGET_NAMESPACE
      • XSD_ATTR_NAMESPACE

        public static final QName XSD_ATTR_NAMESPACE
      • XSD_ATTR_SCHEMA_LOCATION

        public static final QName XSD_ATTR_SCHEMA_LOCATION
      • XSD_DECIMAL

        public static final QName XSD_DECIMAL
      • XSD_STRING

        public static final QName XSD_STRING
      • XSD_INTEGER

        public static final QName XSD_INTEGER
      • XSD_INT

        public static final QName XSD_INT
      • XSD_LONG

        public static final QName XSD_LONG
      • XSD_SHORT

        public static final QName XSD_SHORT
      • XSD_FLOAT

        public static final QName XSD_FLOAT
      • XSD_DOUBLE

        public static final QName XSD_DOUBLE
      • XSD_BOOLEAN

        public static final QName XSD_BOOLEAN
      • XSD_BASE64BINARY

        public static final QName XSD_BASE64BINARY
      • XSD_DATETIME

        public static final QName XSD_DATETIME
      • XSD_DURATION

        public static final QName XSD_DURATION
      • XSD_BYTE

        public static final QName XSD_BYTE
      • XSD_QNAME

        public static final QName XSD_QNAME
      • XSD_ANYURI

        public static final QName XSD_ANYURI
      • XSD_ANY

        public static final QName XSD_ANY
      • XSD_ANYTYPE

        public static final QName XSD_ANYTYPE
      • WSDL_IMPORT_ELEMENT

        public static final QName WSDL_IMPORT_ELEMENT
      • WSDL_TYPES_ELEMENT

        public static final QName WSDL_TYPES_ELEMENT
      • WSDL_ATTR_NAMESPACE

        public static final QName WSDL_ATTR_NAMESPACE
      • WSDL_ATTR_LOCATION

        public static final QName WSDL_ATTR_LOCATION
    • Constructor Detail

      • DOMUtil

        public DOMUtil()
    • Method Detail

      • serializeDOMToString

        public static String serializeDOMToString​(Node node)
      • getDocument

        public static Document getDocument​(Node node)
      • getDocument

        public static Document getDocument()
      • getDocument

        public static Document getDocument​(QName rootElementName)
      • createDocumentBuilder

        public static DocumentBuilder createDocumentBuilder()
      • parseDocument

        public static Document parseDocument​(String doc)
      • parseFile

        public static Document parseFile​(File file)
      • printDom

        public static StringBuffer printDom​(Node node,
                                            boolean indent,
                                            boolean omitXmlDeclaration)
      • getNextSiblingElement

        public static Node getNextSiblingElement​(Node node)
      • getFirstChildElement

        public static Element getFirstChildElement​(Node parent)
      • getLastChildElement

        public static Element getLastChildElement​(Node parent)
      • listChildElements

        @NotNull
        public static @NotNull List<Element> listChildElements​(Node node)
        Returned list contains non-null objects.
      • hasChildElements

        public static boolean hasChildElements​(Node node)
      • resolveQName

        public static QName resolveQName​(Element element)
      • resolveQName

        public static QName resolveQName​(Node domNode,
                                         String qnameStringRepresentation)
        Resolves a QName. Contrary to traditional XML handling, a QName without prefix is parsed to a QName without namespace, even if default namespace declaration is present.
        Parameters:
        domNode - Provides a context in which we will resolve namespace prefixes (may be null)
        qnameStringRepresentation - String representation of a QName (e.g. c:RoleType) (may be null)
        Returns:
        parsed QName (or null if string representation is blank)
      • isMarkedAsIncomplete

        public static boolean isMarkedAsIncomplete​(Element element)
      • resolveQName

        public static QName resolveQName​(com.evolveum.midpoint.util.DOMUtil.NamespaceResolver namespaceResolver,
                                         String qnameStringRepresentation)
      • resolveXsiType

        public static QName resolveXsiType​(Element element)
      • hasXsiType

        public static boolean hasXsiType​(Element element)
      • removeXsiType

        public static void removeXsiType​(Element element)
      • setXsiType

        public static void setXsiType​(Element element,
                                      QName type)
      • setQNameAttribute

        public static void setQNameAttribute​(Element element,
                                             QName attributeName,
                                             QName attributeValue)
      • setQNameAttribute

        public static void setQNameAttribute​(Element element,
                                             String attributeName,
                                             QName attributeValue)
      • setQNameAttribute

        public static void setQNameAttribute​(Element element,
                                             QName attributeName,
                                             QName attributeValue,
                                             Element definitionElement)
      • setQNameAttribute

        public static void setQNameAttribute​(Element element,
                                             String attributeName,
                                             QName attributeValue,
                                             Element definitionElement)
      • setQNameValue

        public static void setQNameValue​(Element element,
                                         QName elementValue)
        Sets QName value for a given element.

        Contrary to standard XML semantics, namespace-less QNames are specified as simple names without prefix (regardless of default prefix used in the XML document).

        Parameters:
        element - Element whose text content should be set to represent QName value
        elementValue - QName value to be stored into the element
      • lookupOrCreateNamespaceDeclaration

        public static String lookupOrCreateNamespaceDeclaration​(Element element,
                                                                String namespaceUri,
                                                                String preferredPrefix,
                                                                Element definitionElement,
                                                                boolean allowUseOfDefaultNamespace)
        Parameters:
        element - Element, on which the namespace declaration is evaluated
        namespaceUri - Namespace URI to be assigned to a prefix
        preferredPrefix - Preferred prefix
        definitionElement - Element, on which namespace declaration will be created (there should not be any redefinitions between definitionElement and element in order for this to work...)
        allowUseOfDefaultNamespace - If we are allowed to use default namespace (i.e. return empty prefix). This is important for QNames, see setQNameValue
        Returns:
        prefix that is really used

        Returned prefix is never null nor "" if allowUseOfDefaultNamespace is false.

      • isNamespaceDefinition

        public static boolean isNamespaceDefinition​(Attr attr)
      • setNamespaceDeclaration

        public static void setNamespaceDeclaration​(Element element,
                                                   String prefix,
                                                   String namespaceUri)
      • getNamespaceDeclarations

        public static Map<String,​String> getNamespaceDeclarations​(Element element)
        Returns map of all namespace declarations from specified element (prefix -> namespace).
      • getNamespaceDeclarationsNonNull

        public static Map<String,​String> getNamespaceDeclarationsNonNull​(Element element)
      • setNamespaceDeclarations

        public static void setNamespaceDeclarations​(Element element,
                                                    Map<String,​String> rootNamespaceDeclarations)
      • getAllVisibleNamespaceDeclarations

        public static Map<String,​String> getAllVisibleNamespaceDeclarations​(Node node)
        Returns all namespace declarations visible from the given node. Uses recursion for simplicity.
      • getAllNonDefaultNamespaceDeclarations

        public static Map<String,​String> getAllNonDefaultNamespaceDeclarations​(Node node)
      • allNamespaceDeclarations

        public static Map<String,​String> allNamespaceDeclarations​(Node node)
      • fixNamespaceDeclarations

        public static void fixNamespaceDeclarations​(Element element)
        Take all the namespace declaration of parent elements and put them to this element.
      • isPrefixUsed

        public static boolean isPrefixUsed​(Element targetElement,
                                           String prefix)
      • hasNamespaceDeclarationForPrefix

        public static boolean hasNamespaceDeclarationForPrefix​(Element targetElement,
                                                               String prefix)
      • getNamespaceDeclarationForPrefix

        public static String getNamespaceDeclarationForPrefix​(Element targetElement,
                                                              String prefix)
      • getNamespaceDeclarationPrefix

        public static String getNamespaceDeclarationPrefix​(Attr attr)
      • getNamespaceDeclarationNamespace

        public static String getNamespaceDeclarationNamespace​(Attr attr)
      • listApplicationAttributes

        public static Collection<Attr> listApplicationAttributes​(Element element)
      • hasApplicationAttributes

        public static boolean hasApplicationAttributes​(Element element)
      • getMatchingChildElement

        public static Element getMatchingChildElement​(Element element,
                                                      QName qname)
      • getMatchingChildElements

        public static List<Element> getMatchingChildElements​(Element element,
                                                             QName qname)
      • getChildElement

        public static Element getChildElement​(Element element,
                                              int index)
      • getOrCreateAsFirstElement

        public static Element getOrCreateAsFirstElement​(Element parentElement,
                                                        QName elementQName)
      • getQName

        @NotNull
        public static @NotNull QName getQName​(Element element)
      • getQName

        public static QName getQName​(Node node)
      • getQNameValue

        public static QName getQNameValue​(Element element)
      • getQNameAttribute

        public static QName getQNameAttribute​(Element element,
                                              String attributeName)
      • getQNameAttribute

        public static QName getQNameAttribute​(Element element,
                                              QName attributeName)
      • getQNameValue

        public static QName getQNameValue​(Attr attr)
      • getIntegerValue

        public static Integer getIntegerValue​(Element element)
      • copyContent

        public static void copyContent​(Element source,
                                       Element destination)
      • createElement

        public static Element createElement​(QName qname)
      • createSubElement

        public static Element createSubElement​(Element parent,
                                               QName subElementQName)
      • compareElement

        public static boolean compareElement​(Element a,
                                             Element b,
                                             boolean considerNamespacePrefixes)
      • compareElement

        public static boolean compareElement​(Element a,
                                             Element b,
                                             boolean considerNamespacePrefixes,
                                             boolean considerWhitespaces)
      • compareDocument

        public static boolean compareDocument​(Document a,
                                              Document b,
                                              boolean considerNamespacePrefixes,
                                              boolean considerWhitespaces)
      • compareElementList

        public static boolean compareElementList​(List<Element> aList,
                                                 List<Element> bList,
                                                 boolean considerNamespacePrefixes)
      • compareElementList

        public static boolean compareElementList​(List<Element> aList,
                                                 List<Element> bList,
                                                 boolean considerNamespacePrefixes,
                                                 boolean considerWhitespaces)
      • compareTextNodeValues

        public static boolean compareTextNodeValues​(String a,
                                                    String b)
      • compareTextNodeValues

        public static boolean compareTextNodeValues​(String a,
                                                    String b,
                                                    boolean considerWhitespaces)
      • normalize

        public static void normalize​(Node node,
                                     boolean keepWhitespaces)
      • isJunk

        public static boolean isJunk​(Node node)
      • validateNonEmptyQName

        public static void validateNonEmptyQName​(QName qname,
                                                 String shortDescription,
                                                 boolean allowEmptyNamespace)
      • findElementRecursive

        public static Element findElementRecursive​(Element element,
                                                   QName elementQName)
      • getQNameWithoutPrefix

        public static QName getQNameWithoutPrefix​(Node node)
      • isElementName

        public static boolean isElementName​(Element element,
                                            QName name)
      • isNil

        public static boolean isNil​(Element element)
      • serializeElementContent

        public static String serializeElementContent​(Element element)
        Serializes the content of the element to a string (without the enclosing element tags).
      • isEmpty

        public static boolean isEmpty​(Element element)
      • isEmpty

        public static boolean isEmpty​(Attr attr)
      • setAttributeValue

        public static void setAttributeValue​(Element element,
                                             String name,
                                             String value)
      • setElementTextContent

        public static void setElementTextContent​(Element element,
                                                 String value)
      • checkValidXmlChars

        public static void checkValidXmlChars​(String stringValue)
      • escapeInvalidXmlCharsIfPresent

        public static String escapeInvalidXmlCharsIfPresent​(String value)
      • createComment

        public static void createComment​(Element element,
                                         String text)
      • hasNoPrefix

        public static boolean hasNoPrefix​(Element top)
      • getElementsWithoutNamespacePrefix

        @NotNull
        public static @NotNull List<Element> getElementsWithoutNamespacePrefix​(Element element)