org.xins.common.text
Class TextUtils

java.lang.Object
  extended byorg.xins.common.text.TextUtils

public final class TextUtils
extends Object

Text-related utility functions.

Since:
XINS 1.0.0
Version:
$Revision: 1.15 $ $Date: 2006/08/28 09:12:31 $
Author:
Ernst de Haan

Method Summary
static boolean isEmpty(String s)
          Determines if the specified string is null or an empty string.
static String quote(Object o)
          Quotes the textual presentation (returned by toString()) of the specified object, or returns "(null)" if the object is null.
static String quote(String s)
          Quotes the specified string, or returns "(null)" if it is null.
static String replace(String s, Properties replacements, String prefix, String suffix)
          Replaces substrings in a string.
static String trim(String s, String ifEmpty)
          Trims the specified string, or returns an empty string if the argument is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quote

public static String quote(String s)
Quotes the specified string, or returns "(null)" if it is null.

Parameters:
s - the input string, or null.
Returns:
if s != null the quoted string, otherwise the string "(null)".

quote

public static String quote(Object o)
Quotes the textual presentation (returned by toString()) of the specified object, or returns "(null)" if the object is null.

Parameters:
o - the object, or null.
Returns:
if o != null then o.toString() quoted, otherwise the string "(null)".
Since:
XINS 1.0.1

isEmpty

public static boolean isEmpty(String s)
Determines if the specified string is null or an empty string.

Parameters:
s - the string, or null.
Returns:
true if s == null || s.length() < 1.
Since:
XINS 1.0.1

trim

public static String trim(String s,
                          String ifEmpty)
Trims the specified string, or returns an empty string if the argument is null.

Parameters:
s - the string, or null.
ifEmpty - the string to return if s == null || s.trim().length < 1.
Returns:
the trimmed version of the string (see String.trim()) or ifEmpty if s == null or s.trim().length < 1.
Since:
XINS 1.3.0

replace

public static String replace(String s,
                             Properties replacements,
                             String prefix,
                             String suffix)
                      throws IllegalArgumentException
Replaces substrings in a string. The substrings to be replaced are passed in a Properties object. A prefix and a suffix can be specified. These are prepended/appended to each of the search keys.

Example: If you have a string "Hello ${name}" and you would like to replace "${name}" with "John" and you would like to replace ${surname} with "Doe", use the following code:

String s = "Hello ${name}";
Properties replacements = new Properties();
replacements.put("name", "John");
replacements.put("surname", "Doe");

StringUtils.replace(s, replacements, "${", "}");

The result string will be "Hello John".

Parameters:
s - the text string to which replacements should be applied, not null.
replacements - the replacements to apply, not null.
prefix - the optional prefix for the search keys, or null.
suffix - the optional prefix for the search keys, or null.
Returns:
the String with the replacements.
Throws:
IllegalArgumentException - if one of the mandatory arguments is missing.
Since:
XINS 1.4.0.


See http://www.xins.org/.