Top Description Constructors Methods
org.apache.tomcat.util.security

public Class Escape

extends Object
Class Inheritance

Provides utility methods to escape content for different contexts. It is critical that the escaping used is correct for the context in which the data is to be used.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

The escaped content or null if the content was null
htmlElementContent
(String
The content to escape
content
)

Escape content for use in HTML.

public static String

Returns:

The escaped content or "?" if obj is null
htmlElementContent
(Object
The object to convert to String and then escape
obj
)

Convert the object to a string via Object#toString() and HTML escape the resulting string for use in HTML content.

public static String

Returns:

The escaped content or null if the content was null
xml
(String
The content to escape
content
)

Escape content for use in XML.

public static String

Returns:

The escaped content or the value of ifNull if the content was null
xml
(String
The value to return if content is null
ifNull
,
String
The content to escape
content
)

Escape content for use in XML.

public static String

Returns:

The escaped content or the value of ifNull if the content was null
xml
(String
The value to return if content is null
ifNull
,
boolean
Should CR and LF also be escaped?
escapeCRLF
,
String
The content to escape
content
)

Escape content for use in XML.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Escapeback to summary
private Escape()

Method Detail

htmlElementContentback to summary
public static String htmlElementContent(String content)

Escape content for use in HTML. This escaping is suitable for the following uses:

  • Element content when the escaped data will be placed directly inside tags such as <p>, <td> etc.
  • Attribute values when the attribute value is quoted with " or '.
Parameters
content:String

The content to escape

Returns:String

The escaped content or null if the content was null

htmlElementContentback to summary
public static String htmlElementContent(Object obj)

Convert the object to a string via Object#toString() and HTML escape the resulting string for use in HTML content.

Parameters
obj:Object

The object to convert to String and then escape

Returns:String

The escaped content or "?" if obj is null

xmlback to summary
public static String xml(String content)

Escape content for use in XML.

Parameters
content:String

The content to escape

Returns:String

The escaped content or null if the content was null

xmlback to summary
public static String xml(String ifNull, String content)

Escape content for use in XML.

Parameters
ifNull:String

The value to return if content is null

content:String

The content to escape

Returns:String

The escaped content or the value of ifNull if the content was null

xmlback to summary
public static String xml(String ifNull, boolean escapeCRLF, String content)

Escape content for use in XML.

Parameters
ifNull:String

The value to return if content is null

escapeCRLF:boolean

Should CR and LF also be escaped?

content:String

The content to escape

Returns:String

The escaped content or the value of ifNull if the content was null