org.erif.util
Class TextUtil

java.lang.Object
  |
  +--org.erif.util.TextUtil

public class TextUtil
extends java.lang.Object

this is partially superseded by java2 v1.4, but, eh...


Constructor Summary
TextUtil()
           
 
Method Summary
static java.lang.String build(java.util.Hashtable subs, java.lang.String body)
          given a hash of mail merge field strings, returns the properly merged body; mail merge fields defined by (|fieldname|); fields with no corresponding value will be returned blank
static java.lang.String emptyToNull(java.lang.String s)
          Takes a string and returns null if it's empty, else returns the original string
static java.lang.String emptyToNull(java.lang.String s, java.lang.String empty)
          Takes a string and returns null if it matches the empty string, else returns the original string
static java.lang.String fixNull(java.lang.String s)
          returns the original string value, converting nulls to blanks
static java.lang.String getEmail(java.lang.String s)
           
static boolean isNumOnly(java.lang.String num)
          Checks whether the given string contains only digits
static boolean isValidEmail(java.lang.String text)
          makes sure an email address is reasonably valid.
static int[] listToIntArray(java.lang.String list)
          Given a comma-delimited list of numbers, provides an int array if the list contains only numbers and commas.
static java.lang.String[] listToStringArray(java.lang.String list)
          Given a comma-delimited list of strings, provides an string array.
static void main(java.lang.String[] args)
          test; can currently call "pad"
static java.lang.String makeList(int[] array)
          Given a int[], returns a comma-delimited list of its values.
static java.lang.String makeList(long[] array)
          Given a long[], returns a comma-delimited list of its values.
static java.lang.String makeList(java.lang.String[] array)
          Given a String[], returns a comma-delimited list of its values.
static java.lang.String makeList(java.lang.String[] array, java.lang.String quote)
          Given a String[], returns a comma-delimited list of its values.
static java.lang.String makeRandomAlNum(int length)
           
static java.lang.String nullToEmpty(java.lang.String s)
          Takes a string and returns the empty string if null, else returns the original string.
static java.lang.String nullToEmpty(java.lang.String s, java.lang.String empty)
          Takes a string and returns the empty string if null, else returns the original string.
static java.lang.String pad(java.lang.String orig, java.lang.String pad, int length)
          Pads a string to a given length, padding to the left
static java.lang.String pad(java.lang.String orig, java.lang.String pad, int length, boolean front)
          Pads a string to a given length, padding to the left or right
static java.lang.String populate(java.util.Hashtable subs, java.lang.String body)
          given a hash of form name/value pairs and a "letter", returns the properly merged body; fields are defined by (|fieldname|); fields with no corresponding value will be returned blank
static java.lang.String populate(java.util.Hashtable subs, java.lang.String body, boolean load)
           
static java.lang.String populate(java.lang.String pattern, java.lang.String replace, java.lang.String body)
           
static java.lang.String readFile(java.lang.String s)
          given a filename, return the contents of the file
static java.lang.String readStream(java.io.InputStream is)
          given a stream, return the contents of the stream
static java.lang.String repeat(java.lang.String s, int n)
          repeats a given String n times
static java.lang.String replaceString(java.lang.String oldstr, java.lang.String newstr, java.lang.String text)
          replaces all occurrences of old with new in the specified text.
static java.lang.String rot13(java.lang.String s)
          transforms text rot13-style, baybee
static java.lang.String stripNonNumerics(java.lang.String string)
          removes all non-numeric characters from a String; originally intended for use with phone numbers that have those pesky -, (, ) characters, and spaces.
static java.lang.String trim(java.lang.String s, java.lang.String trailing, int length)
           
static java.lang.String wrap(java.lang.String text, int cols)
          word-wraps a string
static java.lang.String wrapForEmail(java.lang.String text)
          word-wraps a string to 72 characters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

repeat

public static java.lang.String repeat(java.lang.String s,
                                      int n)
repeats a given String n times

replaceString

public static java.lang.String replaceString(java.lang.String oldstr,
                                             java.lang.String newstr,
                                             java.lang.String text)
replaces all occurrences of old with new in the specified text.
Parameters:
oldStr - Text to be replaced
newStr - Text with which to replace
textStr - String containing the text to be replaced
Returns:
New string containing the replaced text

isValidEmail

public static boolean isValidEmail(java.lang.String text)
makes sure an email address is reasonably valid. Lazy implementation - it tries to make an InternetAddress. If it fails, it's invalid. Simple, no?
Parameters:
text - Potential address to be validated
Returns:
Whether the address is valid or not

wrapForEmail

public static java.lang.String wrapForEmail(java.lang.String text)
word-wraps a string to 72 characters
Parameters:
text - string to wrap
Returns:
string with newlines inserted

wrap

public static java.lang.String wrap(java.lang.String text,
                                    int cols)
word-wraps a string
Parameters:
text - string to wrap
cols - number of columns to wrap to
Returns:
string with newlines inserted

makeList

public static java.lang.String makeList(java.lang.String[] array)
Given a String[], returns a comma-delimited list of its values.
Parameters:
array - String[] to convert to value list
Returns:
Comma-delimited value list

makeList

