public static class SafeHtmlBuilder extends Object
StringBuilder
; unlike a
StringBuilder
, it automatically HTML-escapes appended input where
necessary.
In addition, it supports methods that allow strings with HTML markup to be
appended without escaping: One can append other SafeHtml
objects, and
one can append constant strings. The method that appends constant strings
(#appendHtmlConstant(String)
) requires a convention of use to be
adhered to in order for this class to adhere to the contract required by
SafeHtml
: The argument expression must be fully determined and known
to be safe at compile time, and the value of the argument must not contain
incomplete HTML tags. See #appendHtmlConstant(String)
for details.
The accumulated XSS-safe HTML can be obtained in the form of a
SafeHtml
via the #toSafeHtml()
method.
This class is not thread-safe.
Copyright © 2018. All rights reserved.