Package com.evolveum.midpoint.util
Class DOMUtil
java.lang.Object
com.evolveum.midpoint.util.DOMUtil
- Since:
- 0.1
- Author:
- Igor Farinic, Radovan Semancik
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final Trace
static final String
static final String
static final String
static final String
static final QName
static final String
static final String
static final String
static final String
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
static final QName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallNamespaceDeclarations
(Node node) static void
checkValidXmlChars
(String stringValue) static boolean
compareDocument
(Document a, Document b, boolean considerNamespacePrefixes, boolean considerWhitespaces) static boolean
compareElement
(Element a, Element b, boolean considerNamespacePrefixes) static boolean
compareElement
(Element a, Element b, boolean considerNamespacePrefixes, boolean considerWhitespaces) static boolean
compareElementList
(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes) static boolean
compareElementList
(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes, boolean considerWhitespaces) static boolean
static boolean
compareTextNodeValues
(String a, String b, boolean considerWhitespaces) static boolean
containsHTML
(String code) Method to check if the code in the script element contains HTML.static void
copyContent
(Element source, Element destination) static void
createComment
(Element element, String text) static DocumentBuilder
static Element
createElement
(QName qname) static Element
createElement
(Document document, QName qname) static Element
createElement
(Document document, QName qname, Element parentElement, Element definitionElement) static Element
createSubElement
(Element parent, QName subElementQName) static String
static Element
findElementRecursive
(Element element, QName elementQName) static void
fixNamespaceDeclarations
(Element element) Take all the namespace declaration of parent elements and put them to this element.Returns all namespace declarations visible from the given node.static String
getAttribute
(Element element, String attrName) static String
getAttribute
(Element element, QName attrQname) static Element
getChildElement
(Element element, int index) static Element
getChildElement
(Element element, String localPart) static Element
getChildElement
(Element element, QName qname) getChildElements
(Element element, QName elementName) static String
getContentOfDocumentation
(@NotNull String documentation) Parse documentation that contains xml tag 'documentation' to text of context onlystatic Document
static Document
getDocument
(QName rootElementName) static Document
getDocument
(Node node) getElement
(Element root, QName... path) getElementsWithoutNamespacePrefix
(Element element) static Element
getFirstChildElement
(Node parent) static Integer
getIntegerValue
(Element element) static Element
getLastChildElement
(Node parent) static Element
getMatchingChildElement
(Element element, QName qname) getMatchingChildElements
(Element element, QName qname) static Element
getNamedElement
(List<Element> elements, QName qname) static String
getNamespaceDeclarationForPrefix
(Element targetElement, String prefix) static String
static String
getNamespaceDeclarations
(Element element) Returns map of all namespace declarations from specified element (prefix -> namespace).getNamespaceDeclarationsNonNull
(Element element) static Node
getNextSiblingElement
(Node node) static Element
getOrCreateAsFirstElement
(Element parentElement, QName elementQName) static Element
getOrCreateSubElement
(Document doc, Element parentElement, QName qName) static @NotNull QName
static QName
static QName
getQNameAttribute
(Element element, String attributeName) static QName
getQNameAttribute
(Element element, QName attributeName) static QName
getQNameValue
(String textContent, Map<String, String> namespaces) static QName
getQNameValue
(Attr attr) static QName
getQNameValue
(Element element) static QName
getQNameWithoutPrefix
(Node node) static String
getSchemaTargetNamespace
(Element xsdSchema) Should be synchronized.static boolean
hasApplicationAttributes
(Element element) static boolean
hasChildElements
(Node node) static boolean
hasNamespaceDeclarationForPrefix
(Element targetElement, String prefix) static boolean
hasNoPrefix
(Element top) static boolean
hasXsiType
(Element element) static boolean
isElementName
(Element element, QName name) static boolean
static boolean
static boolean
static boolean
isMarkedAsIncomplete
(Element element) static boolean
isNamespaceDefinition
(Attr attr) static boolean
static boolean
isPrefixUsed
(Element targetElement, String prefix) static Collection<Attr>
listApplicationAttributes
(Element element) listChildElements
(Node node) Returned list contains non-null objects.static String
lookupOrCreateNamespaceDeclaration
(Element element, String namespaceUri, String preferredPrefix, Element definitionElement, boolean allowUseOfDefaultNamespace) static void
static Document
parse
(InputStream inputStream) static Document
parseDocument
(String doc) static Document
static Document
static void
preserveFormattingIfPresent
(Element xsdSchema) static StringBuffer
static StringBuffer
static void
removeXsiType
(Element element) static QName
resolveQName
(com.evolveum.midpoint.util.DOMUtil.NamespaceResolver namespaceResolver, String qnameStringRepresentation) static QName
resolveQName
(Element element) static QName
resolveQName
(Node domNode, String qnameStringRepresentation) Resolves a QName.static QName
resolveXsiType
(Element element) static void
serializeDOMToFile
(Node node, File file) static String
serializeDOMToString
(Node node) static String
serializeElementContent
(Element element) Serializes the content of the element to a string (without the enclosing element tags).static void
setAttributeValue
(Element element, String name, String value) static void
setElementTextContent
(Element element, String value) static void
setElementTextContentWithCDATAPrefix
(Element element, String value) Method to create a child with a CDATA section for a DOM element.static void
setNamespaceDeclaration
(Element element, String prefix, String namespaceUri) static void
setNamespaceDeclarations
(Element element, Map<String, String> rootNamespaceDeclarations) static void
setQNameAttribute
(Element element, String attributeName, QName attributeValue) static void
setQNameAttribute
(Element element, String attributeName, QName attributeValue, Element definitionElement) static void
setQNameAttribute
(Element element, QName attributeName, QName attributeValue) static void
setQNameAttribute
(Element element, QName attributeName, QName attributeValue, Element definitionElement) static void
setQNameValue
(Element element, QName elementValue) Sets QName value for a given element.static TransformerFactory
static void
setXsiType
(Element element, QName type) static String
static void
validateNonEmptyQName
(QName qname, String shortDescription, boolean allowEmptyNamespace)
-
Field Details
-
LOGGER
-
W3C_XML_SCHEMA_XMLNS_URI
- See Also:
-
W3C_XML_SCHEMA_XMLNS_PREFIX
- See Also:
-
W3C_XML_XML_URI
- See Also:
-
W3C_XML_XML_PREFIX
- See Also:
-
NS_W3C_XSI_PREFIX
- See Also:
-
XSI_TYPE
-
XSI_NIL
-
HACKED_XSI_TYPE
- See Also:
-
IS_LIST_ATTRIBUTE_NAME
- See Also:
-
IS_INCOMPLETE_ATTRIBUTE_NAME
- See Also:
-
NS_W3C_XML_SCHEMA_PREFIX
- See Also:
-
XSD_SCHEMA_ELEMENT
-
XSD_ANNOTATION_ELEMENT
-
XSD_APPINFO_ELEMENT
-
XSD_DOCUMENTATION_ELEMENT
-
XSD_IMPORT_ELEMENT
-
XSD_INCLUDE_ELEMENT
-
XSD_ATTR_TARGET_NAMESPACE
-
XSD_ATTR_NAMESPACE
-
XSD_ATTR_SCHEMA_LOCATION
-
XSD_DECIMAL
-
XSD_STRING
-
XSD_INTEGER
-
XSD_INT
-
XSD_LONG
-
XSD_SHORT
-
XSD_FLOAT
-
XSD_DOUBLE
-
XSD_BOOLEAN
-
XSD_BASE64BINARY
-
XSD_DATETIME
-
XSD_DURATION
-
XSD_BYTE
-
XSD_QNAME
-
XSD_ANYURI
-
XSD_ANY
-
XSD_ANYTYPE
-
NS_WSDL
- See Also:
-
NS_WSDL_SCHEMA_PREFIX
- See Also:
-
WSDL_IMPORT_ELEMENT
-
WSDL_TYPES_ELEMENT
-
WSDL_ATTR_NAMESPACE
-
WSDL_ATTR_LOCATION
-
SCRIPT_CODE_ELEMENT_NAME
-
-
Constructor Details
-
DOMUtil
public DOMUtil()
-
-
Method Details
-
setupTransformerFactory
-
serializeDOMToString
-
serializeDOMToFile
public static void serializeDOMToFile(Node node, File file) throws TransformerFactoryConfigurationError, TransformerException -
getDocument
-
getDocument
-
getDocument
-
createDocumentBuilder
-
parseDocument
-
parseFile
-
parseFile
-
parse
- Throws:
IOException
-
showDom
-
printDom
-
printDom
-
getNextSiblingElement
-
getFirstChildElement
-
getLastChildElement
-
getChildElements
-
listChildElements
Returned list contains non-null objects. -
hasChildElements
-
resolveQName
-
resolveQName
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
-
getSchemaTargetNamespace
Should be synchronized. This is the responsibility of the caller. See MID-8860.- Throws:
SchemaException
-
preserveFormattingIfPresent
-
resolveQName
-
resolveXsiType
-
hasXsiType
-
removeXsiType
-
setXsiType
-
setQNameAttribute
-
setQNameAttribute
-
setQNameAttribute
-
setQNameAttribute
-
setQNameValue
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 valueelementValue
- 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 evaluatednamespaceUri
- Namespace URI to be assigned to a prefixpreferredPrefix
- Preferred prefixdefinitionElement
- 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
-
setNamespaceDeclaration
-
getNamespaceDeclarations
Returns map of all namespace declarations from specified element (prefix -> namespace). -
getNamespaceDeclarationsNonNull
-
setNamespaceDeclarations
-
getAllVisibleNamespaceDeclarations
Returns all namespace declarations visible from the given node. Uses recursion for simplicity. -
getAllNonDefaultNamespaceDeclarations
-
allNamespaceDeclarations
-
fixNamespaceDeclarations
Take all the namespace declaration of parent elements and put them to this element. -
isPrefixUsed
-
hasNamespaceDeclarationForPrefix
-
getNamespaceDeclarationForPrefix
-
getNamespaceDeclarationPrefix
-
getNamespaceDeclarationNamespace
-
listApplicationAttributes
-
hasApplicationAttributes
-
getChildElement
-
getElement
-
getMatchingChildElement
-
getMatchingChildElements
-
getNamedElement
-
getChildElement
-
getChildElement
-
getOrCreateAsFirstElement
-
getQName
-
getQName
-
getQNameValue
-
getQNameValue
-
getQNameAttribute
-
getQNameAttribute
-
getQNameValue
-
getIntegerValue
-
copyContent
-
createElement
-
createElement
-
createElement
-
createSubElement
-
compareElement
-
compareElement
-
compareDocument
-
compareElementList
-
compareElementList
-
compareTextNodeValues
-
compareTextNodeValues
-
normalize
-
isJunk
-
validateNonEmptyQName
-
findElementRecursive
-
getQNameWithoutPrefix
-
isElementName
-
isNil
-
serializeElementContent
Serializes the content of the element to a string (without the enclosing element tags). -
isEmpty
-
isEmpty
-
setAttributeValue
-
setElementTextContent
-
setElementTextContentWithCDATAPrefix
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
Method to check if the code in the script element contains HTML. -
checkValidXmlChars
-
escapeInvalidXmlCharsIfPresent
-
createComment
-
getAttribute
-
getAttribute
-
hasNoPrefix
-
getElementsWithoutNamespacePrefix
-
getContentOfDocumentation
Parse documentation that contains xml tag 'documentation' to text of context only -
getOrCreateSubElement
-