com.jaxfront.core.util
Class TextTools

java.lang.Object
  extended by com.jaxfront.core.util.TextTools

public class TextTools
extends java.lang.Object

This class includes some nice features to convert and edit text. For example: the method colorToHex(Color) converts a Color Object into its Hex values.

Version:
1.60

Field Summary
static char CHAR_EMPTY
           
static char CHAR_NEWLINE
           
static char CHAR_SPACE
           
static int DIFFERENCE_IN_DAYS
           
static int DIFFERENCE_IN_MS
           
static java.lang.String ISO_DATE_PATTERN
           
static java.lang.String ISO_DATE_TIME_PATTERN
           
static java.lang.String ISO_TIME_PATTERN
           
static java.text.SimpleDateFormat isoDateFormat
           
static int iSODateFormat
           
static XSDDateFormat isoDateTimeFormat
           
static int iSODateTimeFormat
           
static int iSONoFormat
           
static java.text.SimpleDateFormat isoTimeFormat
           
static int iSOTimeFormat
           
static char NATIVE_DECIMAL_SEP
           
static java.lang.String PI_END_TAG
           
static java.lang.String PI_START_TAG
           
static java.lang.String SQL_DATE_TIME_PATTERN
           
static java.text.SimpleDateFormat sqlDateTIMEFormat
           
static java.awt.Graphics STRING_LENGTH_GRAPHICS
           
 
Method Summary
static int calculateTextLength(java.awt.Font aFont, java.lang.String text)
           
static java.lang.String colorToHex(java.awt.Color color)
          Converts a Color into its Hex values.
static java.lang.String[] compactStrings(java.lang.String[] strings)
           
static int compareTo(char[] string1, char[] string2)
           
static int compareTo(char[] string1, int offsetC1, char[] string2, int offsetC2)
          Compares two strings lexicographically.
static java.lang.String convertExponentialValue(java.lang.String number)
           
static java.lang.String convertNumbersToNative(java.lang.String number, java.text.DecimalFormatSymbols symbols)
           
static java.lang.String convertNumbersToView(java.lang.String number, java.text.DecimalFormat format, boolean useGrouping)
           
static java.lang.String convertSQLDateToIsoDate(java.lang.String dateStr)
           
static int countCharBetween(java.lang.String source, int start, int end, char charakter, char direction)
          Counts the occured named characters between a start and end index of a string.
static java.awt.Color createColor(java.lang.String colorAsString)
           
static java.lang.String createDelimited(java.util.List s, java.lang.String delimiter, java.lang.String fieldSeparator)
           
static java.lang.String createDelimited(java.lang.String[] s, char delimiter, char fieldSeparator)
           
static java.lang.String createDelimited(java.lang.String[] s, java.lang.String delimiter)
           
static java.lang.String createHTMLString(java.lang.String content)
           
static long difference(java.util.Date from, java.util.Date to, int mode)
           
static java.lang.String escapeNLSEntities(java.lang.String value)
          Replaces the global entities of a String.
static java.lang.StringBuffer exportToCSV(int startCol, java.lang.String[] columnNames, java.lang.String[][] array)
           
static int extractDateDelimiter(java.lang.String pattern, char dateSymbol)
          Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, otherwise the char int
static java.lang.String formatDate(long number, java.lang.String pattern)
          Method format calls the java.text.DecimalFormat class with the given parameters.
static java.lang.String formatToISODate(java.text.DateFormat currentFormat, java.lang.String currentFormatedDate)
           
static java.lang.String formatToISODate(java.lang.String pattern, java.lang.String currentFormatedDate)
           
static java.lang.String formatToISODateTime(java.text.DateFormat currentFormat, java.lang.String currentFormatedDateTime)
           
static java.lang.String formatToISODateTime(java.text.DateFormat currentFormat, java.lang.String currentFormatedDateTime, boolean hasReqEx)
           
static java.lang.String formatToISOTime(java.text.DateFormat currentFormat, java.lang.String currentFormatedTime)
           
static byte[] fromHexStringToByte(java.lang.String hex)
           
static java.lang.String[] getChoicesWithNoneEntry(java.lang.String[] choices)
           
static java.lang.String getClassName(java.lang.Class aClass)
           
static java.lang.String getContentFromURL(java.net.URL url)
           
static java.lang.String getCurrentISODate()
           
static java.lang.String getCurrentISODateTime()
           
static java.lang.String getCurrentISODateTime(long time)
           
