Package com.helger.xml.microdom
Interface IMicroNode
- All Superinterfaces:
com.helger.commons.lang.ICloneable<IMicroNode>,com.helger.commons.hierarchy.IHasChildren<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenRecursive<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>,com.helger.commons.hierarchy.IHasParent<IMicroNode>
- All Known Subinterfaces:
IMicroAttributeContainer<IMPLTYPE>,IMicroCDATA,IMicroComment,IMicroContainer,IMicroDocument,IMicroDocumentType,IMicroElement,IMicroEntityReference,IMicroNodeWithChildren,IMicroProcessingInstruction,IMicroText
- All Known Implementing Classes:
AbstractMicroNode,AbstractMicroNodeWithChildren,MicroCDATA,MicroComment,MicroContainer,MicroDocument,MicroDocumentType,MicroElement,MicroEntityReference,MicroProcessingInstruction,MicroText
public interface IMicroNode
extends com.helger.commons.lang.ICloneable<IMicroNode>, com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>, com.helger.commons.hierarchy.IHasChildrenRecursive<IMicroNode>, com.helger.commons.hierarchy.IHasParent<IMicroNode>
This is the base interface for all kind of nodes in the micro document object
model.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault IMicroCDATAappendCDATA(char[] aChars) Append a CDATA node to this node.default IMicroCDATAappendCDATA(char[] aChars, int nOfs, int nLen) Append a CDATA node to this node.default IMicroCDATAappendCDATA(CharSequence sText) Append a CDATA node to this node.default IMicroCDATAappendCDATAWithConversion(Object aValue) Append a CDATA node to this node.<NODETYPE extends IMicroNode>
NODETYPEappendChild(NODETYPE aChildNode) Append any child to the node.default voidappendChildren(IMicroNode... aChildren) Append multiple children to the node at once.default voidappendChildren(Iterable<? extends IMicroNode> aChildren) Append multiple children to the node at once.default IMicroCommentappendComment(char[] aChars) Append a comment node to this node.default IMicroCommentappendComment(char[] aChars, int nOfs, int nLen) Append a comment node to this node.default IMicroCommentappendComment(CharSequence sText) Append a comment node to this node.default IMicroCommentappendCommentWithConversion(Object aValue) Append a comment node to this node.default IMicroContainerAppend a new container to this nodedefault IMicroElementappendElement(String sTagName) Append an element without namespace to this node.default IMicroElementappendElement(String sNamespaceURI, String sTagName) Append an element with namespace to this node.default IMicroEntityReferenceappendEntityReference(String sName) Append an entity reference to this node.default IMicroTextappendIgnorableWhitespaceText(char[] aChars) Append a text node which is ignorable whitespace content to this node.default IMicroTextappendIgnorableWhitespaceText(char[] aChars, int nOfs, int nLen) Append a text node which is ignorable whitespace content to this node.default IMicroTextAppend a text node which is ignorable whitespace content to this node.default IMicroProcessingInstructionappendProcessingInstruction(String sTarget, String sData) Append a processing instruction to this node.default IMicroTextappendText(char[] aChars) Append a text node to this node.default IMicroTextappendText(char[] aChars, int nOfs, int nLen) Append a text node to this node.default IMicroTextappendText(CharSequence sText) Append a text node to this node.default IMicroTextappendTextWithConversion(Object aValue) Append a text node to this node.default booleancontainsAnyChild(Predicate<? super IMicroNode> aFilter) Check if any direct child matching the provided filter is contained.Detach this node from the parent node so it can be inserted into another node without problems.findParentElement(Predicate<? super IMicroElement> aFilter) com.helger.commons.collection.impl.ICommonsList<IMicroNode>Get a list of all direct child nodes.default com.helger.commons.collection.impl.ICommonsList<IMicroNode>Recursively get all children.com.helger.commons.collection.impl.ICommonsMap<EMicroEvent,com.helger.commons.callback.CallbackList<IMicroEventTarget>> com.helger.commons.callback.CallbackList<IMicroEventTarget>getAllEventTargets(EMicroEvent eEvent) Get all event targets for a certain event.default Stringdefault IMicroElementgetParentElementWithName(String sTagName) default IMicroElementgetParentElementWithName(String sNamespaceURI, String sTagName) getType()boolean<NODETYPE extends IMicroNode>
NODETYPEinsertAfter(NODETYPE aChildNode, IMicroNode aPredecessor) Insert an existing node after a certain child node of this.<NODETYPE extends IMicroNode>
NODETYPEinsertAtIndex(int nIndex, NODETYPE aChildNode) Insert an existing node as a child at the specified index.<NODETYPE extends IMicroNode>
NODETYPEinsertBefore(NODETYPE aChildNode, IMicroNode aSuccessor) Insert an existing node before a certain child node of this.booleanisCDATA()booleanbooleanbooleanbooleanbooleanbooleanbooleanisEqualContent(IMicroNode aNode) As instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.booleanbooleanisText()com.helger.commons.state.EChangeregisterEventTarget(EMicroEvent eEventType, IMicroEventTarget aTarget) Register a specific MicroDOM event listener.com.helger.commons.state.EChangeRemove all children from this node.com.helger.commons.state.EChangeremoveChild(IMicroNode aChild) Remove the passed child.com.helger.commons.state.EChangeremoveChildAtIndex(int nIndex) Remove the child not at the specified index.default com.helger.commons.state.EChangereplaceChild(IMicroNode aOldChild, IMicroNode aNewChild) Replace the passed old child with the new child.com.helger.commons.state.EChangeunregisterEventTarget(EMicroEvent eEventType, IMicroEventTarget aTarget) Unregister a specific MicroDOM event listener.Methods inherited from interface com.helger.commons.lang.ICloneable
getCloneMethods inherited from interface com.helger.commons.hierarchy.IHasChildren
forAllChildren, forAllChildren, forAllChildrenBreakable, forAllChildrenMapped, getChildCount, getChildren, hasChildren, hasNoChildrenMethods inherited from interface com.helger.commons.hierarchy.IHasChildrenRecursive
forAllChildrenRecursive, forAllChildrenRecursiveMethods inherited from interface com.helger.commons.hierarchy.IHasChildrenSorted
findFirstChild, findFirstChildMapped, getChildAtIndex
-
Method Details
-
getNodeName
- Returns:
- Just an abstract name that depends on the implementing class. For
IMicroElementnodes this is the same as the tag name.
-
getNodeValue
- Returns:
- The value of this node. This depends on the concrete implementation
class. It is currently implemented for
IMicroText,IMicroCommentandIMicroEntityReference.
-
getAllChildren
Get a list of all direct child nodes.- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Returns:
- May be
nullif the node has no children.
-
containsAnyChild
Check if any direct child matching the provided filter is contained.- Parameters:
aFilter- The filter that is applied to all child nodes. May not benull.- Returns:
trueif any child matching the provided filter is contained,falseotherwise.
-
getFirstChild
- Specified by:
getFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Returns:
- The first child node of this node, or
nullif this node has no children.
-
getLastChild
- Specified by:
getLastChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Returns:
- The last child node of this node, or
nullif this node has no children.
-
getAllChildrenRecursive
@Nullable default com.helger.commons.collection.impl.ICommonsList<IMicroNode> getAllChildrenRecursive()Recursively get all children. Micro container are contained in this list (incl. their children of course)- Returns:
- A list containing all recursively contained child elements. May be
nullif this node has no children.
-
getPreviousSibling
- Returns:
- The previous node on the same level as this node, or
nullif this node has no preceding siblings.
-
getNextSibling
- Returns:
- The next node on the same level as this node, or
nullif this node has no succeeding siblings.
-
hasParent
boolean hasParent()- Specified by:
hasParentin interfacecom.helger.commons.hierarchy.IHasParent<IMicroNode>- Returns:
trueif this node has a parent node assigned,falseotherwise.
-
getParent
- Specified by:
getParentin interfacecom.helger.commons.hierarchy.IHasParent<IMicroNode>- Returns:
- May be
null.
-
detachFromParent
Detach this node from the parent node so it can be inserted into another node without problems. Otherwise you would get anIllegalStateExceptionif adding this node again to another parent since each node can only have one parent.- Returns:
- this
-
findParentElement
-
getParentElementWithName
-
getParentElementWithName
-
appendChild
Append any child to the node.- Type Parameters:
NODETYPE- Parameter type == return type- Parameters:
aChildNode- The child node to append. May benull.- Returns:
- The appended node, or
nullif the parameter wasnull. - Throws:
MicroException- if this node cannot have children
-
appendChildren
Append multiple children to the node at once.- Parameters:
aChildren- The child nodes to be appended. May benulland may containnullvalues.- Throws:
MicroException- if this node cannot have children- Since:
- 9.0.3
-
appendChildren
Append multiple children to the node at once.- Parameters:
aChildren- The child nodes to be appended. May benulland may containnullvalues.- Throws:
MicroException- if this node cannot have children- Since:
- 9.0.3
-
insertBefore
@Nullable <NODETYPE extends IMicroNode> NODETYPE insertBefore(@Nullable NODETYPE aChildNode, @Nonnull IMicroNode aSuccessor) Insert an existing node before a certain child node of this.- Type Parameters:
NODETYPE- Parameter type == return type- Parameters:
aChildNode- The new child node to be inserted.aSuccessor- The node before which the new node will be inserted.- Returns:
- The newly inserted node
- Throws:
MicroException- if this node cannot have children
-
insertAfter
@Nullable <NODETYPE extends IMicroNode> NODETYPE insertAfter(@Nullable NODETYPE aChildNode, @Nonnull IMicroNode aPredecessor) Insert an existing node after a certain child node of this.- Type Parameters:
NODETYPE- Parameter type == return type- Parameters:
aChildNode- The new child node to be inserted.aPredecessor- The node after which the new node will be inserted.- Returns:
- The newly inserted node
- Throws:
MicroException- if this node cannot have children
-
insertAtIndex
@Nullable <NODETYPE extends IMicroNode> NODETYPE insertAtIndex(@Nonnegative int nIndex, @Nullable NODETYPE aChildNode) Insert an existing node as a child at the specified index.- Type Parameters:
NODETYPE- Parameter type == return type- Parameters:
nIndex- The index to insert. Must be ≥ 0.aChildNode- The new child node to be inserted.- Returns:
- The newly inserted node
- Throws:
MicroException- if this node cannot have children
-
appendText
Append a text node to this node.- Parameters:
sText- text to be added- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendText
Append a text node to this node.- Parameters:
aChars- Characters to append. May not benull- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendText
@Nonnull default IMicroText appendText(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen) Append a text node to this node.- Parameters:
aChars- Characters to append. May not benullnOfs- Offset into the array where to start copying data. May not be < 0.nLen- Number of bytes to take from the array. May not be < 0.- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendTextWithConversion
Append a text node to this node. If the type of the value is notString, theTypeConverteris invoked to convert it to aStringobject.- Parameters:
aValue- text to be added- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendIgnorableWhitespaceText
Append a text node which is ignorable whitespace content to this node.- Parameters:
sText- The whitespace content to be added.- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendIgnorableWhitespaceText
Append a text node which is ignorable whitespace content to this node.- Parameters:
aChars- Characters to append. May not benull- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendIgnorableWhitespaceText
@Nonnull default IMicroText appendIgnorableWhitespaceText(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen) Append a text node which is ignorable whitespace content to this node.- Parameters:
aChars- Characters to append. May not benullnOfs- Offset into the array where to start copying data. May not be < 0.nLen- Number of bytes to take from the array. May not be < 0.- Returns:
- The created text node.
- Throws:
MicroException- if this node cannot have children
-
appendCDATA
Append a CDATA node to this node.- Parameters:
sText- CDATA text- Returns:
- The created CDATA node.
- Throws:
MicroException- if this node cannot have children
-
appendCDATA
Append a CDATA node to this node.- Parameters:
aChars- Characters to append. May not benull- Returns:
- The created CDATA node.
- Throws:
MicroException- if this node cannot have children
-
appendCDATA
@Nonnull default IMicroCDATA appendCDATA(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen) Append a CDATA node to this node.- Parameters:
aChars- Characters to append. May not benullnOfs- Offset into the array where to start copying data. May not be < 0.nLen- Number of bytes to take from the array. May not be < 0.- Returns:
- The created CDATA node.
- Throws:
MicroException- if this node cannot have children
-
appendCDATAWithConversion
Append a CDATA node to this node. If the type of the value is notString, theTypeConverteris invoked to convert it to aStringobject.- Parameters:
aValue- CDATA to be added- Returns:
- The created CDATA node.
- Throws:
MicroException- if this node cannot have children
-
appendComment
Append a comment node to this node.- Parameters:
sText- comment text- Returns:
- The created comment.
- Throws:
MicroException- if this node cannot have children
-
appendComment
Append a comment node to this node.- Parameters:
aChars- Characters to append. May not benull- Returns:
- The created comment.
- Throws:
MicroException- if this node cannot have children
-
appendComment
@Nonnull default IMicroComment appendComment(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen) Append a comment node to this node.- Parameters:
aChars- Characters to append. May not benullnOfs- Offset into the array where to start copying data. May not be < 0.nLen- Number of bytes to take from the array. May not be < 0.- Returns:
- The created comment.
- Throws:
MicroException- if this node cannot have children
-
appendCommentWithConversion
Append a comment node to this node. If the type of the value is notString, theTypeConverteris invoked to convert it to aStringobject.- Parameters:
aValue- Comment to be added- Returns:
- The created comment node.
- Throws:
MicroException- if this node cannot have children
-
appendEntityReference
Append an entity reference to this node.- Parameters:
sName- The name of the entity reference.- Returns:
- The created entity reference.
- Throws:
MicroException- if this node cannot have children
-
appendElement
Append an element without namespace to this node.- Parameters:
sTagName- Element name to be created. May neither benullnor empty.- Returns:
- The created element
- Throws:
MicroException- if this node cannot have children
-
appendElement
@Nonnull default IMicroElement appendElement(@Nullable String sNamespaceURI, @Nonnull @Nonempty String sTagName) Append an element with namespace to this node.- Parameters:
sNamespaceURI- Namespace URI to use. May benull.sTagName- Element name to be created. May neither benullnor empty.- Returns:
- The created element
- Throws:
MicroException- if this node cannot have children
-
appendProcessingInstruction
@Nonnull default IMicroProcessingInstruction appendProcessingInstruction(@Nonnull @Nonempty String sTarget, @Nullable String sData) Append a processing instruction to this node.- Parameters:
sTarget- The PI targetsData- The PI data- Returns:
- The created element
- Throws:
MicroException- if this node cannot have children
-
appendContainer
Append a new container to this node- Returns:
- The created container.
- Throws:
MicroException- if this node cannot have children
-
removeChild
Remove the passed child.- Parameters:
aChild- The child to be removed. May not benull.- Returns:
EChange.CHANGEDif the child was successfully removed,EChange.UNCHANGEDotherwise.
-
removeChildAtIndex
Remove the child not at the specified index.- Parameters:
nIndex- The 0-based index of the item to be removed.- Returns:
EChange.CHANGEDif the node was successfully removed,EChange.UNCHANGEDotherwise.
-
removeAllChildren
Remove all children from this node.- Returns:
EChange.CHANGEDif at least one child was present, and was successfully removed,EChange.UNCHANGEDotherwise.
-
replaceChild
@Nonnull default com.helger.commons.state.EChange replaceChild(@Nonnull IMicroNode aOldChild, @Nonnull IMicroNode aNewChild) Replace the passed old child with the new child.- Parameters:
aOldChild- The child to be removed. May not benull.aNewChild- The child to be inserted instead. May not benull.- Returns:
EChange.CHANGEDif the child was successfully replaced,EChange.UNCHANGEDif old child and new child are identical.
-
getType
- Returns:
- The node type. Never
null.
-
isDocument
boolean isDocument()- Returns:
trueif this node can safely be casted toIMicroDocument.
-
isDocumentType
boolean isDocumentType()- Returns:
trueif this node can safely be casted toIMicroDocumentType.
-
isText
boolean isText()- Returns:
trueif this node can safely be casted toIMicroText.
-
isCDATA
boolean isCDATA()- Returns:
trueif this node can safely be casted toIMicroCDATA.
-
isComment
boolean isComment()- Returns:
trueif this node can safely be casted toIMicroComment.
-
isEntityReference
boolean isEntityReference()- Returns:
trueif this node can safely be casted toIMicroEntityReference.
-
isElement
boolean isElement()- Returns:
trueif this node can safely be casted toIMicroElement.
-
isProcessingInstruction
boolean isProcessingInstruction()- Returns:
trueif this node can safely be casted toIMicroProcessingInstruction.
-
isContainer
boolean isContainer()- Returns:
trueif this node can safely be casted toIMicroContainer.
-
registerEventTarget
@Nonnull com.helger.commons.state.EChange registerEventTarget(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEventTarget aTarget) Register a specific MicroDOM event listener. One event listener can only be attached once to an event!- Parameters:
eEventType- The event type. May not benull.aTarget- The event target to be added. May not benull.- Returns:
EChange.CHANGEDif the event listener was registered,EChange.UNCHANGEDotherwise.
-
unregisterEventTarget
@Nonnull com.helger.commons.state.EChange unregisterEventTarget(@Nonnull EMicroEvent eEventType, @Nonnull IMicroEventTarget aTarget) Unregister a specific MicroDOM event listener.- Parameters:
eEventType- The event type. May not benull.aTarget- The event target to be added. May not benull.- Returns:
EChange.CHANGEDif the event listener was unregistered,EChange.UNCHANGEDotherwise.
-
getAllEventTargets
@Nonnull @ReturnsMutableCopy com.helger.commons.collection.impl.ICommonsMap<EMicroEvent,com.helger.commons.callback.CallbackList<IMicroEventTarget>> getAllEventTargets()- Returns:
- A map of all registered event targets. Never
null.
-
getAllEventTargets
@Nonnull @ReturnsMutableCopy com.helger.commons.callback.CallbackList<IMicroEventTarget> getAllEventTargets(@Nullable EMicroEvent eEvent) Get all event targets for a certain event.- Parameters:
eEvent- The event to be queried. May benull.- Returns:
- A map of all registered event targets. Never
null.
-
isEqualContent
As instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.- Parameters:
aNode- The node to compare to this.- Returns:
trueif the nodes are of the same type and the same content,falseotherwise.
-