|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.util.StringHelper
public class StringHelper
Some handy methods for strings.
| Field Summary | |
|---|---|
static char |
creditLetter
short letter for "credit" (haben) |
static DateFormat |
dateFormat
localized DateFormat for a date |
static String |
datePattern
localized format string for a date |
static char |
debitLetter
short letter for "debit" (soll) |
static String |
emptyString
the empty string |
static String |
floatDoublePattern
default float/double format string |
static String |
integerPattern
default integer format string |
static String |
lineSeparatorString
the newline string |
static char[] |
MD5SALT
Salt for md5sum(char[]).The default is null, i.e. |
static String |
moneyPattern
default money format string |
static DateFormat |
shortDateFormat
localized DateFormat for a short date |
static String |
shortDatePattern
localized format string for a short date |
static DateFormat |
shortTimeFormat
localized DateFormat for a short time |
static String |
shortTimePattern
localized format string for a short time |
static DateFormat |
shortTimestampFormat
localized DateFormat for a short timestamp |
static String |
shortTimestampPattern
localized format string for a short timestamp |
static StringConverter |
stringNormalizer
The default normalizer used within the application. |
static DateFormat |
timeFormat
localized DateFormat for a time |
static String |
timePattern
localized format string for a time |
static DateFormat |
timestampFormat
localized DateFormat for a timestamp |
static String |
timestampPattern
localized format string for a timestamp |
| Constructor Summary | |
|---|---|
StringHelper()
|
|
| Method Summary | |
|---|---|
static String |
debitCreditToString(BMoney money,
boolean debit)
Translates a money value to a string with a suffix indicating whether debit or credit. |
static String |
firstLine(String str)
Gets the first line from a multi-line string. |
static String |
getClassBaseName(Class<?> clazz)
Gets the basename of a class. |
static String |
getClassBaseName(String str)
Gets the basename of a classname(-like) string. |
static boolean |
isAllDigits(String str)
checks if a string contains only digits, i.e. |
static boolean |
isAllDigits(String str,
boolean whitespaceAllowed)
Checks if a string contains only digits or whitespaces, i.e. |
static boolean |
isAllWhitespace(String str)
Checks if string contains only whitespaces. |
static void |
loadFormats()
Loads the localized formats. |
static String |
md5sum(char[] input)
Builds an MD5-sum from an array of chars with a default salt given by MD5SALT. |
static String |
md5sum(char[] salt,
char[] input)
Builds an MD5-sum from an array of chars as used in password-fields. Note that this method converts the characters to bytes via toBytes(char[])
before applying the md5 hash. |
static String |
normalize(String str)
Normalizes a string (phonetically) for use as AppDbObject.normText
using stringNormalizer. |
static String |
normalize(String str,
StringConverter normalizer)
Normalizes a string (phonetically) for use as AppDbObject.normText. |
static String |
objectArrayToString(Object[] objArray,
String separator)
Creates a string from an object array. |
static byte[] |
toBytes(char c)
Converts a single (unicode) char to a byte-array. |
static byte[] |
toBytes(char[] chars)
Converts a char-array to a byte-array. |
static char[] |
toCharArray(String str)
Transforms a string to a char-array. |
static String |
toDoubleQuotes(String str)
Takes a string, surrounds it with double-quotes and escapes all double-quotes already in the string according to Unix rules. |
static String |
toDTA(String str)
Filters illegal chars for DTA-Files (German "DATENAUSTAUSCH" banking format). |
static String |
toFixedLength(String str,
int length)
Takes a string and returns one with a given length, cutting or filling up with spaces, whatever appropriate. |
static String |
toFixedLength(String str,
int length,
char filler)
Takes a string and returns one with a given length, cutting or filling up with fillchars, whatever appropriate. |
static String |
toFixedLengthLeftFill(String str,
int length)
Takes a string and returns one with a given length, cutting or filling up with spaces from the left, whatever appropriate. |
static String |
toFixedLengthLeftFill(String str,
int length,
char filler)
Takes a string and returns one with a given length, cutting or filling up with fillchars from the left, whatever appropriate. |
static String |
toHexString(byte[] binaryData)
Creates a human-readable hex-String out of a byte-array (e.g. |
static String |
toHTML(String text)
Converts a multiline string to an HTML-string that can be displayed in a label. |
static String |
toString(String str)
Maps null to the empty string. |
static String |
toVarName(String str)
Filters illegal chars for Java variable names. |
static String |
toWindowsDoubleQuotes(String str)
Takes a string, surrounds it with double-quotes and escapes all double-quotes already in the string according to Windows-rules. |
static String |
trim(String s)
Trims a string. |
static String |
trim(String s,
int max)
Trims a string. |
static String |
unDiacrit(String str)
Converts special unicode characters (so-called diacrits) to standard ascii. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String integerPattern
public static final String floatDoublePattern
public static final String moneyPattern
public static String timestampPattern
public static String datePattern
public static String timePattern
public static String shortTimestampPattern
public static String shortDatePattern
public static String shortTimePattern
public static DateFormat timestampFormat
DateFormat for a timestamp
public static DateFormat dateFormat
DateFormat for a date
public static DateFormat timeFormat
DateFormat for a time
public static DateFormat shortTimestampFormat
DateFormat for a short timestamp
public static DateFormat shortDateFormat
DateFormat for a short date
public static DateFormat shortTimeFormat
DateFormat for a short time
public static char debitLetter
public static char creditLetter
public static final String emptyString
public static final String lineSeparatorString
public static StringConverter stringNormalizer
public static char[] MD5SALT
md5sum(char[]).
| Constructor Detail |
|---|
public StringHelper()
| Method Detail |
|---|
public static void loadFormats()
Locale changes.
public static String unDiacrit(String str)
str - the string to be converted
public static String normalize(String str,
StringConverter normalizer)
AppDbObject.normText.
str - the string to be normalizednormalizer - the normalizer to use, null = global default
public static String normalize(String str)
AppDbObject.normText
using stringNormalizer.
str - the string to be normalized
public static String toDoubleQuotes(String str)
Length 5" --> "Length 5\""
str - the string
public static String toWindowsDoubleQuotes(String str)
Length 5" --> "Length 5""
str - the string
public static String toFixedLength(String str,
int length,
char filler)
str - the stringlength - the length of the returned stringfiller - the character to fill up if str is too short
public static String toFixedLength(String str,
int length)
str - the stringlength - the length of the returned string
public static String toFixedLengthLeftFill(String str,
int length,
char filler)
str - the stringlength - the length of the returned stringfiller - the character to fill up if str is too short
public static String toFixedLengthLeftFill(String str,
int length)
str - the stringlength - the length of the returned string
public static String toDTA(String str)
str - the string
public static String toVarName(String str)
str - the string
public static boolean isAllDigits(String str,
boolean whitespaceAllowed)
str - the string to checkwhitespaceAllowed - true if whitespaces are allowed
public static boolean isAllDigits(String str)
str - the string to check
public static String debitCreditToString(BMoney money,
boolean debit)
money - the amount of moneydebit - true if the amount is debit
public static String trim(String s,
int max)
s - the string, may be nullmax - the maximum number of characters, 0 = minimum length
public static String trim(String s)
s - the string, may be null
trim(java.lang.String, int)public static boolean isAllWhitespace(String str)
str - the string to check
public static String firstLine(String str)
str - the multiline string
public static String toHexString(byte[] binaryData)
binaryData - the data, may be null
public static byte[] toBytes(char c)
c - the character
public static byte[] toBytes(char[] chars)
chars - the character array
public static String md5sum(char[] salt,
char[] input)
toBytes(char[])
before applying the md5 hash.
By this we achieve an enhanced security against md5 crackers, which assume
ordinary strings. In order to enhance security even more, however, you should
add some application-specific salt.
salt - the "salt", null if plain MD5.input - is the input array of chars
md5sum(char[]),
MD5SALTpublic static String md5sum(char[] input)
MD5SALT.
input - is the input array of chars
public static String toString(String str)
str - the string to test against null
public static String getClassBaseName(String str)
str - the classname
public static String getClassBaseName(Class<?> clazz)
clazz - the class
getClassBaseName(java.lang.String)
public static String objectArrayToString(Object[] objArray,
String separator)
objArray - the array of objectsseparator - the string between two objects
public static char[] toCharArray(String str)
str - the string
public static String toHTML(String text)
text - the input string
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||