static java.lang.String getCurrentISOTime(long time)
           
static int getDateDelimiterFor(java.lang.String pattern, char dateSymbol)
          Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, 0 if found at index 0, otherwise the char int value of the separator
static int getNodeEndPos(java.lang.String content, java.lang.String nodeName, int start, char nodeStartQualifier, char nodeEndQualifier)
           
static java.util.HashMap getProcessingInstruction(java.lang.String xml)
           
static java.lang.String getSeasonSplashName()
           
static int getUsedISODateFormat(java.lang.String value)
           
static java.lang.String hardCoreIsoConverter(java.lang.String pattern, java.lang.String value)
          Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, otherwise the char int
static int hasChar(java.lang.String source, int pos, char charakter, char direction)
           
static boolean isISODate(java.lang.String currentFormatedDate)
           
static boolean isISODateTime(java.lang.String currentFormatedDate)
           
static boolean isISOTime(java.lang.String currentFormatedTime)
           
static void main(java.lang.String[] args)
           
static java.lang.StringBuffer out(java.lang.String s, java.text.BreakIterator iter)
           
static boolean parseBoolean(java.lang.String value, boolean defaultValue)
           
static byte parseByte(java.lang.String value, byte defaultValue)
           
static int parseInt(java.lang.String value, int defaultValue)
           
static java.util.Date parseISODate(java.lang.String dateStr)
           
static long parseLong(java.lang.String value, long defaultValue)
           
static java.util.Date parseSQLDate(java.lang.String dateStr)
           
static java.lang.String quote(java.lang.String text)
          Quotes any passing text.
static java.lang.String removeChar(java.lang.String source, char aChar)
           
static java.lang.String removeInvalidUnicodeChars(java.lang.String toClean)
           
static java.lang.String removeSingleOccureChar(java.lang.String source, char aChar)
           
static java.lang.String removeSpaceChars(java.lang.String result)
           
static java.lang.String removeSpecialChars(java.lang.String toClean)
           
static char[] removeTrailingChar(char[] source, char aChar, int offset, char stopChar)
           
static char[] replace(char[] source, char from, char to)
           
static java.lang.String replace(java.lang.String source, char from, char to)
           
static java.lang.String replace(java.lang.String source, java.lang.String oldString, java.lang.String newString)
          Replaces a text of a String by a new one.
static java.lang.String replace(java.lang.String source, java.lang.String oldString, java.lang.String newString, java.lang.String splitCharacter)
          Replaces a text of a String by a new one.
static java.lang.String replaceGlobalEntities(java.lang.String value)
          Replaces the global entities of a String.
static java.lang.String replaceGlobalHTMLEntities(java.lang.String value)
          Replaces the global entities of a String.
static java.lang.String replaceGlobalUserProperties(java.lang.String value, Document dom)
          Replaces the global user properties for a String.
static java.lang.String reverseText(java.lang.String text)
          Reverses the given text.
static java.lang.String splitText(java.lang.String text)
           
static java.lang.String splitTextMaxLength(java.lang.String text, int maxLength)
           
static java.lang.String substringAfter(java.lang.String source, java.lang.String from)
           
static java.lang.String toHexString(byte b)
           
static java.lang.String toHexString(byte[] bytes)
           
static java.lang.String[] tokenize(java.lang.String s, java.lang.String delimiter)
          Tokenizes a String and returns its token in a String array.
static java.lang.Integer[] tokenizeToInteger(java.lang.String s, java.lang.String delimiter)
          Tokenizes a String and returns its token in a String array.
static java.lang.String toString(java.lang.Object[] objects)
          Creates a comma separated string representation of an object array.
static java.lang.String translateVar(java.lang.String aValue, Document dom)
           
static java.lang.String unEscapeNLSEntities(java.lang.String value)
          Replaces the global entities of a String.
static java.lang.String unquote(java.lang.String text)
          Removes the start and end quotes from any passing text.
static java.lang.StringBuffer wordOut(java.lang.String s, java.text.BreakIterator iter, int maxLength)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHAR_SPACE

public static final char CHAR_SPACE
See Also:
Constant Field Values

CHAR_EMPTY

public static final char CHAR_EMPTY
See Also:
Constant Field Values

CHAR_NEWLINE

public static final char CHAR_NEWLINE
See Also:
Constant Field Values

NATIVE_DECIMAL_SEP

public static final char NATIVE_DECIMAL_SEP
See Also:
Constant Field Values

PI_START_TAG

public static final java.lang.String PI_START_TAG
See Also:
Constant Field Values

PI_END_TAG

public static final java.lang.String PI_END_TAG
See Also:
Constant Field Values

ISO_DATE_PATTERN

public static final java.lang.String ISO_DATE_PATTERN
See Also:
Constant Field Values

ISO_DATE_TIME_PATTERN

public static final java.lang.String ISO_DATE_TIME_PATTERN
See Also:
Constant Field Values

SQL_DATE_TIME_PATTERN

public static final java.lang.String SQL_DATE_TIME_PATTERN
See Also:
Constant Field Values

ISO_TIME_PATTERN

public static final java.lang.String ISO_TIME_PATTERN
See Also:
Constant Field Values

isoDateFormat

public static java.text.SimpleDateFormat isoDateFormat

sqlDateTIMEFormat

public static java.text.SimpleDateFormat sqlDateTIMEFormat

isoDateTimeFormat

public static XSDDateFormat isoDateTimeFormat

isoTimeFormat

public static java.text.SimpleDateFormat isoTimeFormat

STRING_LENGTH_GRAPHICS

public static final java.awt.Graphics STRING_LENGTH_GRAPHICS

iSONoFormat

public static final int iSONoFormat
See Also:
Constant Field Values

iSODateFormat

public static final int iSODateFormat
See Also:
Constant Field Values

iSODateTimeFormat

public static final int iSODateTimeFormat
See Also:
Constant Field Values

iSOTimeFormat

public static final int iSOTimeFormat
See Also:
Constant Field Values

DIFFERENCE_IN_DAYS

public static final int DIFFERENCE_IN_DAYS
See Also:
Constant Field Values

DIFFERENCE_IN_MS

public static final int DIFFERENCE_IN_MS
See Also:
Constant Field Values
Method Detail

getClassName

public static java.lang.String getClassName(java.lang.Class aClass)

main

public static void main(java.lang.String[] args)

convertNumbersToNative

public static java.lang.String convertNumbersToNative(java.lang.String number,
                                                      java.text.DecimalFormatSymbols symbols)

convertNumbersToView

public static java.lang.String convertNumbersToView(java.lang.String number,
                                                    java.text.DecimalFormat format,
                                                    boolean useGrouping)

colorToHex

public static java.lang.String colorToHex(java.awt.Color color)
Converts a Color into its Hex values.

Parameters:
Color - a Color to convert
Returns:
the Hex values of a Color

replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String oldString,
                                       java.lang.String newString)
Replaces a text of a String by a new one.

Parameters:
source - the original String that contains the old text
oldString - the text that should be replaced by the new one
newString - the new text that replaces the old one
Returns:
the source String with the new text

removeChar

public static java.lang.String removeChar(java.lang.String source,
                                          char aChar)

removeSingleOccureChar

public static java.lang.String removeSingleOccureChar(java.lang.String source,
                                                      char aChar)

removeTrailingChar

public static char[] removeTrailingChar(char[] source,
                                        char aChar,
                                        int offset,
                                        char stopChar)

substringAfter

public static java.lang.String substringAfter(java.lang.String source,
                                              java.lang.String from)

replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String oldString,
                                       java.lang.String newString,
                                       java.lang.String splitCharacter)
Replaces a text of a String by a new one.

Parameters:
source - the original String that contains the old text
oldString - the text that should be replaced by the new one
newString - the new text that replaces the old one
splitCharacter - a character that is added at the end of both the oldString and newString
Returns:
the source String with the new text

replaceGlobalEntities

public static java.lang.String replaceGlobalEntities(java.lang.String value)
Replaces the global entities of a String.

Parameters:
value - a String that contains global entities
Returns:
a String without any global entities

replaceGlobalHTMLEntities

public static java.lang.String replaceGlobalHTMLEntities(java.lang.String value)
Replaces the global entities of a String.

Parameters:
value - a String that contains global entities
Returns:
a String without any global entities

escapeNLSEntities

public static java.lang.String escapeNLSEntities(java.lang.String value)
Replaces the global entities of a String.

Parameters:
value - a String that contains global entities
Returns:
a String without any global entities

unEscapeNLSEntities

public static java.lang.String unEscapeNLSEntities(java.lang.String value)
Replaces the global entities of a String.

Parameters:
value - a String that contains global entities
Returns:
a String without any global entities

replaceGlobalUserProperties

public static java.lang.String replaceGlobalUserProperties(java.lang.String value,
                                                           Document dom)
Replaces the global user properties for a String.

Parameters:
value - a String that contains global user properties
dom - a JAXFront Document (DOM)
Returns:
a String without any global user properties

tokenize

public static java.lang.String[] tokenize(java.lang.String s,
                                          java.lang.String delimiter)
Tokenizes a String and returns its token in a String array.

Parameters:
s - a String that needs to be tokenized
delimiter - delimiter parameters for the tokenizer
Returns:
a String array that contains all found tokens

tokenizeToInteger

public static java.lang.Integer[] tokenizeToInteger(java.lang.String s,
                                                    java.lang.String delimiter)
Tokenizes a String and returns its token in a String array.

Parameters:
s - a String that needs to be tokenized
delimiter - delimiter parameters for the tokenizer
Returns:
a String array that contains all found tokens

createDelimited

public static java.lang.String createDelimited(java.lang.String[] s,
                                               java.lang.String delimiter)

createDelimited

public static java.lang.String createDelimited(java.util.List s,
                                               java.lang.String delimiter,
                                               java.lang.String fieldSeparator)

createDelimited

public static java.lang.String createDelimited(java.lang.String[] s,
                                               char delimiter,
                                               char fieldSeparator)

hasChar

public static int hasChar(java.lang.String source,
                          int pos,
                          char charakter,
                          char direction)

reverseText

public static java.lang.String reverseText(java.lang.String text)
Reverses the given text.

Parameters:
text - java.lang.String a text
Returns:
java.lang.String the reversed text

countCharBetween

public static int countCharBetween(java.lang.String source,
                                   int start,
                                   int end,
                                   char charakter,
                                   char direction)
Counts the occured named characters between a start and end index of a string.

Parameters:
source - string to process
start - index to start
end - index to end
charakter - to count
direction - to processs

compareTo

public static int compareTo(char[] string1,
                            int offsetC1,
                            char[] string2,
                            int offsetC2)
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the Object.equals(Object)method would return true.

This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, compareTo returns the difference of the two character values at position k in the two string -- that is, the value:

 this.charAt(k) - anotherString.charAt(k)
 
If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, compareTo returns the difference of the lengths of the strings -- that is, the value:
 this.length() - anotherString.length()
 

Parameters:
anotherString - the String to be compared.
Returns:
the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument.

toHexString

public static java.lang.String toHexString(byte b)

toHexString

public static java.lang.String toHexString(byte[] bytes)

fromHexStringToByte

public static byte[] fromHexStringToByte(java.lang.String hex)

compareTo

public static int compareTo(char[] string1,
                            char[] string2)

toString

public static java.lang.String toString(java.lang.Object[] objects)
Creates a comma separated string representation of an object array.

Parameters:
objects - to create string from
Returns:

quote

public static java.lang.String quote(java.lang.String text)
Quotes any passing text.

Parameters:
text - to quote

unquote

public static java.lang.String unquote(java.lang.String text)
Removes the start and end quotes from any passing text.

Parameters:
text - to unquote

getSeasonSplashName

public static java.lang.String getSeasonSplashName()

createColor

public static java.awt.Color createColor(java.lang.String colorAsString)

getContentFromURL

public static java.lang.String getContentFromURL(java.net.URL url)
                                          throws java.io.IOException
Throws:
java.io.IOException

compactStrings

public static java.lang.String[] compactStrings(java.lang.String[] strings)

convertExponentialValue

public static java.lang.String convertExponentialValue(java.lang.String number)
                                                throws java.lang.NumberFormatException
Throws:
java.lang.NumberFormatException

getProcessingInstruction

public static java.util.HashMap getProcessingInstruction(java.lang.String xml)

getCurrentISODate

public static java.lang.String getCurrentISODate()

getCurrentISODateTime

public static java.lang.String getCurrentISODateTime()

getCurrentISODateTime

public static java.lang.String getCurrentISODateTime(long time)

getCurrentISOTime

public static java.lang.String getCurrentISOTime(long time)

formatToISODate

public static java.lang.String formatToISODate(java.text.DateFormat currentFormat,
                                               java.lang.String currentFormatedDate)
                                        throws java.text.ParseException
Throws:
java.text.ParseException

formatToISODateTime

public static java.lang.String formatToISODateTime(java.text.DateFormat currentFormat,
                                                   java.lang.String currentFormatedDateTime)
                                            throws java.text.ParseException
