Class DOMUtil

java.lang.Object
com.evolveum.midpoint.util.DOMUtil

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

    • LOGGER

      public static final Trace LOGGER
    • W3C_XML_SCHEMA_XMLNS_URI

      public static final String W3C_XML_SCHEMA_XMLNS_URI
      See Also:
    • W3C_XML_SCHEMA_XMLNS_PREFIX

      public static final String W3C_XML_SCHEMA_XMLNS_PREFIX
      See Also:
    • W3C_XML_XML_URI

      public static final String W3C_XML_XML_URI
      See Also:
    • W3C_XML_XML_PREFIX

      public static final String W3C_XML_XML_PREFIX
      See Also:
    • NS_W3C_XSI_PREFIX

      public static final String NS_W3C_XSI_PREFIX
      See Also:
    • XSI_TYPE

      public static final QName XSI_TYPE
    • XSI_NIL

      public static final QName XSI_NIL
    • HACKED_XSI_TYPE

      public static final String HACKED_XSI_TYPE
      See Also:
    • IS_LIST_ATTRIBUTE_NAME

      public static final String IS_LIST_ATTRIBUTE_NAME
      See Also:
    • IS_INCOMPLETE_ATTRIBUTE_NAME

      public static final String IS_INCOMPLETE_ATTRIBUTE_NAME
      See Also:
    • NS_W3C_XML_SCHEMA_PREFIX

      public static final String NS_W3C_XML_SCHEMA_PREFIX
      See Also:
    • 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
    • NS_WSDL

      public static final String NS_WSDL
      See Also:
    • NS_WSDL_SCHEMA_PREFIX

      public static final String NS_WSDL_SCHEMA_PREFIX
      See Also:
    • 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
    • SCRIPT_CODE_ELEMENT_NAME

      public static final QName SCRIPT_CODE_ELEMENT_NAME
  • Constructor Details

    • DOMUtil

      public DOMUtil()
  • Method Details

    • setupTransformerFactory

      public static TransformerFactory setupTransformerFactory()
    • serializeDOMToString

      public static String serializeDOMToString(Node node)
    • serializeDOMToFile

      public static void serializeDOMToFile(Node node, File file) throws TransformerFactoryConfigurationError, TransformerException
      Throws:
      TransformerFactoryConfigurationError
      TransformerException
    • 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(String filePath)
    • parseFile

      public static Document parseFile(File file)
    • parse

      public static Document parse(InputStream inputStream) throws IOException
      Throws:
      IOException
    • showDom

      public static String showDom(List<Element> elements)
    • printDom

      public static StringBuffer printDom(Node node)
    • 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)
    • getChildElements

      public static List<Element> getChildElements(Element element, QName elementName)
    • 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)
    • getSchemaTargetNamespace

      public static String getSchemaTargetNamespace(Element xsdSchema) throws SchemaException
      Should be synchronized. This is the responsibility of the caller. See MID-8860.
      Throws:
      SchemaException
    • preserveFormattingIfPresent

      public static void preserveFormattingIfPresent(Element xsdSchema)
    • 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)
    • getChildElement

      public static Element getChildElement(Element element, QName qname)
    • getElement

      public static Optional<Element> getElement(Element root, QName... path)
    • getMatchingChildElement

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

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

      public static Element getNamedElement(List<Element> elements, QName qname)
    • getChildElement

      public static Element getChildElement(Element element, String localPart)
    • 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)
    • getQNameValue

      public static QName getQNameValue(String textContent, Map<String,String> namespaces)
    • 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)
    • createElement

      public static Element createElement(Document document, QName qname)
    • createElement

      public static Element createElement(Document document, QName qname, Element parentElement, Element definitionElement)
    • 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)
    • setElementTextContentWithCDATAPrefix

      public static void setElementTextContentWithCDATAPrefix(Element element, String value)
      Method to create a child with a CDATA section for a DOM element.
      Parameters:
      element - The DOM element for which a child element with a CDATA section will be created.
      value - The value that will be wrapped in the CDATA section.
    • containsHTML

      public static boolean containsHTML(String code)
      Method to check if the code in the script element contains HTML.
    • checkValidXmlChars

      public static void checkValidXmlChars(String stringValue)
    • escapeInvalidXmlCharsIfPresent

      public static String escapeInvalidXmlCharsIfPresent(String value)
    • createComment

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

      public static String getAttribute(Element element, QName attrQname)
    • getAttribute

      public static String getAttribute(Element element, String attrName)
    • hasNoPrefix

      public static boolean hasNoPrefix(Element top)
    • getElementsWithoutNamespacePrefix

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

      public static String getContentOfDocumentation(@NotNull @NotNull String documentation)
      Parse documentation that contains xml tag 'documentation' to text of context only
    • getOrCreateSubElement

      public static Element getOrCreateSubElement(Document doc, Element parentElement, QName qName)