|
Copyright © 2006 BEA Systems, Inc. All Rights Reserved | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.compoze.collab.util.StringUtility
public class StringUtility
This class contains useful methods for working with strings.
| Method Summary | |
|---|---|
static String |
bytesToHex(byte[] bytes)
Gets a byte array as a string in hexadecimal with the characters returned in uppercase. |
static String |
bytesToHex(byte[] bytes,
boolean bUppercase)
Gets a byte array as a string in hexadecimal with the characters returned in uppercase. |
static String |
bytesToHex(byte[] bytes,
int iOffset,
int iLength,
boolean bUppercase,
boolean bFormatted)
Gets a byte array as a string in hexadecimal. |
static String |
byteToHex(byte data)
Convenience method to convert a byte to a hex string. |
static String |
byteToHex(byte data,
boolean bUpperCase)
Convenience method to convert a byte to a hex string. |
static int |
compareVersions(int[] version1,
int[] version2)
Compare two version arrays as Comparator.compare(java.lang.Object, java.lang.Object). |
static int[] |
crackVersionString(String sVersion)
Crack a version number String like "3.12-4" into an array of ints {3,12,4}. |
static boolean |
equalsWithNull(String s1,
String s2)
Determines if two strings are equal (either string may be null). |
static String |
escapeAndProcessLinks(String sUnprocessed)
HTML escapes a string and process its links for use in a JSP page. |
static String |
escapeAndProcessLinks(String sUnprocessed,
boolean bNewWindow)
HTML escapes a string and process its links for use in a JSP page. |
static String |
escapeQuotes(String sUnescapedString)
This replaces the special quote characters with escaped value |
static String[] |
getArrayFromSeparatedList(String sStr,
String sDelim,
boolean bTrim)
Gets a String array from a separated list of Strings. |
static String |
getCommaSeparatedList(Collection strs,
boolean bSpaceAfterComma)
Gets a comma separated list from a collection of strings or objects (for an object we call the toString method). |
static void |
getCommaSeparatedList(Collection strs,
boolean bSpaceAfterComma,
StringBuffer buf)
Gets a comma separated list from a collection of strings or objects (for an object we call the toString method). |
static void |
getCommaSeparatedList(long[] longs,
boolean bSpaceAfterComma,
StringBuffer buf)
Gets a comma separated list from an array of longs. |
static String |
getCommaSeparatedList(Object[] strs,
boolean bSpaceAfterComma)
Gets a comma separated list from a collection of strings or objects (for an object we call the toString method). |
static void |
getCommaSeparatedList(Object[] strs,
boolean bSpaceAfterComma,
StringBuffer buf)
Gets a comma separated list from an array of strings or objects (for an object we call the toString method). |
static byte[] |
getDigest(String sStr)
Get an SHA digest of the specified string using the UTF-8 character encoding. |
static byte[] |
getDigest(String sStr,
String sAlgorithm)
Get a digest of the specified string using the UTF-8 character encoding. |
static byte[] |
getDigest(String sStr,
String sAlgorithm,
String sEncoding)
Get a digest of the specified string. |
static String |
getExceptionStackTrace(Throwable t)
Gets the stack trace of a Throwable as a String. |
static List |
getListFromSeparatedList(String sStr,
String sDelim,
boolean bTrim)
Gets a list of Strings from a separated list of Strings. |
static void |
getSeparatedList(Collection strs,
String sSeparator,
StringBuffer buf)
Gets a separated list from a collection of strings or objects (for an object we call the toString method). |
static void |
getSeparatedList(long[] longs,
String sSeparator,
StringBuffer buf)
Gets a separated list from an array of longs. |
static void |
getSeparatedList(Object[] strs,
String sSeparator,
StringBuffer buf)
Gets a separated list from an array of strings or objects (for an object we call the toString method). |
static byte |
hexToByte(String s)
Convenience method to convert a hex string to a byte. |
static byte[] |
hexToBytes(String sHex)
Convenience method to convert a hex string to a byte array. |
static String |
htmlEscape(String sUnescapedString)
HTML escape a string. |
static String |
htmlEscape(String sUnescapedString,
String sEncoding)
HTML escape a string. |
static String |
htmlEscapeUnformatted(String sUnescapedString)
Parially HMTL escapes a string for use in a JSP page. |
static String |
htmlEscapeUnformatted(String sUnescapedString,
String[] sTags)
Partially HTML escapes a string for use in a JSP page. |
static String |
indent(String s,
int iColumns)
Indents a String by the specified number of columns. |
static boolean |
isBlank(String sStr)
Determine if a string is null or empty. |
static void |
main(String[] args)
Main. |
static String |
prettyTruncate(String sStr,
int iLength)
Truncate a string after a certain number of characters and append the specified string to it. |
static String |
prettyTruncate(String sStr,
String sPostfix,
int iLength)
Truncate a string after a certain number of characters and append the specified string to it. |
static void |
printColumns(String[][] strs,
int iPadding,
PrintStream out)
Prints strings in columns. |
static String |
processLinks(String sUnprocessed)
Processes a string, replacing any apparent URLs with the HTML code needed to generate an HREF link to that URL. |
static String |
processLinks(String sUnprocessed,
boolean bNewWindow)
Processes a string, replacing any apparent URLs with the HTML code needed to generate an HREF link to that URL. |
static String |
safeHtmlEscape(Object obj)
HTML escapes a object for use in a JSP page. |
static String |
safeHtmlEscape(String sUnescapedString)
HTML escapes a string for use in a JSP page. |
static String |
safeHtmlEscape(String sUnescapedString,
String sEncoding)
HTML escapes a string for use in a JSP page. |
static String |
substituteAll(String sSource,
String sToBeReplaced,
String sReplacement)
Substitutes all occurrences of a string. |
static char |
toHexChar(int i)
Convenience method to convert an int to a hex char. |
static String |
trimChar(String str,
char c)
Trim the given character from either end of a String. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String safeHtmlEscape(Object obj)
obj - object to escape (may not be wnull)
public static String safeHtmlEscape(String sUnescapedString)
sUnescapedString - string to escape
public static String safeHtmlEscape(String sUnescapedString,
String sEncoding)
throws UnsupportedEncodingException
sUnescapedString - string to escapesEncoding - character encoding
UnsupportedEncodingExceptionpublic static String htmlEscapeUnformatted(String sUnescapedString)
<br><i><b><u><font>
<ol><ul><li><pre><code>.
sUnescapedString - the unescaped string
public static String htmlEscapeUnformatted(String sUnescapedString,
String[] sTags)
sUnescapedString - the unescaped stringsTags - the tags that are not to be escaped, as their localized name.
For example new String[] { "b", "i", "font" }
public static String processLinks(String sUnprocessed,
boolean bNewWindow)
sUnprocessed - the unprocessed stringbNewWindow - if true, link should open new browser window
public static String processLinks(String sUnprocessed)
sUnprocessed - the unprocessed string
public static String escapeAndProcessLinks(String sUnprocessed)
sUnprocessed - the unprocessed string
htmlEscape(String),
processLinks(String)
public static String escapeAndProcessLinks(String sUnprocessed,
boolean bNewWindow)
sUnprocessed - the unprocessed stringbNewWindow - if true, link should open new browser window
htmlEscape(String),
processLinks(String)
public static byte[] getDigest(String sStr,
String sAlgorithm,
String sEncoding)
throws NoSuchAlgorithmException,
UnsupportedEncodingException
sStr - the string to digestsAlgorithm - use the specified MessageDigest algorithmsEncoding - use the specified character encoding
NoSuchAlgorithmException - if the specified algorithm could not be found
UnsupportedEncodingException - if the specified character encoding
is not supported
public static byte[] getDigest(String sStr)
throws NoSuchAlgorithmException,
UnsupportedEncodingException
sStr - the string to digest
NoSuchAlgorithmException - if the specified algorithm could not be found
UnsupportedEncodingException - if the specified character encoding
is not supported
public static byte[] getDigest(String sStr,
String sAlgorithm)
throws NoSuchAlgorithmException,
UnsupportedEncodingException
sStr - the string to digestsAlgorithm - use the specified MessageDigest algorithm
NoSuchAlgorithmException - if the specified algorithm could not be found
UnsupportedEncodingException - if the specified character encoding
is not supportedpublic static String byteToHex(byte data)
data - the byte to convert
public static String byteToHex(byte data,
boolean bUpperCase)
data - the byte to convert
public static String bytesToHex(byte[] bytes)
bytes - the byte array
public static String bytesToHex(byte[] bytes,
boolean bUppercase)
bytes - the byte arraybUppercase - if true,
public static String bytesToHex(byte[] bytes,
int iOffset,
int iLength,
boolean bUppercase,
boolean bFormatted)
bytes - the byte arrayiOffset - the offset in the byte array to startiLength - the number of bytes to convertbUppercase - if true, characters are returned
in uppercasebFormatted - if true, format hexadecimal in
a multiline easily readable way
public static void getCommaSeparatedList(Collection strs,
boolean bSpaceAfterComma,
StringBuffer buf)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)bSpaceAfterComma - if true, include a space after
each comma that separates the elements in the listbuf - the buffer to write to
public static void getSeparatedList(Collection strs,
String sSeparator,
StringBuffer buf)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)sSeparator - the String to use to separate the elementsbuf - the buffer to write to
public static String getCommaSeparatedList(Collection strs,
boolean bSpaceAfterComma)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)bSpaceAfterComma - if true, include a space after
each comma that separates the elements in the list
public static void getCommaSeparatedList(Object[] strs,
boolean bSpaceAfterComma,
StringBuffer buf)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)bSpaceAfterComma - if true, include a space after
each comma that separates the elements in the listbuf - the buffer to write to
public static void getCommaSeparatedList(long[] longs,
boolean bSpaceAfterComma,
StringBuffer buf)
longs - the longsbSpaceAfterComma - if true, include a space after
each comma that separates the elements in the listbuf - the buffer to write to
public static void getSeparatedList(Object[] strs,
String sSeparator,
StringBuffer buf)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)sSeparator - the separator between list objectsbuf - the buffer to write to
public static void getSeparatedList(long[] longs,
String sSeparator,
StringBuffer buf)
longs - the strings or objects (not null)sSeparator - the separator between list objectsbuf - the buffer to write to
public static String getCommaSeparatedList(Object[] strs,
boolean bSpaceAfterComma)
toString method). Null objects are
represented by the empty string.
strs - the strings or objects (not null)bSpaceAfterComma - if true, include a space after
each comma that separates the elements in the list
public static String getExceptionStackTrace(Throwable t)
Throwable as a String.
t - the throwable
public static boolean isBlank(String sStr)
sStr - the string to evaluate
public static byte[] hexToBytes(String sHex)
data - the byte[] to convert
public static byte hexToByte(String s)
s - the string to convert
public static char toHexChar(int i)
i - the int to convert
public static int[] crackVersionString(String sVersion)
throws NumberFormatException
sVersion - the version number String
NumberFormatException - if sVersion isn't of the form #(-#)*-? where
'#' represents a number and '-' represents a
delimiter
public static int compareVersions(int[] version1,
int[] version2)
Comparator.compare(java.lang.Object, java.lang.Object).
If the arrays are different lengths with one a prefix of the other, the
longer array will be considered greater.
version1 - the first version arrayversion2 - the second version array
public static boolean equalsWithNull(String s1,
String s2)
s1 - the first string (may be null)s2 - the second string (may be null)
true if the strings are equal or both are
null
public static String htmlEscape(String sUnescapedString,
String sEncoding)
throws UnsupportedEncodingException
sUnescapedString - the unescaped stringsEncoding - the character encoding
UnsupportedEncodingExceptionpublic static String htmlEscape(String sUnescapedString)
sUnescapedString - the unescaped string
public static String escapeQuotes(String sUnescapedString)
sUnescapedString - the unescaped string
public static String trimChar(String str,
char c)
str - the string to trimc - the character to trim from either end
public static final String substituteAll(String sSource,
String sToBeReplaced,
String sReplacement)
sSource - the string to do the replacement insToBeReplaced - the string to search forsReplacement - the replacement
public static String prettyTruncate(String sStr,
String sPostfix,
int iLength)
sStr - the original stringsPostfix - the string to put at the end of the original stringiLength - the maximum length of the result (string plus postfix)
public static String prettyTruncate(String sStr,
int iLength)
sStr - the original stringiLength - the maximum length of the result (string plus postfix)
public static String[] getArrayFromSeparatedList(String sStr,
String sDelim,
boolean bTrim)
sStr - the original string (not null)sDelim - the delimiter (not null)bTrim - if true, do a trim()
on each String
null)
public static List getListFromSeparatedList(String sStr,
String sDelim,
boolean bTrim)
sStr - the original string (not null)sDelim - the delimiter (not null)bTrim - if true, do a trim()
on each String
null)
public static void printColumns(String[][] strs,
int iPadding,
PrintStream out)
strs - the strings (first dimension is rows, second
dimension is columns, not null)iWidth - if negative, the number of spaces between columns,
if positive, the actual column width
public static String indent(String s,
int iColumns)
s - the String to indent (not null)iColumns - the number of columns to indent
public static void main(String[] args)
|
Copyright © 2006 BEA Systems, Inc. All Rights Reserved | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||