Package lumis.util
Class TextUtil
- java.lang.Object
-
- lumis.util.TextUtil
-
@StableMinor(version="16.0", sinceVersion="4.0") public class TextUtil extends java.lang.Object
Utility methods for text-related operations.- Since:
- 4.0.0
- Version:
- $Revision: 25808 $ $Date: 2023-07-04 15:20:55 -0300 (Tue, 04 Jul 2023) $
-
-
Constructor Summary
Constructors Constructor Description TextUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
copyFile(java.lang.String sourceFile, java.lang.String targetFile)
static java.lang.String
escapeJs(java.lang.String javascriptString)
Escapes a javascript string so it can added to inside quotes without breaking the javascript code.static java.lang.String
escapeLocalizationParameter(java.lang.String str)
Escapes a localization parameter string.static java.lang.String
escapeRegexpReplacement(java.lang.String replacementString)
Escapes regexp replacement commands in a string for use as replacement.static java.io.FileWriter
getFileWriter(java.lang.String filename, boolean append)
Deprecated.Since 4.0.9 because this method uses the system default charset encoding.static int
indexOfCaseInsensitive(java.lang.StringBuilder source, java.lang.String findStr)
static int
indexOfCaseInsensitive(java.lang.StringBuilder source, java.lang.String findStr, int fromIndex)
static java.lang.String
joinStringArray(java.lang.String[] array, java.lang.String delim)
static java.lang.StringBuffer
joinStringArray(java.lang.String[] array, java.lang.String delim, java.lang.StringBuffer sb)
static java.lang.String
joinStringCollection(java.util.Collection<java.lang.String> strings, java.lang.String delim)
Generates a string joining the strings in the collection with the delimiter specified between them.static java.lang.String
joinStringCollectionUserFriendly(java.util.List<java.lang.String> listItems)
Build a list, separating terms with the locale-defined separator.static java.lang.String
leftPad(java.lang.String s, int minimumLength, char fillingChar)
static java.lang.String
read(java.io.InputStream in, java.lang.String encoding)
Reads an input stream as a string using the given encoding.static java.lang.String
read(java.io.Reader reader)
Reads the data from the reader until its end is reached.static java.lang.String
read(java.net.URL url, java.lang.String encoding)
Reads theInputStream
provided by the givenURL
as a string.static java.lang.String
readFile(java.lang.String filename)
Deprecated.This method uses the system default encoding, which if diferent from the file's encoding may cause data corruption.static java.lang.String
readFile(java.lang.String filename, java.lang.String encoding)
static java.lang.String
stringRepeat(char ch, int count)
Generate a string repeating the 'ch' character 'count' times.static java.lang.String
stringReplace(java.lang.String str, java.lang.String target, java.lang.String replacement)
static java.lang.String
stringReplace(java.lang.String str, java.lang.String target, java.lang.String replacement, boolean replaceOnlyFirstOccurrence)
static void
writeFile(java.lang.String filename, java.lang.String content, boolean append)
Deprecated.Since 4.0.8, usewriteFile(String, String, String, boolean)
because this method uses the system default charset encoding.static void
writeFile(java.lang.String filename, java.lang.String content, java.lang.String charset, boolean append)
-
-
-
Method Detail
-
stringReplace
public static java.lang.String stringReplace(java.lang.String str, java.lang.String target, java.lang.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 java.lang.String stringReplace(java.lang.String str, java.lang.String target, java.lang.String replacement, boolean replaceOnlyFirstOccurrence)
-
escapeRegexpReplacement
public static java.lang.String escapeRegexpReplacement(java.lang.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 java.lang.String escapeJs(java.lang.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 java.lang.String escapeLocalizationParameter(java.lang.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 java.lang.String joinStringCollection(java.util.Collection<java.lang.String> strings, java.lang.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 java.lang.String joinStringArray(java.lang.String[] array, java.lang.String delim)
-
joinStringArray
public static java.lang.StringBuffer joinStringArray(java.lang.String[] array, java.lang.String delim, java.lang.StringBuffer sb)
-
readFile
@Deprecated public static java.lang.String readFile(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
Deprecated.This method uses the system default encoding, which if diferent from the file's encoding may cause data corruption. Instead of using this method usereadFile(String, String)
specifying the correct encoding.Reads the text from a file.- Parameters:
filename
- the filename.- Returns:
- the file content.
- Throws:
java.io.FileNotFoundException
java.io.IOException
- Since:
- 4.0.0
-
readFile
public static java.lang.String readFile(java.lang.String filename, java.lang.String encoding) throws java.io.FileNotFoundException, java.io.IOException
- Throws:
java.io.FileNotFoundException
java.io.IOException
-
read
public static java.lang.String read(java.net.URL url, java.lang.String encoding) throws java.io.IOException
Reads theInputStream
provided by the givenURL
as a string.- Parameters:
url
- the URL.encoding
- the encoding to use for reading.- Returns:
- the read content as a string.
- Throws:
java.io.IOException
- if an I/O exception occurs.- Since:
- 6.0.0
- See Also:
URL.openStream()
,read(InputStream, String)
-
read
public static java.lang.String read(java.io.InputStream in, java.lang.String encoding) throws java.io.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:
java.io.IOException
- if an I/O exception occurs.- Since:
- 6.0.0
-
read
public static java.lang.String read(java.io.Reader reader) throws java.io.IOException
Reads the data from the reader until its end is reached.- Parameters:
reader
- the reader.- Returns:
- the string read.
- Throws:
java.io.IOException
- if an I/O error occurs.- Since:
- 4.0.7
-
writeFile
@Deprecated public static void writeFile(java.lang.String filename, java.lang.String content, boolean append) throws java.io.IOException
Deprecated.Since 4.0.8, usewriteFile(String, String, String, boolean)
because this method uses the system default charset encoding.- Throws:
java.io.IOException
-
writeFile
public static void writeFile(java.lang.String filename, java.lang.String content, java.lang.String charset, boolean append) throws java.io.IOException, PortalException
- Throws:
java.io.IOException
PortalException
-
copyFile
public static void copyFile(java.lang.String sourceFile, java.lang.String targetFile) throws java.io.IOException
- Throws:
java.io.IOException
-
getFileWriter
@Deprecated public static java.io.FileWriter getFileWriter(java.lang.String filename, boolean append) throws java.io.IOException
Deprecated.Since 4.0.9 because this method uses the system default charset encoding.- Throws:
java.io.IOException
-
indexOfCaseInsensitive
public static int indexOfCaseInsensitive(java.lang.StringBuilder source, java.lang.String findStr)
-
indexOfCaseInsensitive
public static int indexOfCaseInsensitive(java.lang.StringBuilder source, java.lang.String findStr, int fromIndex)
-
leftPad
public static java.lang.String leftPad(java.lang.String s, int minimumLength, char fillingChar)
-
stringRepeat
public static java.lang.String stringRepeat(char ch, int count)
Generate a string repeating the 'ch' character 'count' times.- Parameters:
ch
- The character to be repeatedcount
- The number of repetitions- Returns:
-
joinStringCollectionUserFriendly
public static java.lang.String joinStringCollectionUserFriendly(java.util.List<java.lang.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
-
-