Class Transform

java.lang.Object
org.apache.logging.log4j.core.util.Transform

public final class Transform extends Object
Utility class for transforming strings.
  • Method Details

    • escapeHtmlTags

      public static String escapeHtmlTags(String input)
      Escapes characters in a string for safe inclusion in HTML or XML text.

      Replaces the characters <, >, &, " and ' with their corresponding entity references (&lt;, &gt;, &amp;, &quot;, and &#39;). Any code point that is invalid in XML 1.0 is replaced with the Unicode replacement character U+FFFD.

      Parameters:
      input - The text to be escaped; may be null or empty.
      Returns:
      The escaped string, or the original input if no changes were required.
    • appendEscapingCData

      public static void appendEscapingCData(StringBuilder buf, String str)
      Ensures that embedded CDEnd strings (]]>) are handled properly within message, NDC and throwable tag text.
      Parameters:
      buf - StringBuilder holding the XML data to this point. The initial CDStart (<![CDATA[) and final CDEnd (]]>) of the CDATA section are the responsibility of the calling method.
      str - The String that is inserted into an existing CDATA Section within buf.
    • escapeJsonControlCharacters

      public static String escapeJsonControlCharacters(String input)
      This method takes a string which may contain JSON reserved chars and escapes them.
      Parameters:
      input - The text to be converted.
      Returns:
      The input string with the special characters replaced.