Class DOMUtilities
java.lang.Object
org.apache.batik.xml.XMLCharacters
org.apache.batik.xml.XMLUtilities
org.apache.batik.dom.util.DOMUtilities
- All Implemented Interfaces:
XMLConstants
A collection of utility functions for the DOM.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String[]String constants representing DOM modifier strings for various all key lock combinations.protected static final String[]String constants representing DOM modifier strings for various all shift modifier combinations.Fields inherited from class XMLUtilities
IS_XML_10_NAME, IS_XML_10_QNAMEFields inherited from class XMLCharacters
ALPHABETIC_CHARACTER, NAME_CHARACTER, NAME_FIRST_CHARACTER, NAME11_CHARACTER, NAME11_FIRST_CHARACTER, PUBLIC_ID_CHARACTER, VERSION_CHARACTER, XML_CHARACTERFields inherited from interface XMLConstants
XLINK_HREF_ATTRIBUTE, XLINK_HREF_QNAME, XLINK_NAMESPACE_URI, XLINK_PREFIX, XML_BASE_ATTRIBUTE, XML_BASE_QNAME, XML_CDATA_END, XML_CHAR_AMP, XML_CHAR_APOS, XML_CHAR_GT, XML_CHAR_LT, XML_CHAR_QUOT, XML_CHAR_REF_PREFIX, XML_CHAR_REF_SUFFIX, XML_CLOSE_TAG_END, XML_CLOSE_TAG_START, XML_DEFAULT_VALUE, XML_DOUBLE_DASH, XML_DOUBLE_QUOTE, XML_ENTITY_AMP, XML_ENTITY_APOS, XML_ENTITY_GT, XML_ENTITY_LT, XML_ENTITY_QUOT, XML_EQUAL_QUOT, XML_EQUAL_SIGN, XML_EVENTS_EVENT_ATTRIBUTE, XML_EVENTS_NAMESPACE_URI, XML_ID_ATTRIBUTE, XML_ID_QNAME, XML_LANG_ATTRIBUTE, XML_LANG_QNAME, XML_NAMESPACE_URI, XML_OPEN_TAG_END_CHILDREN, XML_OPEN_TAG_END_NO_CHILDREN, XML_OPEN_TAG_START, XML_PREFIX, XML_PRESERVE_VALUE, XML_PROCESSING_INSTRUCTION_END, XML_SPACE, XML_SPACE_ATTRIBUTE, XML_SPACE_QNAME, XML_TAB, XML_VERSION_10, XML_VERSION_11, XMLNS_NAMESPACE_URI, XMLNS_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringassertValidCharacters(String s, boolean isXML11) static booleanChecks if the node can be appended on the given parent nodestatic booleancanAppendAny(ArrayList children, Node parentNode) Checks whether any of the nodes from the list can be appended to a given parentNode.static booleancanHaveChildren(Node parentNode) Returns whether the given Node can have children.static StringcontentToString(String s, boolean isXML11) Returns the given content value transformed to replace invalid characters with entities.static DocumentdeepCloneDocument(Document doc, DOMImplementation impl) Deep clones a document using the given DOM implementation.static intgetChildIndex(Node child) Finds and returns the index of child node in its parent's children arraystatic intgetChildIndex(Node child, Node parent) Finds and returns the index of child node in the given parent's children arraystatic StringGets the local name from the given qualified name.static StringgetModifiersList(int lockState, int modifiersEx) Gets a DOM 3 modifiers string from the given lock and shift bitmasks.static StringGets the prefix from the given qualified name.static StringSerializes the given DOM node usingwriteNode(Node,Writer)and returns the XML as a String.static booleanisAncestorOf(Node node, Node descendant) Checks whether a node is ancestor of another node.static booleanisAnyNodeAncestorOf(ArrayList ancestorNodes, Node node) Checks if any of from the given list of nodes is an ancestor to another nodestatic booleanisAttributeSpecifiedNS(Element e, String namespaceURI, String localName) Returns whether the given element has a particular attribute and that it exists due to being specified explicitly, rather than being defaulted from a DTD.static booleanisParentOf(Node node, Node parentNode) Tests whether the given node is a child of the given parent node.static booleanTests whether the given string is a valid name.static booleanTests whether the given string is a valid XML 1.1 name.static booleanTests whether the given string is a valid prefix.static voidparseStyleSheetPIData(String data, HashMap<String, String> table) Parses a 'xml-stylesheet' processing instruction data section and puts the pseudo attributes in the given table.static NodeparseXML(String text, Document doc, String uri, Map prefixes, String wrapperElementName, SAXDocumentFactory documentFactory) Parses the given XML string into a DocumentFragment of the given document or a new document if 'doc' is null.static voidwriteDocument(Document doc, Writer w) Serializes the specifiedDocument, writing it to the givenWriter.static voidWrites a node using the given writer.protected static voidMethods inherited from class XMLUtilities
createXMLDeclarationReader, createXMLDocumentReader, encodingToJavaEncoding, getXMLDeclarationEncoding, isXML11Character, isXML11NameCharacter, isXML11NameFirstCharacter, isXMLAlphabeticCharacter, isXMLCharacter, isXMLNameCharacter, isXMLNameFirstCharacter, isXMLPublicIdCharacter, isXMLSpace, isXMLVersionCharacter, testXMLQName
-
Field Details
-
LOCK_STRINGS
String constants representing DOM modifier strings for various all key lock combinations. -
MODIFIER_STRINGS
String constants representing DOM modifier strings for various all shift modifier combinations.
-
-
Constructor Details
-
DOMUtilities
protected DOMUtilities()Does not need to be instantiated.
-
-
Method Details
-
writeDocument
Serializes the specifiedDocument, writing it to the givenWriter.- Throws:
IOException
-
writeNode
protected static void writeNode(Node n, Writer w, org.apache.batik.dom.util.DOMUtilities.NSMap m, boolean isXML11) throws IOException - Throws:
IOException
-
writeNode
Writes a node using the given writer.- Throws:
IOException
-
getXML
Serializes the given DOM node usingwriteNode(Node,Writer)and returns the XML as a String.- Parameters:
n- The Node to serialize.- Returns:
- A String containing the XML serialization of the Node, or an empty String if there was a problem during serialization.
-
assertValidCharacters
- Throws:
IOException
-
contentToString
Returns the given content value transformed to replace invalid characters with entities.- Throws:
IOException
-
getChildIndex
-
getChildIndex
Finds and returns the index of child node in its parent's children array- Parameters:
child- The child node- Returns:
- the index in children array
-
isAnyNodeAncestorOf
Checks if any of from the given list of nodes is an ancestor to another node- Parameters:
ancestorNodes- The potential ancestor nodesnode- The potential descendant node- Returns:
- True if at least one node is ancestor of the given node
-
isAncestorOf
-
isParentOf
-
canAppend
-
canAppendAny
Checks whether any of the nodes from the list can be appended to a given parentNode.- Parameters:
children- The given node listparentNode- The potential parent node- Returns:
- true if at least one node from a list can be appended
-
canHaveChildren
Returns whether the given Node can have children.- Parameters:
parentNode- The Node to test- Returns:
trueif the node can have children,falseotherwise
-
parseXML
public static Node parseXML(String text, Document doc, String uri, Map prefixes, String wrapperElementName, SAXDocumentFactory documentFactory) Parses the given XML string into a DocumentFragment of the given document or a new document if 'doc' is null.- Parameters:
text- The given XML stringdoc- The given documenturi- The document URIprefixes- The prefixes map with (prefix, namespaceURI) pairswrapperElementName- null: Ignore the wrapper element and prefixes map and try to parse the text as a whole document otherwise: Wrap the given text with the wrapper element with prefixes specified from the prefixes mapdocumentFactory- What document factory to use when parsing the text- Returns:
- The document fragment or null on error.
-
deepCloneDocument
Deep clones a document using the given DOM implementation. -
isValidName
Tests whether the given string is a valid name. -
isValidName11
Tests whether the given string is a valid XML 1.1 name. -
isValidPrefix
Tests whether the given string is a valid prefix. This method assume that isValidName(s) is true. -
getPrefix
-
getLocalName
-
parseStyleSheetPIData
-
getModifiersList
Gets a DOM 3 modifiers string from the given lock and shift bitmasks. -
isAttributeSpecifiedNS
-