org.apache.tomcat.util.security

## Class Escape

- java.lang.Object
- - org.apache.tomcat.util.security.Escape

-     public class Escape
      extends Object

  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

    Constructors
    Constructor and Description
    `Escape()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `htmlElementContent(String content)` Escape content for use in HTML.
    `static String` | `htmlElementContext(Object obj)` Convert the object to a string via `Object.toString()` and HTML escape the resulting string for use in HTML content.
    `static String` | `xml(String content)` Escape content for use in XML.
    `static String` | `xml(String ifNull, boolean escapeCRLF, String content)` Escape content for use in XML.
    `static String` | `xml(String ifNull, String content)` Escape content for use in XML.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Escape

          public Escape()

  - ### Method Detail

    - #### htmlElementContent

          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` - The content to escape
      Returns:
        The escaped content or `null` if the content was `null`

    - #### htmlElementContext

          public static String htmlElementContext(Object obj)

      Convert the object to a string via `Object.toString()` and HTML escape the resulting string for use in HTML content.
      Parameters:
        `obj` - The object to convert to String and then escape
      Returns:
        The escaped content or `"?"` if obj is `null`

    - #### xml

          public static String xml(String content)

      Escape content for use in XML.
      Parameters:
        `content` - The content to escape
      Returns:
        The escaped content or `null` if the content was `null`

    - #### xml

          public static String xml(String ifNull,
                   String content)

      Escape content for use in XML.
      Parameters:
        `ifNull` - The value to return if content is `null`
        `content` - The content to escape
      Returns:
        The escaped content or the value of `ifNull` if the content was `null`

    - #### xml

          public static String xml(String ifNull,
                   boolean escapeCRLF,
                   String content)

      Escape content for use in XML.
      Parameters:
        `ifNull` - The value to return if content is `null`
        `escapeCRLF` - Should CR and LF also be escaped?
        `content` - The content to escape
      Returns:
        The escaped content or the value of ifNull if the content was `null`

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.