com.opensymphony.xwork2.util
Class TextUtils

java.lang.Object
  extended by com.opensymphony.xwork2.util.TextUtils

public class TextUtils
extends Object

Utilities for common String manipulations. This is a class contains static methods only and is not meant to be instantiated. It was brought in from oscore trunk revision 147, and trimmed to only contain methods used by XWork.

Version:
$Revision: 147 $
Author:
Joe Walnes, Patrick Kan, Mike Cannon-Brookes, Hani Suleiman, Joseph B. Ottinger, Scott Farquhar

Constructor Summary
TextUtils()
           
 
Method Summary
static String htmlEncode(String s)
           
static String htmlEncode(String s, boolean encodeSpecialChars)
          Escape html entity characters and high characters (eg "curvy" Word quotes).
static String join(String glue, Collection pieces)
          Join a Collection of Strings together.
static String join(String glue, Iterator pieces)
          Join an Iteration of Strings together.
static String join(String glue, String[] pieces)
          Join an array of Strings together.
static String noNull(String string)
          Return string, or "" if string is null.
static String noNull(String string, String defaultString)
          Return string, or defaultString if string is null or "".
static boolean stringSet(String string)
          Check whether string has been set to something other than "" or null.
static boolean verifyUrl(String url)
          Verify That the given String is in valid URL format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtils

public TextUtils()
Method Detail

htmlEncode

public static final String htmlEncode(String s)

htmlEncode

public static final String htmlEncode(String s,
                                      boolean encodeSpecialChars)
Escape html entity characters and high characters (eg "curvy" Word quotes). Note this method can also be used to encode XML.

Parameters:
s - the String to escape.
encodeSpecialChars - if true high characters will be encode other wise not.
Returns:
the escaped string

join

public static final String join(String glue,
                                Iterator pieces)
Join an Iteration of Strings together.
Example
   // get Iterator of Strings ("abc","def","123");
   Iterator i = getIterator();
   out.print( TextUtils.join(", ",i) );
   // prints: "abc, def, 123"
 

Parameters:
glue - Token to place between Strings.
pieces - Iteration of Strings to join.
Returns:
String presentation of joined Strings.

join

public static final String join(String glue,
                                String[] pieces)
Join an array of Strings together.

Parameters:
glue - Token to place between Strings.
pieces - Array of Strings to join.
Returns:
String presentation of joined Strings.
See Also:
join(String, java.util.Iterator)

join

public static final String join(String glue,
                                Collection pieces)
Join a Collection of Strings together.

Parameters:
glue - Token to place between Strings.
pieces - Collection of Strings to join.
Returns:
String presentation of joined Strings.
See Also:
join(String, java.util.Iterator)

noNull

public static final String noNull(String string,
                                  String defaultString)
Return string, or defaultString if string is null or "". Never returns null.

Examples:

 // prints "hello"
 String s=null;
 System.out.println(TextUtils.noNull(s,"hello");

 // prints "hello"
 s="";
 System.out.println(TextUtils.noNull(s,"hello");

 // prints "world"
 s="world";
 System.out.println(TextUtils.noNull(s, "hello");
 

Parameters:
string - the String to check.
defaultString - The default string to return if string is null or ""
Returns:
string if string is non-empty, and defaultString otherwise
See Also:
stringSet(java.lang.String)

noNull

public static final String noNull(String string)
Return string, or "" if string is null. Never returns null.

Examples:

 // prints 0
 String s=null;
 System.out.println(TextUtils.noNull(s).length());

 // prints 1
 s="a";
 System.out.println(TextUtils.noNull(s).length());
 

Parameters:
string - the String to check
Returns:
a valid (non-null) string reference

stringSet

public static final boolean stringSet(String string)
Check whether string has been set to something other than "" or null.

Parameters:
string - the String to check
Returns:
a boolean indicating whether the string was non-empty (and non-null)

verifyUrl

public static final boolean verifyUrl(String url)
Verify That the given String is in valid URL format.

Parameters:
url - The url string to verify.
Returns:
a boolean indicating whether the URL seems to be incorrect.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.