Class Escape

java.lang.Object
io.wcm.sling.commons.util.Escape

@ProviderType public final class Escape extends Object
Encoding utility functions.
  • Method Details

    • urlEncode

      @NotNull public static @NotNull String urlEncode(@Nullable @Nullable String value)
      Applies URL-Encoding to the given parameter name or value. Uses URLEncoder.encode(String, String) with UTF-8 character set, while avoiding the need to catch the UnsupportedEncodingException.
      Parameters:
      value - the parameter name or value to encode
      Returns:
      URL-encoded string - or empty string if the specified value was null
      Throws:
      RuntimeException - in the very unlikely case that UTF-8 is not supported on the current system
    • validName

      @NotNull public static @NotNull String validName(@NotNull @NotNull String value)
      Creates a valid node name. Replaces all chars not in a-z, A-Z and 0-9 or '_' with '-' and converts all to lowercase.
      Parameters:
      value - String to be labelized.
      Returns:
      The labelized string.
    • validFilename

      @NotNull public static @NotNull String validFilename(@NotNull @NotNull String value)
      Create valid filename by applying method validName(String) on filename and extension.
      Parameters:
      value - Filename
      Returns:
      Valid filename
    • jcrQueryLiteral

      @NotNull public static @NotNull String jcrQueryLiteral(@NotNull @NotNull String value)
      Convert a string to a literal, suitable for inclusion in a query (XPath or JCR-SQL2). See JSR-283 specification v2.0, Section 4.6.6.19.
      Parameters:
      value - Any string.
      Returns:
      A valid JCR query string literal, including enclosing quotes.
    • jcrQueryContainsExpr

      @NotNull public static @NotNull String jcrQueryContainsExpr(@NotNull @NotNull String value)
      Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath) or contains (JCR-SQL2). The characters - and " have special meaning, and may be escaped with a backslash to obtain their literal value. See JSR-283 specification v2.0, Section 4.6.6.19.
      Parameters:
      value - Any string.
      Returns:
      A valid string literal suitable for use in JCR contains clauses, including enclosing quotes.
    • jcrQueryLikeString

      @NotNull public static @NotNull String jcrQueryLikeString(@NotNull @NotNull String value)
      Convert a string to a JCR search expression literal, suitable for use in jcr:like() (inside XPath) or contains (JCR-SQL2). The characters _ and % have special meaning, and may be escaped with a backslash to obtain their literal value. See JSR-283 specification v2.0, Section 4.6.6.19.
      Parameters:
      value - Any string.
      Returns:
      A valid string literal suitable for use as part of JCR like clauses, excluding enclosing quotes, excluding quote escaping.