Class HtmlStreamRenderer

  • All Implemented Interfaces:
    HtmlStreamEventReceiver

    @NotThreadSafe
    public class HtmlStreamRenderer
    extends java.lang.Object
    implements HtmlStreamEventReceiver
    Given a series of HTML tokens, writes valid, normalized HTML to the output. The output will have well-defined tag boundaries, but there may be orphaned or missing close and open tags. The result of two renderers can always be concatenated to produce a larger snippet of HTML, but if the first was called with writeOpenTag("plaintext", ...), then any tags in the second will not be interpreted as tags in the concatenated version.
    • Method Detail

      • create

        public static HtmlStreamRenderer create​(@WillCloseWhenClosed
                                                java.lang.Appendable output,
                                                Handler<? super java.io.IOException> ioExHandler,
                                                Handler<? super java.lang.String> badHtmlHandler)
        Factory.
        Parameters:
        output - the buffer to which HTML is streamed.
        ioExHandler - called with any exception raised by output.
        badHtmlHandler - receives alerts when HTML cannot be rendered because there is not valid HTML tree that results from that series of calls. E.g. it is not possible to create an HTML <style> element whose textual content is "</style>".
      • create

        public static HtmlStreamRenderer create​(java.lang.StringBuilder output,
                                                Handler<? super java.lang.String> badHtmlHandler)
        Factory.
        Parameters:
        output - the buffer to which HTML is streamed.
        badHtmlHandler - receives alerts when HTML cannot be rendered because there is not valid HTML tree that results from that series of calls. E.g. it is not possible to create an HTML <style> element whose textual content is "</style>".
      • openDocument

        public final void openDocument()
                                throws java.lang.IllegalStateException
        Specified by:
        openDocument in interface HtmlStreamEventReceiver
        Throws:
        java.lang.IllegalStateException
      • closeDocument

        public final void closeDocument()
                                 throws java.lang.IllegalStateException
        Specified by:
        closeDocument in interface HtmlStreamEventReceiver
        Throws:
        java.lang.IllegalStateException
      • isDocumentOpen

        public final boolean isDocumentOpen()
      • openTag

        public final void openTag​(java.lang.String elementName,
                                  java.util.List<java.lang.String> attrs)
        Specified by:
        openTag in interface HtmlStreamEventReceiver
        attrs - alternating attribute names and values.