lumis.util
Class TextUtil

Package class diagram package TextUtil
java.lang.Object
  extended by lumis.util.TextUtil

@StableMinor(version="6.2",
             sinceVersion="4.0")
public class TextUtil
extends Object

Utility methods for text-related operations.

Since:
4.0.0

Constructor Summary
TextUtil()
           
 
Method Summary
static void copyFile(String sourceFile, String targetFile)
           
static String escapeJs(String javascriptString)
          Escapes a javascript string so it can added to inside quotes without breaking the javascript code.
static String escapeLocalizationParameter(String str)
          Escapes a localization parameter string.
static String escapeRegexpReplacement(String replacementString)
          Escapes regexp replacement commands in a string for use as replacement.
static FileWriter getFileWriter(String filename, boolean append)
          Deprecated. Since 4.0.9 because this method uses the system default charset encoding.
static int indexOfCaseInsensitive(StringBuilder source, String findStr)
           
static int indexOfCaseInsensitive(StringBuilder source, String findStr, int fromIndex)
           
static String joinStringArray(String[] array, String delim)
           
static StringBuffer joinStringArray(String[] array, String delim, StringBuffer sb)
           
static String joinStringCollection(Collection<String> strings, String delim)
          Generates a string joining the strings in the collection with the delimiter specified between them.
static String joinStringCollectionUserFriendly(List<String> listItems)
          Build a list, separating terms with the locale-defined separator.
static String leftPad(String s, int minimumLength, char fillingChar)
           
static String read(InputStream in, String encoding)
          Reads an input stream as a string using the given encoding.
static String read(Reader reader)
          Reads the data from the reader until its end is reached.
static String read(URL url, String encoding)
          Reads the InputStream provided by the given URL as a string.
static String readFile(String filename)
          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 use readFile(String, String) specifying the correct encoding.
static String readFile(String filename, String encoding)
           
static String stringRepeat(char ch, int count)
          Generate a string repeating the 'ch' character 'count' times.
static String stringReplace(String str, String target, String replacement)
           
static String stringReplace(String str, String target, String replacement, boolean replaceOnlyFirstOccurrence)
           
static void writeFile(String filename, String content, boolean append)
          Deprecated. Since 4.0.8, use writeFile(String, String, String, boolean) because this method uses the system default charset encoding.
static void writeFile(String filename, String content, String charset, boolean append)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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)

joinStringArray

public static StringBuffer joinStringArray(String[] array,
                                           String delim,
                                           StringBuffer sb)

readFile

@Deprecated
public static String readFile(String filename)
                       throws FileNotFoundException,
                              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 use readFile(String, String) specifying the correct encoding.

Reads the text from a file.

Parameters:
filename - the filename.
Returns:
the file content.
Throws:
FileNotFoundException
IOException
Since:
4.0.0

readFile

public static String readFile(String filename,
                              String encoding)
                       throws FileNotFoundException,
                              IOException
Throws:
FileNotFoundException
IOException

read

public static String read(URL url,
                          String encoding)
                   throws IOException
Reads the InputStream provided by the given URL as a string.

Parameters:
url - the URL.
encoding - the encoding to use for reading.
Returns:
the read content as a string.
Throws:
IOException - if an I/O exception occurs.
Since:
6.0.0
See Also:
URL.openStream(), read(InputStream, String)

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

writeFile

@Deprecated
public static void writeFile(String filename,
                                        String content,
                                        boolean append)
                      throws IOException
Deprecated. Since 4.0.8, use writeFile(String, String, String, boolean) because this method uses the system default charset encoding.

Throws:
IOException

writeFile

public static void writeFile(String filename,
                             String content,
                             String charset,
                             boolean append)
                      throws IOException,
                             PortalException
Throws:
IOException
PortalException

copyFile

public static void copyFile(String sourceFile,
                            String targetFile)
                     throws IOException
Throws:
IOException

getFileWriter

@Deprecated
public static FileWriter getFileWriter(String filename,
                                                  boolean append)
                                throws IOException
Deprecated. Since 4.0.9 because this method uses the system default charset encoding.

Throws:
IOException

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


Lumisportal  6.2.0.120405 - Copyright © 2006–2012 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.