|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.archiviststoolkit.util.StringHelper
public class StringHelper
Utilities for String formatting, manipulation, and queries. More information about this class is available from ostermiller.org.
20Nov03 Fixed bug in replace method. length = stringLength + (count * (replaceLength - findLength));
Constructor Summary | |
---|---|
StringHelper()
|
Method Summary | |
---|---|
static java.lang.String |
cleanUpWhiteSpace(java.lang.String stringToStrip)
|
static java.lang.String |
concat(java.util.ArrayList array,
java.lang.String seperator)
|
static java.lang.String |
concat(java.lang.String seperator,
java.lang.String... strings)
|
static java.lang.String |
concatenateAllFields(java.lang.String delimiter,
java.lang.String... fields)
|
static java.lang.String |
concatenateFields(java.lang.String delimiter,
java.lang.String... fields)
|
static java.lang.String |
convertPipeToCarriageReturn(java.lang.String toConvert)
|
static java.lang.String |
convertToNmtoken(java.lang.String string)
|
static java.lang.String |
escapeHTML(java.lang.String s)
Replaces characters that may be confused by a HTML parser with their equivalent character entity references. |
static java.lang.String |
escapeJavaLiteral(java.lang.String s)
Replaces characters that are not allowed in a Java style string literal with their escape characters. |
static java.lang.String |
escapeSQL(java.lang.String s)
Replaces characters that may be confused by an SQL parser with their equivalent escape characters. |
static java.lang.String[] |
extractStringAndValueInParenthesis(java.lang.String val)
|
static java.lang.String |
getFileExtension(java.io.File file)
|
static java.lang.String |
getFileExtension(java.lang.String pathName)
|
static java.lang.String |
getFilePathWithoutExtension(java.io.File file)
|
static java.lang.String |
getFilePathWithoutExtension(java.lang.String pathName)
|
static java.lang.String |
getFirstPartofLangString(java.lang.String val,
java.lang.String delim)
|
static java.lang.String |
getSecondPartofLangString(java.lang.String val,
java.lang.String delim)
|
static java.lang.String |
getStackTrace(java.lang.Exception e)
|
static java.lang.String |
getStackTrace(java.lang.Throwable e)
|
static java.lang.String |
handleDecimal(java.lang.String valueD)
Method to return a decimal which only has zeros following the decimal as an integer value |
static java.lang.String |
handleRunningSpaces(java.lang.String val)
|
static java.lang.String |
highlightTerms(java.lang.String s,
java.util.ArrayList searchTermList,
java.lang.String highlightStartTag,
java.lang.String highlightEndTag)
|
static boolean |
isEmpty(java.lang.String val)
|
static boolean |
isNotEmpty(java.lang.String val)
|
static void |
main(java.lang.String[] args)
|
static java.lang.String |
makePrettyName(java.lang.String name)
Handles underscores by replacing them with spaces, and handles camelCase by breaking words apart at the humps; it capitalizes the first word. |
static java.lang.String |
MD5(java.lang.String text)
|
static java.lang.String |
midpad(java.lang.String s,
int length)
Pad the beginning and end of the given String with spaces until the String is of the given length. |
static java.lang.String |
midpad(java.lang.String s,
int length,
char c)
Pad the beginning and end of the given String with the given character until the result is the desired length. |
static void |
parseDate(ArchDescription accession,
java.lang.String dateString)
|
static java.lang.String |
postpad(java.lang.String s,
int length)
Pad the end of the given String with spaces until the String is of the given length. |
static java.lang.String |
postpad(java.lang.String s,
int length,
char c)
Append the given character to the String until the result is the desired length. |
static java.lang.String |
prepad(java.lang.String s,
int length)
Pad the beginning of the given String with spaces until the String is of the given length. |
static java.lang.String |
prepad(java.lang.String s,
int length,
char c)
Pre-pend the given character to the String until the result is the desired length. |
static java.lang.String |
removeInvalidFileNameCharacters(java.lang.String fileName)
|
static java.lang.String |
replace(java.lang.String s,
java.lang.String find,
java.lang.String replace)
Replace occurrences of a substring. |
static void |
simpleParseDate(ArchDescription archDescription,
java.lang.String str,
boolean inclusive)
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delimiter)
Split the given String into tokens. |
static java.lang.String |
tagRemover(java.lang.String str)
This method will remove the tags from a given string. |
static java.lang.String |
trim(java.lang.String s,
java.lang.String c)
Trim any of the characters contained in the second string from the beginning and end of the first. |
static java.lang.String |
trimToLength(java.lang.String stringToTrim,
int maxLength)
|
static java.util.Hashtable |
unpackHash(java.lang.String str)
A hash can be passed as a param using its toString() method; it comes in looking like: {key1=val1, key2=val2, key3=val3} ; this method restores it to a hash copied from tedmaint in ServletUtilities (CM) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringHelper()
Method Detail |
---|
public static java.lang.String convertPipeToCarriageReturn(java.lang.String toConvert)
public static java.lang.String makePrettyName(java.lang.String name)
public static java.lang.String prepad(java.lang.String s, int length)
s
- String to be padded.length
- desired length of result.
java.lang.NullPointerException
- if s is null.public static java.lang.String prepad(java.lang.String s, int length, char c)
s
- String to be padded.length
- desired length of result.c
- padding character.
java.lang.NullPointerException
- if s is null.public static java.lang.String postpad(java.lang.String s, int length)
s
- String to be padded.length
- desired length of result.
java.lang.NullPointerException
- if s is null.public static java.lang.String postpad(java.lang.String s, int length, char c)
s
- String to be padded.length
- desired length of result.c
- padding character.
java.lang.NullPointerException
- if s is null.public static java.lang.String midpad(java.lang.String s, int length)
s
- String to be padded.length
- desired length of result.
java.lang.NullPointerException
- if s is null.public static java.lang.String midpad(java.lang.String s, int length, char c)
s
- String to be padded.length
- desired length of result.c
- padding character.
java.lang.NullPointerException
- if s is null.public static java.lang.String[] split(java.lang.String s, java.lang.String delimiter)
s
- String to be split.delimiter
- String literal on which to split.
java.lang.NullPointerException
- if s is null.public static java.lang.String replace(java.lang.String s, java.lang.String find, java.lang.String replace)
s
- String to be modified.find
- String to find.replace
- String to replace.
java.lang.NullPointerException
- if s is null.public static java.lang.String escapeHTML(java.lang.String s)
Server: What is your name? User: <b>Joe<b> Server: Hello Joe, WelcomeIf the name is put on the page without checking that it doesn't contain HTML code or without sanitizing that HTML code, the user could reformat the page, insert scripts, and control the the content on your web server. This method will replace HTML characters such as > with their HTML entity reference (>) so that the html parser will be sure to interpret them as plain text rather than HTML or script. This method should be used for both data to be displayed in text in the html document, and data put in form elements. For example:
<html><body>This in not a <tag>
in HTML</body></html>
<form><input type="hidden" name="date" value="This data could
be "malicious""></form>
This data could be %22malicious%22
s
- String to be escaped
java.lang.NullPointerException
- if s is null.public static java.lang.String escapeSQL(java.lang.String s)
"SELECT * FROM addresses WHERE name='" + name + "' AND private='N'"
" OR 1=1 OR ''='"
as their name causing the query to be:"SELECT * FROM addresses WHERE name='' OR 1=1 OR ''='' AND private='N'"
"SELECT * FROM addresses WHERE name='" + StringHelper.escapeSQL(name) + "' AND private='N'"
s
- String to be escaped
java.lang.NullPointerException
- if s is null.public static java.lang.String escapeJavaLiteral(java.lang.String s)
s
- String to be escaped
java.lang.NullPointerException
- if s is null.public static java.lang.String trim(java.lang.String s, java.lang.String c)
s
- String to be trimmed.c
- list of characters to trim from s.
java.lang.NullPointerException
- if s is null.public static java.lang.String highlightTerms(java.lang.String s, java.util.ArrayList searchTermList, java.lang.String highlightStartTag, java.lang.String highlightEndTag)
public static java.util.Hashtable unpackHash(java.lang.String str)
public static java.lang.String getStackTrace(java.lang.Exception e)
public static java.lang.String getStackTrace(java.lang.Throwable e)
public static java.lang.String trimToLength(java.lang.String stringToTrim, int maxLength)
public static void parseDate(ArchDescription accession, java.lang.String dateString)
public static void simpleParseDate(ArchDescription archDescription, java.lang.String str, boolean inclusive)
public static java.lang.String getFileExtension(java.io.File file)
public static java.lang.String getFileExtension(java.lang.String pathName)
public static java.lang.String getFilePathWithoutExtension(java.io.File file)
public static java.lang.String getFilePathWithoutExtension(java.lang.String pathName)
public static java.lang.String tagRemover(java.lang.String str)
public static java.lang.String[] extractStringAndValueInParenthesis(java.lang.String val)
public static java.lang.String getFirstPartofLangString(java.lang.String val, java.lang.String delim)
public static java.lang.String getSecondPartofLangString(java.lang.String val, java.lang.String delim)
public static boolean isNotEmpty(java.lang.String val)
public static boolean isEmpty(java.lang.String val)
public static java.lang.String concatenateFields(java.lang.String delimiter, java.lang.String... fields)
public static java.lang.String concatenateAllFields(java.lang.String delimiter, java.lang.String... fields)
public static java.lang.String handleRunningSpaces(java.lang.String val)
public static java.lang.String cleanUpWhiteSpace(java.lang.String stringToStrip)
public static java.lang.String concat(java.util.ArrayList array, java.lang.String seperator)
public static java.lang.String concat(java.lang.String seperator, java.lang.String... strings)
public static java.lang.String convertToNmtoken(java.lang.String string)
public static java.lang.String MD5(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.UnsupportedEncodingException
public static java.lang.String removeInvalidFileNameCharacters(java.lang.String fileName)
public static java.lang.String handleDecimal(java.lang.String valueD)
valueD
- The String value of the decimal
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |