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 voidcloseDocument()Called first to indicate that no more events will be received.voidcloseTag(String elementName)Called to specify an end tag like</elementName>.static HtmlStreamRenderercreate(Appendable output, Handler<? super IOException> ioExHandler, Handler<? super String> badHtmlHandler)Factory.static HtmlStreamRenderercreate(StringBuilder output, Handler<? super String> badHtmlHandler)Factory.booleanisDocumentOpen()True ifopenDocument()has been called andcloseDocument()has not subsequently been called.voidopenDocument()Called first to indicate that events follow.voidopenTag(String elementName, List<String> attrs)Called to specify a tag with the given name and attributes.voidtext(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 IllegalStateExceptionDescription copied from interface:HtmlStreamEventReceiverCalled first to indicate that events follow.- Specified by:
openDocumentin interfaceHtmlStreamEventReceiver- Throws:
IllegalStateException
-
closeDocument
public final void closeDocument() throws IllegalStateExceptionDescription copied from interface:HtmlStreamEventReceiverCalled first to indicate that no more events will be received.- Specified by:
closeDocumentin 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:HtmlStreamEventReceiverCalled to specify a tag with the given name and attributes.- Specified by:
openTagin interfaceHtmlStreamEventReceiverattrs- alternating attribute names and values.
-
closeTag
public final void closeTag(String elementName)
Description copied from interface:HtmlStreamEventReceiverCalled to specify an end tag like</elementName>.- Specified by:
closeTagin interfaceHtmlStreamEventReceiver
-
text
public final void text(String text)
Description copied from interface:HtmlStreamEventReceiverCalled to specify a text node.- Specified by:
textin interfaceHtmlStreamEventReceiver
-
-