Class HCHelper


  • @Immutable
    public final class HCHelper
    extends Object
    Helper class for common IHCNode related elements.
    Author:
    Philip Helger
    • Method Detail

      • iterateChildren

        public static void iterateChildren​(@Nonnull
                                           IHCNode aNode,
                                           @Nonnull
                                           IHCIteratorCallback aCallback)
        Recursively iterate all child nodes of the passed node.
        Parameters:
        aNode - The node who's children should be iterated.
        aCallback - The callback to be invoked on every child
      • iterateChildrenNoCopy

        public static void iterateChildrenNoCopy​(@Nonnull
                                                 IHCNode aNode,
                                                 @Nonnull
                                                 IHCIteratorCallback aCallback)
        Recursively iterate all child nodes of the passed node.
        Parameters:
        aNode - The node who's children should be iterated.
        aCallback - The callback to be invoked on every child
      • iterateChildrenNonBreakable

        public static void iterateChildrenNonBreakable​(@Nonnull
                                                       IHCNode aNode,
                                                       @Nonnull
                                                       IHCIteratorNonBreakableCallback aCallback)
        Recursively iterate all child nodes of the passed node.
        Parameters:
        aNode - The node who's children should be iterated.
        aCallback - The callback to be invoked on every child
      • recursiveContainsAtLeastOneTextNode

        public static boolean recursiveContainsAtLeastOneTextNode​(@Nullable
                                                                  IHCNode aStartNode)
      • getFirstChildElement

        @Nullable
        public static com.helger.xml.microdom.IMicroElement getFirstChildElement​(@Nonnull
                                                                                 com.helger.xml.microdom.IMicroElement aElement,
                                                                                 @Nonnull
                                                                                 EHTMLElement eHTMLElement)
        Find the first HTML child element within a start element. This check considers both lower- and upper-case element names. Mixed case is not supported!
        Parameters:
        aElement - The element to search in
        eHTMLElement - The HTML element to search.
        Returns:
        null if no such child element is present.
      • getChildElements

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<com.helger.xml.microdom.IMicroElement> getChildElements​(@Nonnull
                                                                                                                              com.helger.xml.microdom.IMicroElement aElement,
                                                                                                                              @Nonnull
                                                                                                                              EHTMLElement eHTMLElement)
        Get a list of all HTML child elements of the given element. This methods handles lower- and upper-cased elements.
        Parameters:
        aElement - The element to search in
        eHTMLElement - The HTML element to search
        Returns:
        A non-null list where the lower-case elements are listed before the upper-case elements.
      • getAsFlattenedList

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<IHCNode> getAsFlattenedList​(@Nullable
                                                                                                  IHCNode aNode)
        Inline all contained node lists so that a "flat" list results. This only flattens something if the passed node is an HCNodeList and all node-lists directly contained in the other node lists. Node-lists that are hidden deep inside the tree are not considered!
        Parameters:
        aNode - The source node. May be null.
        Returns:
        A non-null flattened list.
      • getAsFlattenedList

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<IHCNode> getAsFlattenedList​(@Nullable
                                                                                                  Iterable<? extends IHCNode> aNodes)
        Inline all contained node lists so that a "flat" list results. This only flattens something if the passed node is an HCNodeList and all node-lists directly contained in the other node lists. Node-lists that are hidden deep inside the tree are not considered!
        Parameters:
        aNodes - The source nodes. May be null or empty.
        Returns:
        A non-null flattened list.
      • getUnwrappedNode

        @Nullable
        public static IHCNode getUnwrappedNode​(@Nullable
                                               IHCNode aHCNode)
        Resolve all wrappings via IHCWrappingNode of the passed node. This is usually either an HCOutOfBandNode or a HCConditionalCommentNode.
        Parameters:
        aHCNode - The node to be unwrapped. May be null.
        Returns:
        The unwrapped node. May be the same as the parameter, if the node is not wrapped. May be null if the parameter node is null.
      • isWrappedNode

        public static boolean isWrappedNode​(@Nullable
                                            IHCNode aHCNode)
        Check if the passed node is a wrapped node by checking if it implements IHCWrappingNode.
        Parameters:
        aHCNode - The node to be checked. May be null.
        Returns:
        true if the node is not null and if it implements IHCWrappingNode.
      • getAsHTMLID

        @Nonnull
        public static String getAsHTMLID​(@Nullable
                                         String sSrc)
        Convert the passed ID string to a valid HTML ID.
        Parameters:
        sSrc - The source string. May be null.
        Returns:
        An underscore instead of an empty string. The string cleaned from the malicious characters.