Class HCSpecialNodeHandler


  • @NotThreadSafe
    public final class HCSpecialNodeHandler
    extends Object
    This class is used to handle the special nodes (JS and CSS, inline and reference).
    Author:
    Philip Helger
    • Method Detail

      • isOutOfBandNode

        public static boolean isOutOfBandNode​(@Nonnull
                                              IHCNode aHCNode)
        Check if the passed node is an out-of-band node.
        Parameters:
        aHCNode - The node to be checked. May not be null.
        Returns:
        true if it is an out-of-band node, false if not.
      • recursiveExtractAndRemoveOutOfBandNodes

        public static void recursiveExtractAndRemoveOutOfBandNodes​(@Nonnull
                                                                   IHCNode aParentElement,
                                                                   @Nonnull
                                                                   List<IHCNode> aTargetList)
        Extract all out-of-band child nodes for the passed element. Must be called after the element is finished! All out-of-band nodes are detached from their parent so that the original node can be reused. Wrapped nodes where the inner node is an out of band node are also considered and removed.
        Parameters:
        aParentElement - The parent element to extract the nodes from. May not be null.
        aTargetList - The target list to be filled. May not be null.
      • getMergedInlineCSSAndJSNodes

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<IHCNode> getMergedInlineCSSAndJSNodes​(@Nonnull
                                                                                                            Iterable<? extends IHCNode> aNodes,
                                                                                                            boolean bKeepOnDocumentReady)
        Merge all inline CSS and JS elements contained in the source nodes into one script elements
        Parameters:
        aNodes - Source list of nodes. May not be null.
        bKeepOnDocumentReady - if true than all combined document.ready() scripts are kept as document.ready() scripts. If false than all document.ready() scripts are converted to regular scripts and are executed after all other scripts. For AJAX calls, this should be false.
        Returns:
        Target list. JS and CSS and other nodes are mixed. Inline JS and CSS that comes before files, is first. Than come the CSS and JS external as well as other elements. Finally the inline JS and CSS nodes to be emitted after the files are contained. So the resulting order is at it should be except that JS and CSS and other nodes are mixed.
      • getMergedInlineCSSAndJSNodes

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<IHCNode> getMergedInlineCSSAndJSNodes​(@Nonnull
                                                                                                            Iterable<? extends IHCNode> aNodes,
                                                                                                            @Nullable
                                                                                                            IHCOnDocumentReadyProvider aOnDocumentReadyProvider)
        Merge all inline CSS and JS elements contained in the source nodes into one script elements
        Parameters:
        aNodes - Source list of nodes. May not be null.
        aOnDocumentReadyProvider - if not null than all combined document.ready() scripts are kept as document.ready() scripts using this provider. If null than all document.ready() scripts are converted to regular scripts and are executed after all other scripts. For AJAX calls, this should be null as there is no "document ready" callback - alternatively you can provide a custom "on document ready" provider.
        Returns:
        Target list. JS and CSS and other nodes are mixed. Inline JS and CSS that comes before files, is first. Than come the CSS and JS external as well as other elements. Finally the inline JS and CSS nodes to be emitted after the files are contained. So the resulting order is at it should be except that JS and CSS and other nodes are mixed.
      • extractSpecialContent

        public static void extractSpecialContent​(@Nonnull
                                                 IHCNode aNode,
                                                 @Nonnull
                                                 AbstractHCSpecialNodes<?> aSpecialNodes,
                                                 boolean bKeepOnDocumentReady)
        Extract all out-of-band nodes of the source node, merge JS and CSS and finally extract all special nodes into the passed object.
        Parameters:
        aNode - Source node. May not be null.
        aSpecialNodes - Target special node object to be filled. May not be null.
        bKeepOnDocumentReady - if true than all combined document.ready() scripts are kept as document.ready() scripts. If false than all document.ready() scripts are converted to regular scripts and are executed after all other scripts. For AJAX calls, this should be false.
      • extractSpecialContent

        public static void extractSpecialContent​(@Nonnull
                                                 IHCNode aNode,
                                                 @Nonnull
                                                 AbstractHCSpecialNodes<?> aSpecialNodes,
                                                 @Nullable
                                                 IHCOnDocumentReadyProvider aOnDocumentReadyProvider)
        Extract all out-of-band nodes of the source node, merge JS and CSS and finally extract all special nodes into the passed object.
        Parameters:
        aNode - Source node. May not be null.
        aSpecialNodes - Target special node object to be filled. May not be null.
        aOnDocumentReadyProvider - if not null than all combined document.ready() scripts are kept as document.ready() scripts using this provider. If null than all document.ready() scripts are converted to regular scripts and are executed after all other scripts. For AJAX calls, this should be null as there is no "document ready" callback - alternatively you can provide a custom "on document ready" provider.