| java.lang.Object org.nemesis.forum.util.StringUtils
StringUtils | public class StringUtils (Code) | | Utility class to peform common String manipulation algorithms.
|
Field Summary | |
protected static Log | log |
Method Summary | |
final public static String | chopAtWord(String string, int length) Intelligently chops a String at a word boundary (whitespace) that occurs
at the specified index in the argument or before. | final public static String | escapeForXML(String string) Escapes all necessary characters in the String so that it can be used
in an XML doc.
Parameters: string - the string to escape. | final public static String | escapeHTMLTags(String input) This method takes a string which may contain HTML tags (ie, <b>,
<table>, etc) and converts the '<'' and '>' characters to
their HTML escape sequences.
Parameters: input - the text to be converted. | final public static synchronized String | hash(String data) Hashes a String using the Md5 algorithm and returns the result as a
String of hexadecimal numbers. | final public static String | highlightWords(String string, String[] words, String startHighlight, String endHighlight) Highlights words in a string. | final public static String | randomString(int length) Returns a random String of numbers and letters of the specified length.
The method uses the Random class that is built-in to Java which is
suitable for low to medium grade security uses. | final public static String[] | removeCommonWords(String[] words) Returns a new String array with some of the most common English words
removed. | final public static String | replace(String line, String oldString, String newString) Replaces all instances of oldString with newString in line. | final public static String | replace(String line, String oldString, String newString, int[] count) Replaces all instances of oldString with newString in line. | final public static String | replaceIgnoreCase(String line, String oldString, String newString) Replaces all instances of oldString with newString in line with the
added feature that matches of newString in oldString ignore case. | final public static String | toHex(byte hash) Turns an array of bytes into a String representing each byte as an
unsigned hex number. | final public static String[] | toLowerCaseWordArray(String text) Converts a line of text into an array of lower case words. |
log | protected static Log log(Code) | | |
chopAtWord | final public static String chopAtWord(String string, int length)(Code) | | Intelligently chops a String at a word boundary (whitespace) that occurs
at the specified index in the argument or before. However, if there is a
newline character before 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.
Parameters: string - the String to chop. Parameters: length - the index in string to start looking for awhitespace boundary at. a substring of string whose length is less than orequal to length , and that is chopped at whitespace. |
escapeForXML | final public static String escapeForXML(String string)(Code) | | Escapes all necessary characters in the String so that it can be used
in an XML doc.
Parameters: string - the string to escape. the string with appropriate characters escaped. |
escapeHTMLTags | final public static String escapeHTMLTags(String input)(Code) | | This method takes a string which may contain HTML tags (ie, <b>,
<table>, etc) and converts the '<'' and '>' characters to
their HTML escape sequences.
Parameters: input - the text to be converted. the input string with the characters '<' and '>' replacedwith their HTML escape sequences. |
hash | final public static synchronized String hash(String data)(Code) | | Hashes a String using the Md5 algorithm and returns the result as a
String of hexadecimal numbers. This method is synchronized to avoid
excessive MessageDigest object creation. If calling this method becomes
a bottleneck in your code, you may wish to maintain a pool of
MessageDigest objects instead of using this method.
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.
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.
Parameters: data - the String to compute the hash of. a hashed version of the passed-in String |
highlightWords | final public static String highlightWords(String string, String[] words, String startHighlight, String endHighlight)(Code) | | Highlights words in a string. Words matching ignores case. The actual
higlighting method is specified with the start and end higlight tags.
Those might be beginning and ending HTML bold tags, or anything else.
Parameters: string - the String to highlight words in. Parameters: words - an array of words that should be highlighted in the string. Parameters: startHighlight - the tag that should be inserted to start highlighting. Parameters: endHighlight - the tag that should be inserted to end highlighting. a new String with the specified words highlighted. |
randomString | final public static String randomString(int length)(Code) | | Returns a random String of numbers and letters of the specified length.
The method uses the Random class that is built-in to Java which is
suitable for low to medium grade security uses. This means that the
output is only pseudo random, i.e., each number is mathematically
generated so is not truly random.
For every character in the returned String, there is an equal chance that
it will be a letter or number. If a letter, there is an equal chance
that it will be lower or upper case.
The specified length must be at least one. If not, the method will return
null.
Parameters: length - the desired length of the random String to return. a random String of numbers and letters of the specified length. |
removeCommonWords | final public static String[] removeCommonWords(String[] words)(Code) | | Returns a new String array with some of the most common English words
removed. The specific words removed are: a, and, as, at, be, do, i, if,
in, is, it, so, the, to
|
replace | final public static String replace(String line, String oldString, String newString)(Code) | | Replaces all instances of oldString with newString in line.
Parameters: line - the String to search to perform replacements on Parameters: oldString - the String that should be replaced by newString Parameters: newString - the String that will replace all instances of oldString a String will all instances of oldString replaced by newString |
replace | final public static String replace(String line, String oldString, String newString, int[] count)(Code) | | Replaces all instances of oldString with newString in line.
The count Integer is updated with number of replaces.
Parameters: line - the String to search to perform replacements on Parameters: oldString - the String that should be replaced by newString Parameters: newString - the String that will replace all instances of oldString a String will all instances of oldString replaced by newString |
replaceIgnoreCase | final public static String replaceIgnoreCase(String line, String oldString, String newString)(Code) | | Replaces all instances of oldString with newString in line with the
added feature that matches of newString in oldString ignore case.
Parameters: line - the String to search to perform replacements on Parameters: oldString - the String that should be replaced by newString Parameters: newString - the String that will replace all instances of oldString a String will all instances of oldString replaced by newString |
toHex | final public static String toHex(byte hash)(Code) | | Turns an array of bytes into a String representing each byte as an
unsigned hex number.
Method by Santeri Paavolainen, Helsinki Finland 1996
(c) Santeri Paavolainen, Helsinki Finland 1996
Distributed under LGPL.
Parameters: hash - an rray of bytes to convert to a hex-string generated hex string |
toLowerCaseWordArray | final public static String[] toLowerCaseWordArray(String text)(Code) | | Converts a line of text into an array of lower case words. Words are
delimited by the following characters: , .\r\n:/\+
In the future, this method should be changed to use a
BreakIterator.wordInstance(). That class offers much more fexibility.
Parameters: text - a String of text to convert into an array of words text broken up into an array of words. |
|
|