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 Details

    • getNodeName

      @Nonnull @Nonempty String getNodeName()
      Returns:
      Just an abstract name that depends on the implementing class. For IMicroElement nodes this is the same as the tag name.
    • getNodeValue

      default String getNodeValue()
      Returns:
      The value of this node. This depends on the concrete implementation class. It is currently implemented for IMicroText, IMicroComment and IMicroEntityReference.
    • getAllChildren

      @Nullable com.helger.commons.collection.impl.ICommonsList<IMicroNode> getAllChildren()
      Get a list of all direct child nodes.
      Specified by:
      getAllChildren in interface com.helger.commons.hierarchy.IHasChildren<IMicroNode>
      Specified by:
      getAllChildren in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Returns:
      May be null if the node has no children.
    • containsAnyChild

      default boolean containsAnyChild(@Nonnull Predicate<? super IMicroNode> aFilter)
      Check if any direct child matching the provided filter is contained.
      Parameters:
      aFilter - The filter that is applied to all child nodes. May not be null.
      Returns:
      true if any child matching the provided filter is contained, false otherwise.
    • getFirstChild

      @Nullable IMicroNode getFirstChild()
      Specified by:
      getFirstChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Returns:
      The first child node of this node, or null if this node has no children.
    • getLastChild

      @Nullable IMicroNode getLastChild()
      Specified by:
      getLastChild in interface com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>
      Returns:
      The last child node of this node, or null if 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 null if this node has no children.
    • getPreviousSibling

      @Nullable IMicroNode getPreviousSibling()
      Returns:
      The previous node on the same level as this node, or null if this node has no preceding siblings.
    • getNextSibling

      @Nullable IMicroNode getNextSibling()
      Returns:
      The next node on the same level as this node, or null if this node has no succeeding siblings.
    • hasParent

      boolean hasParent()
      Specified by:
      hasParent in interface com.helger.commons.hierarchy.IHasParent<IMicroNode>
      Returns:
      true if this node has a parent node assigned, false otherwise.
    • getParent

      @Nullable IMicroNode getParent()
      Specified by:
      getParent in interface com.helger.commons.hierarchy.IHasParent<IMicroNode>
      Returns:
      May be null.
    • detachFromParent

      @Nonnull IMicroNode detachFromParent()
      Detach this node from the parent node so it can be inserted into another node without problems. Otherwise you would get an IllegalStateException if adding this node again to another parent since each node can only have one parent.
      Returns:
      this
    • findParentElement

      @Nullable IMicroElement findParentElement(@Nonnull Predicate<? super IMicroElement> aFilter)
    • getParentElementWithName

      @Nullable default IMicroElement getParentElementWithName(@Nullable String sTagName)
    • getParentElementWithName

      @Nullable default IMicroElement getParentElementWithName(@Nullable String sNamespaceURI, @Nullable String sTagName)
    • appendChild

      @Nullable <NODETYPE extends IMicroNode> NODETYPE appendChild(@Nullable NODETYPE aChildNode)
      Append any child to the node.
      Type Parameters:
      NODETYPE - Parameter type == return type
      Parameters:
      aChildNode - The child node to append. May be null.
      Returns:
      The appended node, or null if the parameter was null.
      Throws:
      MicroException - if this node cannot have children
    • appendChildren

      default void appendChildren(@Nullable IMicroNode... aChildren)
      Append multiple children to the node at once.
      Parameters:
      aChildren - The child nodes to be appended. May be null and may contain null values.
      Throws:
      MicroException - if this node cannot have children
      Since:
      9.0.3
    • appendChildren

      default void appendChildren(@Nullable Iterable<? extends IMicroNode> aChildren)
      Append multiple children to the node at once.
      Parameters:
      aChildren - The child nodes to be appended. May be null and may contain null values.
      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

      @Nonnull default IMicroText appendText(boolean bValue)
      Append a text node to this node.
      Parameters:
      bValue - Will add true or false
      Returns:
      The created text node.
      Throws:
      MicroException - if this node cannot have children
      Since:
      11.1.11
    • appendText

      @Nonnull default IMicroText appendText(int nValue)
      Append a text node to this node.
      Parameters:
      nValue - The number to append
      Returns:
      The created text node.
      Throws:
      MicroException - if this node cannot have children
      Since:
      11.1.11
    • appendText

      @Nonnull default IMicroText appendText(long nValue)
      Append a text node to this node.
      Parameters:
      nValue - The number to append
      Returns:
      The created text node.
      Throws:
      MicroException - if this node cannot have children
      Since:
      11.1.11
    • appendText

      @Nonnull default IMicroText appendText(@Nullable CharSequence sText)
      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

      @Nonnull default IMicroText appendText(@Nonnull char[] aChars)
      Append a text node to this node.
      Parameters:
      aChars - Characters to append. May not be null
      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 be null
      nOfs - 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

      @Nonnull default IMicroText appendTextWithConversion(@Nullable Object aValue)
      Append a text node to this node. If the type of the value is not String, the TypeConverter is invoked to convert it to a String object.
      Parameters:
      aValue - text to be added
      Returns:
      The created text node.
      Throws:
      MicroException - if this node cannot have children
    • appendIgnorableWhitespaceText

      @Nonnull default IMicroText appendIgnorableWhitespaceText(@Nullable CharSequence sText)
      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

      @Nonnull default IMicroText appendIgnorableWhitespaceText(@Nonnull char[] aChars)
      Append a text node which is ignorable whitespace content to this node.
      Parameters:
      aChars - Characters to append. May not be null
      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 be null
      nOfs - 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

      @Nonnull default IMicroCDATA appendCDATA(@Nullable CharSequence sText)
      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

      @Nonnull default IMicroCDATA appendCDATA(@Nonnull char[] aChars)
      Append a CDATA node to this node.
      Parameters:
      aChars - Characters to append. May not be null
      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 be null
      nOfs - 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

      @Nonnull default IMicroCDATA appendCDATAWithConversion(@Nullable Object aValue)
      Append a CDATA node to this node. If the type of the value is not String, the TypeConverter is invoked to convert it to a String object.
      Parameters:
      aValue - CDATA to be added
      Returns:
      The created CDATA node.
      Throws:
      MicroException - if this node cannot have children
    • appendComment

      @Nonnull default IMicroComment appendComment(@Nullable CharSequence sText)
      Append a comment node to this node.
      Parameters:
      sText - comment text
      Returns:
      The created comment.
      Throws:
      MicroException - if this node cannot have children
    • appendComment

      @Nonnull default IMicroComment appendComment(@Nonnull char[] aChars)
      Append a comment node to this node.
      Parameters:
      aChars - Characters to append. May not be null
      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 be null
      nOfs - 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

      @Nonnull default IMicroComment appendCommentWithConversion(@Nullable Object aValue)
      Append a comment node to this node. If the type of the value is not String, the TypeConverter is invoked to convert it to a String object.
      Parameters:
      aValue - Comment to be added
      Returns:
      The created comment node.
      Throws:
      MicroException - if this node cannot have children
    • appendEntityReference

      @Nonnull default IMicroEntityReference appendEntityReference(@Nonnull String sName)
      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

      @Nonnull default IMicroElement appendElement(@Nonnull @Nonempty String sTagName)
      Append an element without namespace to this node.
      Parameters:
      sTagName - Element name to be created. May neither be null nor 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 be null.
      sTagName - Element name to be created. May neither be null nor 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 target
      sData - The PI data
      Returns:
      The created element
      Throws:
      MicroException - if this node cannot have children
    • appendContainer

      @Nonnull default IMicroContainer appendContainer()
      Append a new container to this node
      Returns:
      The created container.
      Throws:
      MicroException - if this node cannot have children
    • removeChild

      @Nonnull com.helger.commons.state.EChange removeChild(@Nonnull IMicroNode aChild)
      Remove the passed child.
      Parameters:
      aChild - The child to be removed. May not be null.
      Returns:
      EChange.CHANGED if the child was successfully removed, EChange.UNCHANGED otherwise.
    • removeChildAtIndex

      @Nonnull com.helger.commons.state.EChange removeChildAtIndex(@Nonnegative int nIndex)
      Remove the child not at the specified index.
      Parameters:
      nIndex - The 0-based index of the item to be removed.
      Returns:
      EChange.CHANGED if the node was successfully removed, EChange.UNCHANGED otherwise.
    • removeAllChildren

      @Nonnull com.helger.commons.state.EChange removeAllChildren()
      Remove all children from this node.
      Returns:
      EChange.CHANGED if at least one child was present, and was successfully removed, EChange.UNCHANGED otherwise.
    • 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 be null.
      aNewChild - The child to be inserted instead. May not be null.
      Returns:
      EChange.CHANGED if the child was successfully replaced, EChange.UNCHANGED if old child and new child are identical.
    • getType

      Returns:
      The node type. Never null.
    • isDocument

      boolean isDocument()
      Returns:
      true if this node can safely be casted to IMicroDocument.
    • isDocumentType

      boolean isDocumentType()
      Returns:
      true if this node can safely be casted to IMicroDocumentType.
    • isText

      boolean isText()
      Returns:
      true if this node can safely be casted to IMicroText.
    • isCDATA

      boolean isCDATA()
      Returns:
      true if this node can safely be casted to IMicroCDATA.
    • isComment

      boolean isComment()
      Returns:
      true if this node can safely be casted to IMicroComment.
    • isEntityReference

      boolean isEntityReference()
      Returns:
      true if this node can safely be casted to IMicroEntityReference.
    • isElement

      boolean isElement()
      Returns:
      true if this node can safely be casted to IMicroElement.
    • isProcessingInstruction

      boolean isProcessingInstruction()
      Returns:
      true if this node can safely be casted to IMicroProcessingInstruction.
    • isContainer

      boolean isContainer()
      Returns:
      true if this node can safely be casted to IMicroContainer.
    • 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 be null.
      aTarget - The event target to be added. May not be null.
      Returns:
      EChange.CHANGED if the event listener was registered, EChange.UNCHANGED otherwise.
    • 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 be null.
      aTarget - The event target to be added. May not be null.
      Returns:
      EChange.CHANGED if the event listener was unregistered, EChange.UNCHANGED otherwise.
    • 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 be null.
      Returns:
      A map of all registered event targets. Never null.
    • isEqualContent

      boolean isEqualContent(@Nullable 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.
      Parameters:
      aNode - The node to compare to this.
      Returns:
      true if the nodes are of the same type and the same content, false otherwise.