com.smartgwt.client.util
Class StringUtil

java.lang.Object
  extended by com.smartgwt.client.util.StringUtil

public class StringUtil
extends Object


Constructor Summary
StringUtil()
           
 
Method Summary
static String abbreviate(String str, int maxWidth)
          Abbreviates a String using ellipses.
static String asHTML(String str)
          Convert plain text into into displayable HTML.
static String asHTML(String str, boolean noAutoWrap)
          Convert plain text into into displayable HTML.
static String convertTags(String str, String prefix, String suffix)
          Convert all tag symbols ( < and > ) into displayable HTML by changing them to &lt; and &gt; respectively.
static String makeXMLSafe(String str)
          Escapes special characters in XML values - so called 'unparsed data'
static String unescapeHTML(String str)
          Reverses asHTML(String).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

convertTags

public static String convertTags(String str,
                                 String prefix,
                                 String suffix)
Convert all tag symbols ( < and > ) into displayable HTML by changing them to &lt; and &gt; respectively.

Parameters:
str - the string to convert
prefix - text to tack onto the beginning of result (eg: "<PRE>")
suffix - text to tack onto the end of result (eg: "</PRE>")
Returns:
prefix + converted text + suffix as a single string

asHTML

public static String asHTML(String str)
Convert plain text into into displayable HTML.

This prevents HTML-special characters like < and > from being interpreted as tags, and preserves line breaks and extra spacing.

                        converts                   to
                        --------                   ---------------------------
                          &                                &
                          <                                <
                          >                                >
                          \r,\n,\r\n1space 
  \r,\n,\r\n
\t      2 spaces 1space 

Parameters:
str - the string to convert
Returns:
the plain text into into displayable HTM

asHTML

public static String asHTML(String str,
                            boolean noAutoWrap)
Convert plain text into into displayable HTML.

This prevents HTML-special characters like < and > from being interpreted as tags, and preserves line breaks and extra spacing.

                        converts                   to
                        --------                   ---------------------------
                          &                                &
                          <                                <
                          >                                >
                          \r,\n,\r\n1space 
  \r,\n,\r\n
\t      2 spaces 1space 

Parameters:
str - the string to convert
noAutoWrap -
Returns:
the plain text into into displayable HTM

unescapeHTML

public static String unescapeHTML(String str)
Reverses asHTML(String).

Parameters:
str - the input str
Returns:
unescaped HTML

makeXMLSafe

public static String makeXMLSafe(String str)
Escapes special characters in XML values - so called 'unparsed data'
 " -> "
 ' -> '
 & -> &
 < -> <
 > -> >
 \r -> &x000D;
 

Parameters:
str - the String to escape
Returns:
xml safe String

abbreviate

public static String abbreviate(String str,
                                int maxWidth)
Abbreviates a String using ellipses. StringUtils.abbreviate("abcdefg", 6) = "abc..."

Parameters:
str - the String to abbreviate
maxWidth - maximum length of result String, must be at least 4
Returns:
the abbreviated String
Throws:
IllegalArgumentException - when the width is too small