|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.iastate.utils.string.StringUtils
Utility class to peform common String manipulation algorithms.
| Field Summary | |
private static char[] |
AMP_ENCODE
|
private static java.lang.String |
cvt
|
private static java.security.MessageDigest |
digest
Used by the hash method. |
private static int |
DIGIT
|
private static int |
EOI
|
private static int |
fillchar
|
private static char[] |
GT_ENCODE
|
(package private) static java.lang.String |
HEX_DIGITS
|
private static int |
LOWER
|
private static char[] |
LT_ENCODE
|
private static char[] |
numbersAndLetters
Array of numbers and letters of mixed case. |
private static int |
OTHER
|
private static char[] |
QUOTE_ENCODE
|
private static java.util.Random |
randGen
Pseudo-random number generator object for use with randomString(). |
private static int |
UPPER
|
private static char[] |
zeroArray
|
| Constructor Summary | |
StringUtils()
|
|
| Method Summary | |
static java.lang.String |
beautifyString(java.lang.String s)
Adds spaces in suitable locations of the input string. |
static java.lang.String |
chopAtWord(java.lang.String string,
int length)
Intelligently chops a String at a word boundary (whitespace) that occurs at the specified index in the argument or before. |
static java.lang.String |
dateToMillis(java.util.Date date)
Formats a Date as a fifteen character long String made up of the Date's padded millisecond value. |
static java.lang.String |
decodeBase64(byte[] data)
Decodes a base64 aray of bytes. |
static java.lang.String |
decodeBase64(java.lang.String data)
Decodes a base64 String. |
static byte[] |
decodeHex(java.lang.String hex)
Turns a hex encoded string into a byte array. |
static java.lang.String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String. |
static java.lang.String |
encodeBase64(java.lang.String data)
Encodes a String as a base64 String. |
static java.lang.String |
encodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an unsigned hex number. |
static java.lang.String |
escapeForXML(java.lang.String string)
Escapes all necessary characters in the String so that it can be used in an XML doc. |
static java.lang.String |
escapeHTML(java.lang.String htmlContents)
Substitutes most common HTML reserved characters with their escaped version. |
static java.lang.String |
escapeHTMLTags(java.lang.String in)
This method takes a string which may contain HTML tags (ie, <b>, <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences. |
static boolean |
getBooleanProperty(java.util.Properties props,
java.lang.String key,
boolean defval)
Gets a boolean property from a standard Properties list. |
private static int |
getCharKind(int c)
|
static java.lang.String |
hash(java.lang.String data)
Hashes a String using the Md5 algorithm and returns the result as a String of hexadecimal numbers. |
private static byte |
hexCharToByte(char ch)
Returns the the byte value of a hexadecmical char (0-f). |
static boolean |
isPositive(java.lang.String val)
Returns true, if the string "val" denotes a positive string. |
static boolean |
isStringEmpty(java.lang.String str)
|
static java.lang.String |
normalizePostData(java.lang.String postData)
Makes sure that the POSTed data is conforms to certain rules. |
static int |
parseIntParameter(java.lang.String value,
int defvalue)
Parses an integer parameter, returning a default value if the value is null or a non-number. |
static java.lang.String |
quote(java.lang.String literal)
Puts a quote before and after given string. |
static java.lang.String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case) of the specified length. |
static java.lang.String |
removeDuplicate(java.lang.String original,
char lookfor)
Removes all duplicates of specified char in given text. |
static java.lang.String |
replace(java.lang.CharSequence htmlContent,
java.lang.String tagToBeReplaced,
java.lang.String replacingTag)
Replaces a sequence with another inside a text content. |
static java.lang.String |
replace(java.lang.String line,
java.lang.String oldString,
java.lang.String newString)
Replaces all instances of oldString with newString in line. |
static java.lang.String |
replace(java.lang.String line,
java.lang.String oldString,
java.lang.String newString,
int[] count)
Replaces all instances of oldString with newString in line. |
static java.lang.String |
replaceEntities(java.lang.String src)
Replaces the relevant entities inside the String. |
static java.lang.String |
replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.String newString)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. |
static java.lang.String |
replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.String newString,
int[] count)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. |
static java.lang.String |
replaceString(java.lang.String orig,
int start,
int end,
java.lang.String text)
Replaces a part of a string with a new String. |
static java.lang.String |
replaceString(java.lang.String orig,
java.lang.String src,
java.lang.String dest)
Replaces a string with an other string. |
static java.lang.String[] |
toLowerCaseWordArray(java.lang.String text)
Converts a line of text into an array of lower case words using a BreakIterator.wordInstance(). |
static java.lang.String |
unescapeFromXML(java.lang.String string)
Unescapes the String by converting XML escape sequences back into normal characters. |
static java.lang.String |
unescapeHTML(java.lang.String htmlContents)
Substitutes most common HTML escape sequences with their unescaped version. |
static java.lang.String |
unquote(java.lang.String literal)
Removes all quotes at the beginning and ending of given string. |
protected static java.lang.String |
urlDecode(byte[] bytes)
URL encoder does not handle all characters correctly. |
static java.lang.String |
urlDecode(java.lang.String data,
java.lang.String encoding)
Provides decoded version of string depending on encoding. |
static java.lang.String |
urlDecodeUTF8(java.lang.String utf8)
As java.net.URLDecoder class, but for UTF-8 strings. |
protected static java.lang.String |
urlEncode(byte[] rs)
java.net.URLEncoder.encode() method in JDK < 1.4 is buggy. |
static java.lang.String |
urlEncode(java.lang.String data,
java.lang.String encoding)
Provides encoded version of string depending on encoding. |
static java.lang.String |
urlEncodeUTF8(java.lang.String text)
As java.net.URLEncoder class, but this does it in UTF8 character set. |
static java.lang.String |
wordWrap(java.lang.String input,
int width,
java.util.Locale locale)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner. |
static java.lang.String |
zeroPadString(java.lang.String string,
int length)
Pads the supplied String with 0's to the specified length and returns the result as a new String. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final char[] QUOTE_ENCODE
private static final char[] AMP_ENCODE
private static final char[] LT_ENCODE
private static final char[] GT_ENCODE
private static java.security.MessageDigest digest
private static final int fillchar
private static final java.lang.String cvt
private static java.util.Random randGen
private static char[] numbersAndLetters
private static final char[] zeroArray
static final java.lang.String HEX_DIGITS
private static final int EOI
private static final int LOWER
private static final int UPPER
private static final int DIGIT
private static final int OTHER
| Constructor Detail |
public StringUtils()
| Method Detail |
public static final java.lang.String replace(java.lang.String line,
java.lang.String oldString,
java.lang.String newString)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldString
public static final java.lang.String replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.String newString)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldString
public static final java.lang.String replaceIgnoreCase(java.lang.String line,
java.lang.String oldString,
java.lang.String newString,
int[] count)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldStringcount - a value that will be updated with the number of replaces
performed.
public static final java.lang.String replace(java.lang.String line,
java.lang.String oldString,
java.lang.String newString,
int[] count)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldString
public static java.lang.String escapeHTML(java.lang.String htmlContents)
public static final java.lang.String escapeHTMLTags(java.lang.String in)
in - the text to be converted.
public static final java.lang.String hash(java.lang.String data)
A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.
In Jive, every time a user logs in, we simply take their plain text password, compute the hash, and compare the generated hash to the stored hash. Since it is almost impossible that two passwords will generate the same hash, we know if the user gave us the correct password or not. The only negative to this system is that password recovery is basically impossible. Therefore, a reset password method is used instead.
data - the String to compute the hash of.
public static final java.lang.String encodeHex(byte[] bytes)
Method by Santeri Paavolainen, Helsinki Finland 1996
(c) Santeri Paavolainen, Helsinki Finland 1996
Distributed under LGPL.
bytes - an array of bytes to convert to a hex-string
public static final byte[] decodeHex(java.lang.String hex)
hex - a hex encoded String to transform into a byte array.
private static final byte hexCharToByte(char ch)
ch - a hexedicmal character (0-f)
public static java.lang.String encodeBase64(java.lang.String data)
data - a String to encode.
public static java.lang.String encodeBase64(byte[] data)
data - a byte array to encode.
public static java.lang.String decodeBase64(java.lang.String data)
data - a base64 encoded String to decode.
public static java.lang.String decodeBase64(byte[] data)
data - a base64 encode byte array to decode.
public static final java.lang.String[] toLowerCaseWordArray(java.lang.String text)
This method is under the Jive Open Source Software License and was written by Mark Imbriaco.
text - a String of text to convert into an array of words
public static final java.lang.String randomString(int length)
The specified length must be at least one. If not, the method will return null.
length - the desired length of the random String to return.
public static final java.lang.String chopAtWord(java.lang.String string,
int length)
length, the String will be chopped
there. If no newline or whitespace is found in string up to
the index length, the String will chopped at length.
For example, chopAtWord("This is a nice String", 10) will return "This is a" which is the first word boundary less than or equal to 10 characters into the original String.
string - the String to chop.length - the index in string to start looking for a
whitespace boundary at.
string whose length is less than or
equal to length, and that is chopped at whitespace.
public static java.lang.String wordWrap(java.lang.String input,
int width,
java.util.Locale locale)
Please note that this method can be lossy - trailing spaces on wrapped lines may be trimmed.
input - the String to reformat.width - the maximum length of any one line.
public static final java.lang.String escapeForXML(java.lang.String string)
string - the string to escape.
public static final java.lang.String unescapeFromXML(java.lang.String string)
string - the string to unescape.
public static final java.lang.String zeroPadString(java.lang.String string,
int length)
string - the original String to pad.length - the desired length of the new padded String.
public static final java.lang.String dateToMillis(java.util.Date date)
protected static java.lang.String urlEncode(byte[] rs)
protected static java.lang.String urlDecode(byte[] bytes)
throws java.io.UnsupportedEncodingException,
java.lang.IllegalArgumentException
Thanks to CJB for this fix.
java.io.UnsupportedEncodingException
java.lang.IllegalArgumentExceptionpublic static java.lang.String urlEncodeUTF8(java.lang.String text)
public static java.lang.String urlDecodeUTF8(java.lang.String utf8)
public static java.lang.String urlEncode(java.lang.String data,
java.lang.String encoding)
This implementation is the same as in FileSystemProvider.mangleName().
public static java.lang.String urlDecode(java.lang.String data,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException,
java.lang.IllegalArgumentException
This implementation is the same as in FileSystemProvider.unmangleName().
java.io.UnsupportedEncodingException
java.lang.IllegalArgumentExceptionpublic static java.lang.String replaceEntities(java.lang.String src)
public static java.lang.String replaceString(java.lang.String orig,
java.lang.String src,
java.lang.String dest)
orig - Original string. Null is safe.src - The string to find.dest - The string to replace src with.
public static java.lang.String replaceString(java.lang.String orig,
int start,
int end,
java.lang.String text)
start - Where in the original string the replacing should start.end - Where the replacing should end.orig - Original string. Null is safe.text - The new text to insert into the string.
public static int parseIntParameter(java.lang.String value,
int defvalue)
public static boolean getBooleanProperty(java.util.Properties props,
java.lang.String key,
boolean defval)
The possible values for the property are "true"/"false", "yes"/"no", or "on"/"off". Any value not recognized is always defined as "false".
props - A list of properties to search.key - The property key.defval - The default value to return.
public static boolean isPositive(java.lang.String val)
val - Value to check.
public static java.lang.String normalizePostData(java.lang.String postData)
private static int getCharKind(int c)
public static java.lang.String beautifyString(java.lang.String s)
s - String to be beautified.
public static boolean isStringEmpty(java.lang.String str)
str -
public static java.lang.String removeDuplicate(java.lang.String original,
char lookfor)
lookfor - the char to remove duplicates.
public static java.lang.String unquote(java.lang.String literal)
public static java.lang.String unescapeHTML(java.lang.String htmlContents)
public static java.lang.String quote(java.lang.String literal)
public static java.lang.String replace(java.lang.CharSequence htmlContent,
java.lang.String tagToBeReplaced,
java.lang.String replacingTag)
htmlContent - the text content to update.tagToBeReplaced - the undesired occurrence.replacingTag - the desired one.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||