public static java.lang.String makeList(java.lang.String[] array,
                                        java.lang.String quote)
Given a String[], returns a comma-delimited list of its values.
Parameters:
array - String[] to convert to value list
quote - String to put before and after each item of value list
Returns:
Comma-delimited value list

makeList

public static java.lang.String makeList(int[] array)
Given a int[], returns a comma-delimited list of its values.
Parameters:
array - int[] to convert to value list
Returns:
Comma-delimited value list

makeList

public static java.lang.String makeList(long[] array)
Given a long[], returns a comma-delimited list of its values.
Parameters:
array - long[] to convert to value list
Returns:
Comma-delimited value list

listToIntArray

public static int[] listToIntArray(java.lang.String list)
Given a comma-delimited list of numbers, provides an int array if the list contains only numbers and commas. Silently drops items that aren't numbers.
Parameters:
list - String containing number list
Returns:
int array

listToStringArray

public static java.lang.String[] listToStringArray(java.lang.String list)
Given a comma-delimited list of strings, provides an string array.
Parameters:
list - String containing list
Returns:
String array

isNumOnly

public static boolean isNumOnly(java.lang.String num)
Checks whether the given string contains only digits
Parameters:
num - String to be tested
Returns:
whether string contains digits only

fixNull

public static java.lang.String fixNull(java.lang.String s)
returns the original string value, converting nulls to blanks
Parameters:
s - string to be stripped of nulls
Returns:
original string value or blank if parameter was null

getEmail

public static java.lang.String getEmail(java.lang.String s)

rot13

public static java.lang.String rot13(java.lang.String s)
transforms text rot13-style, baybee
Parameters:
s - string to be rotated
Returns:
rotated text

populate

public static java.lang.String populate(java.util.Hashtable subs,
                                        java.lang.String body)
                                 throws java.io.IOException
given a hash of form name/value pairs and a "letter", returns the properly merged body; fields are defined by (|fieldname|); fields with no corresponding value will be returned blank
Parameters:
subs - fieldname/value pairs
body - the contents of the message, containing (|fieldname|) tags
Returns:
final body with merge fields replaced

populate

public static java.lang.String populate(java.util.Hashtable subs,
                                        java.lang.String body,
                                        boolean load)
                                 throws java.io.IOException

populate

public static java.lang.String populate(java.lang.String pattern,
                                        java.lang.String replace,
                                        java.lang.String body)

readFile

public static java.lang.String readFile(java.lang.String s)
                                 throws java.io.IOException
given a filename, return the contents of the file
Parameters:
s - filename

readStream

public static java.lang.String readStream(java.io.InputStream is)
                                   throws java.io.IOException
given a stream, return the contents of the stream
Parameters:
s - stream

makeRandomAlNum

public static java.lang.String makeRandomAlNum(int length)

trim

public static java.lang.String trim(java.lang.String s,
                                    java.lang.String trailing,
                                    int length)

build

public static java.lang.String build(java.util.Hashtable subs,
                                     java.lang.String body)
given a hash of mail merge field strings, returns the properly merged body; mail merge fields defined by (|fieldname|); fields with no corresponding value will be returned blank
Parameters:
subs - keyed by fieldname, with value String containing replacement text
body - the contents of the message, containing (|fieldname|) tags
Returns:
final body with merge fields replaced

emptyToNull

public static java.lang.String emptyToNull(java.lang.String s)
Takes a string and returns null if it's empty, else returns the original string
Parameters:
s - string to process
Returns:
original string or null

nullToEmpty

public static java.lang.String nullToEmpty(java.lang.String s)
Takes a string and returns the empty string if null, else returns the original string.
Parameters:
s - string to process
Returns:
empty string or original

emptyToNull

public static java.lang.String emptyToNull(java.lang.String s,
                                           java.lang.String empty)
Takes a string and returns null if it matches the empty string, else returns the original string
Parameters:
s - string to process
empty - string that constitutes "empty"
Returns:
original string or null

nullToEmpty

public static java.lang.String nullToEmpty(java.lang.String s,
                                           java.lang.String empty)
Takes a string and returns the empty string if null, else returns the original string. If the empty string is null, you're just a dumbass
Parameters:
s - string to process
empty - string that constitutes "empty"
Returns:
empty string or original

pad

public static java.lang.String pad(java.lang.String orig,
                                   java.lang.String pad,
                                   int length)
Pads a string to a given length, padding to the left
Parameters:
orig - original string
pad - padding string (typically a single character)
length - minimum length to pad to

pad

public static java.lang.String pad(java.lang.String orig,
                                   java.lang.String pad,
                                   int length,
                                   boolean front)
Pads a string to a given length, padding to the left or right
Parameters:
orig - original string
pad - padding string (typically a single character)
length - minimum length to pad to
front - boolean: true == front, false == back

stripNonNumerics

public static java.lang.String stripNonNumerics(java.lang.String string)
removes all non-numeric characters from a String; originally intended for use with phone numbers that have those pesky -, (, ) characters, and spaces.
Parameters:
string - string to strip

main

public static void main(java.lang.String[] args)
test; can currently call "pad"


Copyright © 2003 - kaolin fire