Package lumis.util

Class TextUtil


  • @StableMinor(version="14.2",
                 sinceVersion="4.0")
    public class TextUtil
    extends Object
    Utility methods for text-related operations.
    Since:
    4.0.0
    Version:
    $Revision: 24985 $ $Date: 2022-05-02 23:04:30 -0300 (Mon, 02 May 2022) $
    • Constructor Detail

      • TextUtil

        public TextUtil()
    • Method Detail

      • stringReplace

        public static String stringReplace​(String str,
                                           String target,
                                           String replacement)
        Parameters:
        str - is the original String which may contain substring target.
        target - is the substring which is to be replaced.
        replacement - is the replacement for target.
      • stringReplace

        public static String stringReplace​(String str,
                                           String target,
                                           String replacement,
                                           boolean replaceOnlyFirstOccurrence)
      • escapeRegexpReplacement

        public static String escapeRegexpReplacement​(String replacementString)
        Escapes regexp replacement commands in a string for use as replacement.
        Parameters:
        replacementString - the replacement string.
        Returns:
        the string with regexp replacement commands escaped.
      • escapeJs

        public static String escapeJs​(String javascriptString)
        Escapes a javascript string so it can added to inside quotes without breaking the javascript code.

        Single quotes, double quotes, '\', next line and line feed characters are escaped.

        Parameters:
        javascriptString - the javacript string raw value.
        Returns:
        the javascript string escaped.
      • escapeLocalizationParameter

        public static String escapeLocalizationParameter​(String str)
        Escapes a localization parameter string. ; character is espaced to \;
        Parameters:
        str - the string to escape.
        Returns:
        the escaped string.
        Since:
        4.0.4
      • joinStringCollection

        public static String joinStringCollection​(Collection<String> strings,
                                                  String delim)
        Generates a string joining the strings in the collection with the delimiter specified between them.
        Parameters:
        strings - the collectino with the strings.
        delim - the delimiter.
        Returns:
        the generated string.
      • joinStringArray

        public static String joinStringArray​(String[] array,
                                             String delim)
      • read

        public static String read​(InputStream in,
                                  String encoding)
                           throws IOException
        Reads an input stream as a string using the given encoding.
        Parameters:
        in - the input stream.
        encoding - the encoding.
        Returns:
        the string read.
        Throws:
        IOException - if an I/O exception occurs.
        Since:
        6.0.0
      • read

        public static String read​(Reader reader)
                           throws IOException
        Reads the data from the reader until its end is reached.
        Parameters:
        reader - the reader.
        Returns:
        the string read.
        Throws:
        IOException - if an I/O error occurs.
        Since:
        4.0.7
      • indexOfCaseInsensitive

        public static int indexOfCaseInsensitive​(StringBuilder source,
                                                 String findStr)
      • indexOfCaseInsensitive

        public static int indexOfCaseInsensitive​(StringBuilder source,
                                                 String findStr,
                                                 int fromIndex)
      • leftPad

        public static String leftPad​(String s,
                                     int minimumLength,
                                     char fillingChar)
      • stringRepeat

        public static String stringRepeat​(char ch,
                                          int count)
        Generate a string repeating the 'ch' character 'count' times.
        Parameters:
        ch - The character to be repeated
        count - The number of repetitions
        Returns:
      • joinStringCollectionUserFriendly

        public static String joinStringCollectionUserFriendly​(List<String> listItems)
                                                       throws PortalException
        Build a list, separating terms with the locale-defined separator. For example, in English, an input of items X, Y, Z would return "X, Y and Z".
        Parameters:
        listItems -
        Returns:
        Throws:
        PortalException