@ParametersAreNonnullByDefault public final class SanitizedContents extends Object
This should contain utilities that have extremely broad application. More specific utilities should reside with the specific project.
All utilities here should be extremely difficult to abuse in a way that could create attacker-controlled SanitizedContent objects. Java's type system is a great tool to achieve this.
| Modifier and Type | Method and Description |
|---|---|
static SanitizedContent |
concatHtml(SanitizedContent... contents)
Concatenate the contents of multiple
SanitizedContent objects of kind HTML. |
static SanitizedContent |
emptyString(SanitizedContent.ContentKind kind)
Creates an empty string constant.
|
static SanitizedContent |
fromResource(Class<?> contextClass,
String resourceName,
Charset charset,
SanitizedContent.ContentKind kind)
Loads assumed-safe content from a Java resource.
|
static SanitizedContent |
fromResource(String resourceName,
Charset charset,
SanitizedContent.ContentKind kind)
Loads assumed-safe content from a Java resource.
|
static SanitizedContent |
unsanitizedText(String text)
Creates a SanitizedContent object of kind TEXT and unknown direction.
|
static SanitizedContent |
unsanitizedText(String text,
Dir dir)
Creates a SanitizedContent object of kind TEXT of a given direction (null if unknown).
|
public static SanitizedContent emptyString(SanitizedContent.ContentKind kind)
public static SanitizedContent unsanitizedText(String text, @Nullable Dir dir)
This is useful when stubbing out a function that needs to create a SanitizedContent object.
public static SanitizedContent unsanitizedText(String text)
This is useful when stubbing out a function that needs to create a SanitizedContent object.
public static SanitizedContent concatHtml(SanitizedContent... contents)
SanitizedContent objects of kind HTML.contents - The HTML content to combine.public static SanitizedContent fromResource(Class<?> contextClass, String resourceName, Charset charset, SanitizedContent.ContentKind kind) throws IOException
contextClass - Class relative to which to load the resource.resourceName - The name of the resource, relative to the context class.charset - The character set to use, usually Charsets.UTF_8.kind - The content kind of the resource.IOExceptionpublic static SanitizedContent fromResource(String resourceName, Charset charset, SanitizedContent.ContentKind kind) throws IOException
resourceName - The name of the resource to be found using
context class loader.charset - The character set to use, usually Charsets.UTF_8.kind - The content kind of the resource.IOException