Class Escape


  • @ProviderType
    public final class Escape
    extends java.lang.Object
    Encoding utility functions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull java.lang.String jcrQueryContainsExpr​(@NotNull java.lang.String value)
      Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath) or contains (JCR-SQL2).
      static @NotNull java.lang.String jcrQueryLikeString​(@NotNull java.lang.String value)
      Convert a string to a JCR search expression literal, suitable for use in jcr:like() (inside XPath) or contains (JCR-SQL2).
      static @NotNull java.lang.String jcrQueryLiteral​(@NotNull java.lang.String value)
      Convert a string to a literal, suitable for inclusion in a query (XPath or JCR-SQL2).
      static @NotNull java.lang.String urlEncode​(@Nullable java.lang.String value)
      Applies URL-Encoding to the given parameter name or value.
      static @NotNull java.lang.String validFilename​(@NotNull java.lang.String value)
      Create valid filename by applying method validName(String) on filename and extension.
      static @NotNull java.lang.String validName​(@NotNull java.lang.String value)
      Creates a valid node name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • urlEncode

        @NotNull
        public static @NotNull java.lang.String urlEncode​(@Nullable
                                                          @Nullable java.lang.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:
        java.lang.RuntimeException - in the very unlikely case that UTF-8 is not supported on the current system
      • validName

        @NotNull
        public static @NotNull java.lang.String validName​(@NotNull
                                                          @NotNull java.lang.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 java.lang.String validFilename​(@NotNull
                                                              @NotNull java.lang.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 java.lang.String jcrQueryLiteral​(@NotNull
                                                                @NotNull java.lang.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 java.lang.String jcrQueryContainsExpr​(@NotNull
                                                                     @NotNull java.lang.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 java.lang.String jcrQueryLikeString​(@NotNull
                                                                   @NotNull java.lang.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.