Class TextUtil


  • @ProviderType
    public final class TextUtil
    extends Object
    • Method Detail

      • getFirstNonNull

        public static <T> T getFirstNonNull​(T... values)
        Returns first non-null value from the parameter list

        Ex. TextUtil.getFirstNonNull(x.getLastModifiedDate(), x.getCreatedDate())

        If getLastModifiedDate() returns null, and getCreatedDate() returns not-null, the value for getCreatedDate() is returned.

        Type Parameters:
        T -
        Parameters:
        values -
        Returns:
      • getFirstNonEmpty

        public static String getFirstNonEmpty​(String... values)
        Returns the first non-null and non-empty String from the parameter list of strings.

        Ex. TextUtil.getFirstNonEmpty(x.getPageTitle(), x.getNavigationTitle(), x.getTitle(), x.getName())

        Parameters:
        values -
        Returns:
      • getFirstProperty

        public static <T> T getFirstProperty​(org.apache.sling.api.resource.Resource resource,
                                             Class<T> klass,
                                             String... keys)
        Returns first non-null value from the resource property.
        Type Parameters:
        T -
        Parameters:
        resource -
        klass -
        keys -
        Returns:
      • getFirstProperty

        public static <T> T getFirstProperty​(org.apache.sling.api.resource.ValueMap valueMap,
                                             Class<T> klass,
                                             String... keys)
        Returns first non-null value from the resource property value map.

        Ex. TextUtil.getFirstProperty(Date.class, "jcr:lastModified", "jcr:created")

        If getLastModifiedDate() returns null, and getCreatedDate() returns not-null, the value for getCreatedDate() is returned.

        Type Parameters:
        T -
        Parameters:
        valueMap - of resource properties
        klass - data type to return
        keys - list of property names to evaluate
        Returns:
      • isRichText

        public static boolean isRichText​(String str)
        Looks for <..> substrings in the parameter string. If any are found it assume Rich text.
        Parameters:
        str -
        Returns: