org.yawlfoundation.yawl.util
Class StringUtil

java.lang.Object
  extended by org.yawlfoundation.yawl.util.StringUtil

public class StringUtil
extends Object


Constructor Summary
StringUtil()
           
 
Method Summary
static String capitalise(String s)
          Converts a string to all lower case, and capitalises the first letter of the string
static String convertThrowableToString(Throwable t)
          Converts the throwable object into the standard Java stack trace format.
static long durationStrToMSecs(String s)
           
static long durationToMSecs(Duration d)
           
static long durationToMSecs(Duration d, long def)
           
static String extract(String source, String pattern)
           
static String fileToString(File f)
           
static String fileToString(String filename)
           
static int find(String toSearch, String toFind)
           
static int find(String toSearch, String toFind, int start)
           
static int find(String toSearch, String toFind, int start, boolean ignoreCase)
           
static List<Integer> findAll(String toSearch, String toFind)
           
static List<Integer> findAll(String toSearch, String toFind, boolean ignoreCase)
           
static String formatDecimalCost(BigDecimal value)
          Utility routine which takes a decimal value as a string (e.g.
static String formatForHTML(String string)
          Esacpes all HTML entities and "funky accents" into the HTML 4.0 encodings, replacing new lines with "<br>", tabs with four "&nbsp;" and single spaces with "&nbsp;".
static String formatPostCode(String postcode)
          Formats a postcode into standard Royal Mail format
static String formatSortCode(String sortcode)
          Formats a sortcode into the common form nn-nn-nn
static String formatTime(long time)
          formats a long time value into a string of the form 'ddd:hh:mm:ss'
static String formatUIDate(Calendar calendar)
          Deprecated. Use TimeUtil.formatUIDate
static String getDebugMessage(String msg)
          Utility routine to return a debug message suitable for logging.
static String getISOFormattedDate(Date date)
          Utility routine to return the date supplied as an ISO formatted string.
static String getRandomString(int length)
           
static boolean isIntegerString(String s)
           
static boolean isNullOrEmpty(String s)
           
static boolean isValidDurationString(String s)
           
static String longToDateTime(long time)
           
static String removeAllWhiteSpace(String string)
          Removes all white space from a string.
static String repeat(char c, int count)
           
static String replaceTokens(String buffer, String fromToken, String toToken)
          Utility routine to replace one token with another within a string object.
static String reverseString(String inputString)
          Utility method to take a string and return the string in revserse sequence.
static File stringToFile(String fileName, String contents)
           
static Duration strToDuration(String s)
           
static int strToInt(String s, int def)
           
static long strToLong(String s, long def)
           
static String unwrap(String xml)
          Removes an outer set of xml tags from an xml string, if possible
static String wrap(String core, String wrapTag)
          encases a string with a pair of xml tags
static String wrapEscaped(String core, String wrapTag)
           
static long xmlDateToLong(String s)
           
static String xmlDecode(String s)
          Decodes reserved characters in an xml string
static String xmlEncode(String s)
          Encodes reserved characters in an xml string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

replaceTokens

public static String replaceTokens(String buffer,
                                   String fromToken,
                                   String toToken)
Utility routine to replace one token with another within a string object.

Parameters:
buffer - String object to be manipulated
fromToken - Token to be replaced
toToken - Token used in replacement
Returns:
String object holding modified String

getISOFormattedDate

public static String getISOFormattedDate(Date date)
Utility routine to return the date supplied as an ISO formatted string.

Parameters:
date - Date object to be formatted
Returns:
String object holding ISO formatted representation of date supplied

getDebugMessage

public static String getDebugMessage(String msg)
Utility routine to return a debug message suitable for logging. It basically prefixes the supplied message with the current timestamp in ISO format.

Parameters:
msg - Body of debug message to be prefixed with the current timestamp
Returns:
String object holding debug message prefixed with ISO formatted current timestamp

reverseString

public static String reverseString(String inputString)
Utility method to take a string and return the string in revserse sequence.

Parameters:
inputString - String to be reversed
Returns:
Reversed string

removeAllWhiteSpace

public static String removeAllWhiteSpace(String string)
Removes all white space from a string.

Parameters:
string - String to remove white space from
Returns:
Resulting whitespaceless string.

formatPostCode

public static String formatPostCode(String postcode)
Formats a postcode into standard Royal Mail format

Parameters:
postcode -
Returns:
Postcode correctly formatted

formatSortCode

public static String formatSortCode(String sortcode)
Formats a sortcode into the common form nn-nn-nn

Parameters:
sortcode -
Returns:
Sortcode correctly formatted

capitalise

public static String capitalise(String s)
Converts a string to all lower case, and capitalises the first letter of the string

Parameters:
s - unformated string.
Returns:
The formated string.

formatUIDate

public static String formatUIDate(Calendar calendar)
Deprecated. Use TimeUtil.formatUIDate

Utility routine that takes in a Calendar referece and returns a date/time stamp suitable for use in a Portlets environment.

Parameters:
calendar -
Returns:
Date/timestamp suitable for display.

formatDecimalCost

public static String formatDecimalCost(BigDecimal value)
Utility routine which takes a decimal value as a string (e.g. 0.25 equating to 25p) and returns the value in UI currency format (e.g. £0.25).

Returns:
A formatted currency

formatTime

public static String formatTime(long time)
formats a long time value into a string of the form 'ddd:hh:mm:ss'

Parameters:
time - the time value (in milliseconds)
Returns:
the formatted time string

convertThrowableToString

public static String convertThrowableToString(Throwable t)
Converts the throwable object into the standard Java stack trace format.

Parameters:
t - Throwable to convert to a String
Returns:
String representation of Throwable t

formatForHTML

public static String formatForHTML(String string)
Esacpes all HTML entities and "funky accents" into the HTML 4.0 encodings, replacing new lines with "<br>", tabs with four "&nbsp;" and single spaces with "&nbsp;".

Parameters:
string - to escape
Returns:
escaped string

wrap

public static String wrap(String core,
                          String wrapTag)
encases a string with a pair of xml tags

Parameters:
core - the text to encase
wrapTag - the name of the tag to encase the text
Returns:
the encased string (e.g. "core")

wrapEscaped

public static String wrapEscaped(String core,
                                 String wrapTag)

unwrap

public static String unwrap(String xml)
Removes an outer set of xml tags from an xml string, if possible

Parameters:
xml - the xml string to strip
Returns:
the stripped xml string

xmlEncode

public static String xmlEncode(String s)
Encodes reserved characters in an xml string

Parameters:
s - the string to encode
Returns:
the newly encoded string

xmlDecode

public static String xmlDecode(String s)
Decodes reserved characters in an xml string

Parameters:
s - the string to decode
Returns:
the newly decoded string

isIntegerString

public static boolean isIntegerString(String s)

stringToFile

public static File stringToFile(String fileName,
                                String contents)

fileToString

public static String fileToString(File f)

fileToString

public static String fileToString(String filename)

extract

public static String extract(String source,
                             String pattern)

getRandomString

public static String getRandomString(int length)

isNullOrEmpty

public static boolean isNullOrEmpty(String s)

strToInt

public static int strToInt(String s,
                           int def)

strToLong

public static long strToLong(String s,
                             long def)

strToDuration

public static Duration strToDuration(String s)

isValidDurationString

public static boolean isValidDurationString(String s)

durationToMSecs

public static long durationToMSecs(Duration d,
                                   long def)

durationToMSecs

public static long durationToMSecs(Duration d)

durationStrToMSecs

public static long durationStrToMSecs(String s)

xmlDateToLong

public static long xmlDateToLong(String s)

longToDateTime

public static String longToDateTime(long time)

find

public static int find(String toSearch,
                       String toFind,
                       int start,
                       boolean ignoreCase)

find

public static int find(String toSearch,
                       String toFind,
                       int start)

find

public static int find(String toSearch,
                       String toFind)

findAll

public static List<Integer> findAll(String toSearch,
                                    String toFind,
                                    boolean ignoreCase)

findAll

public static List<Integer> findAll(String toSearch,
                                    String toFind)

repeat

public static String repeat(char c,
                            int count)


Copyright © 2004-2012 The YAWL Foundation.