Throws:
java.text.ParseException

formatToISODateTime

public static java.lang.String formatToISODateTime(java.text.DateFormat currentFormat,
                                                   java.lang.String currentFormatedDateTime,
                                                   boolean hasReqEx)
                                            throws java.text.ParseException
Throws:
java.text.ParseException

formatToISOTime

public static java.lang.String formatToISOTime(java.text.DateFormat currentFormat,
                                               java.lang.String currentFormatedTime)
                                        throws java.text.ParseException
Throws:
java.text.ParseException

formatToISODate

public static java.lang.String formatToISODate(java.lang.String pattern,
                                               java.lang.String currentFormatedDate)
                                        throws java.text.ParseException
Throws:
java.text.ParseException

getUsedISODateFormat

public static int getUsedISODateFormat(java.lang.String value)

isISODate

public static boolean isISODate(java.lang.String currentFormatedDate)

isISODateTime

public static boolean isISODateTime(java.lang.String currentFormatedDate)

isISOTime

public static boolean isISOTime(java.lang.String currentFormatedTime)

formatDate

public static java.lang.String formatDate(long number,
                                          java.lang.String pattern)
Method format calls the java.text.DecimalFormat class with the given parameters.

Parameters:
number -
pattern -
Returns:
String

getNodeEndPos

public static int getNodeEndPos(java.lang.String content,
                                java.lang.String nodeName,
                                int start,
                                char nodeStartQualifier,
                                char nodeEndQualifier)

wordOut

public static java.lang.StringBuffer wordOut(java.lang.String s,
                                             java.text.BreakIterator iter,
                                             int maxLength)

splitTextMaxLength

public static java.lang.String splitTextMaxLength(java.lang.String text,
                                                  int maxLength)

splitText

public static java.lang.String splitText(java.lang.String text)

out

public static java.lang.StringBuffer out(java.lang.String s,
                                         java.text.BreakIterator iter)

difference

public static long difference(java.util.Date from,
                              java.util.Date to,
                              int mode)

removeSpecialChars

public static java.lang.String removeSpecialChars(java.lang.String toClean)

removeInvalidUnicodeChars

public static java.lang.String removeInvalidUnicodeChars(java.lang.String toClean)

removeSpaceChars

public static java.lang.String removeSpaceChars(java.lang.String result)

createHTMLString

public static java.lang.String createHTMLString(java.lang.String content)

getChoicesWithNoneEntry

public static java.lang.String[] getChoicesWithNoneEntry(java.lang.String[] choices)

getDateDelimiterFor

public static int getDateDelimiterFor(java.lang.String pattern,
                                      char dateSymbol)
Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, 0 if found at index 0, otherwise the char int value of the separator

Parameters:
pattern -
dateSymbol -
Returns:

extractDateDelimiter

public static int extractDateDelimiter(java.lang.String pattern,
                                       char dateSymbol)
Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, otherwise the char int

Parameters:
pattern -
dateSymbol -
Returns:

hardCoreIsoConverter

public static java.lang.String hardCoreIsoConverter(java.lang.String pattern,
                                                    java.lang.String value)
Extract a possible separator for the given date symbol to it's antecessor returns -1 if not found, otherwise the char int

Parameters:
pattern -
dateSymbol -
Returns:

replace

public static java.lang.String replace(java.lang.String source,
                                       char from,
                                       char to)

replace

public static char[] replace(char[] source,
                             char from,
                             char to)

exportToCSV

public static java.lang.StringBuffer exportToCSV(int startCol,
                                                 java.lang.String[] columnNames,
                                                 java.lang.String[][] array)

calculateTextLength

public static int calculateTextLength(java.awt.Font aFont,
                                      java.lang.String text)

parseInt

public static int parseInt(java.lang.String value,
                           int defaultValue)

parseLong

public static long parseLong(java.lang.String value,
                             long defaultValue)

parseBoolean

public static boolean parseBoolean(java.lang.String value,
                                   boolean defaultValue)

parseByte

public static byte parseByte(java.lang.String value,
                             byte defaultValue)

translateVar

public static java.lang.String translateVar(java.lang.String aValue,
                                            Document dom)

convertSQLDateToIsoDate

public static java.lang.String convertSQLDateToIsoDate(java.lang.String dateStr)

parseISODate

public static java.util.Date parseISODate(java.lang.String dateStr)

parseSQLDate

public static java.util.Date parseSQLDate(java.lang.String dateStr)