Package org.owasp.html
Class HtmlStreamRenderer
- java.lang.Object
-
- org.owasp.html.HtmlStreamRenderer
-
- All Implemented Interfaces:
HtmlStreamEventReceiver
@NotThreadSafe public class HtmlStreamRenderer extends 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 withwriteOpenTag("plaintext", ...)
, then any tags in the second will not be interpreted as tags in the concatenated version.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeDocument()
Called first to indicate that no more events will be received.void
closeTag(String elementName)
Called to specify an end tag like</elementName>
.static HtmlStreamRenderer
create(Appendable output, Handler<? super IOException> ioExHandler, Handler<? super String> badHtmlHandler)
Factory.static HtmlStreamRenderer
create(StringBuilder output, Handler<? super String> badHtmlHandler)
Factory.boolean
isDocumentOpen()
True ifopenDocument()
has been called andcloseDocument()
has not subsequently been called.void
openDocument()
Called first to indicate that events follow.void
openTag(String elementName, List<String> attrs)
Called to specify a tag with the given name and attributes.void
text(String text)
Called to specify a text node.
-
-
-
Method Detail
-
create
public static HtmlStreamRenderer create(@WillCloseWhenClosed Appendable output, Handler<? super IOException> ioExHandler, Handler<? super 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(StringBuilder output, Handler<? super 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 IllegalStateException
Description copied from interface:HtmlStreamEventReceiver
Called first to indicate that events follow.- Specified by:
openDocument
in interfaceHtmlStreamEventReceiver
- Throws:
IllegalStateException
-
closeDocument
public final void closeDocument() throws IllegalStateException
Description copied from interface:HtmlStreamEventReceiver
Called first to indicate that no more events will be received.- Specified by:
closeDocument
in interfaceHtmlStreamEventReceiver
- Throws:
IllegalStateException
-
isDocumentOpen
public final boolean isDocumentOpen()
True ifopenDocument()
has been called andcloseDocument()
has not subsequently been called.
-
openTag
public final void openTag(String elementName, List<String> attrs)
Description copied from interface:HtmlStreamEventReceiver
Called to specify a tag with the given name and attributes.- Specified by:
openTag
in interfaceHtmlStreamEventReceiver
attrs
- alternating attribute names and values.
-
closeTag
public final void closeTag(String elementName)
Description copied from interface:HtmlStreamEventReceiver
Called to specify an end tag like</elementName>
.- Specified by:
closeTag
in interfaceHtmlStreamEventReceiver
-
text
public final void text(String text)
Description copied from interface:HtmlStreamEventReceiver
Called to specify a text node.- Specified by:
text
in interfaceHtmlStreamEventReceiver
-
-