org.juniverse.utils
Class StringUtils

java.lang.Object
  |
  +--org.juniverse.utils.StringUtils

public class StringUtils
extends java.lang.Object

This class formats strings for different intentions. Further implementations of methods for manipulating strings should be insert here.

Version:
1.0 [2001-05-12]
Author:
Alexander Ilg

Constructor Summary
StringUtils()
          create a new StringUtils object
 
Method Summary
static java.lang.String createFilename(java.lang.String input, java.lang.String replace)
           
static java.lang.String cutString(java.lang.String inputString, int newLenght)
          This static method cut's an string at newLenght -3 and adds "..." at the end of the string
static boolean equals(java.lang.String s1, java.lang.String s2)
          Compares two Strings, returns true if their values are the same.
static java.lang.String firstLetterCaps(java.lang.String data)
          Makes the first letter caps and leaves the rest as is.
static java.lang.String highlightWords(java.lang.String string, java.lang.String[] words, java.lang.String startHighlight, java.lang.String endHighlight)
          Highlights words in a string.
static boolean isEmpty(java.lang.String inputString)
          Determine whether a (trimmed) string is empty
static boolean isValid(java.lang.String inputString)
          Validates that the supplied string is neither null nor the empty string.
static java.lang.String makeString(java.lang.String inString)
          Deal with null strings converting them to "" instead.
static java.lang.String removeEndOfLine(java.lang.String inputString)
          This method replaces all End of Line Charactars (\n) with spaces
static java.lang.String removeTabs(java.lang.String inputString)
          This method replaces all tab-chars (\t) with spaces
static java.lang.String replace(java.lang.String line, java.lang.String oldString, java.lang.String newString)
          Replaces all instances of oldString with newString in line.
static java.lang.String replaceIgnoreCase(java.lang.String line, java.lang.String oldString, java.lang.String newString)
          Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case.
static java.lang.String[] split(java.lang.String inputString, java.lang.String delimiter)
          This static method splits an string into an array of strings
static java.lang.String stackTrace(java.lang.Throwable e)
          Returns the output of printStackTrace as a String.
static java.lang.String stackTrace(java.lang.Throwable e, boolean addPre)
          Returns the output of printStackTrace as a String.
protected static java.lang.String wrapLine(java.lang.String line, java.lang.String newline, int wrapColumn)
          Wraps a single line of text.
static java.lang.String wrapText(java.lang.String inString, java.lang.String newline, int wrapColumn)
          Takes a block of text which might have long lines in it and wraps the long lines based on the supplied wrapColumn parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
create a new StringUtils object

Method Detail

makeString

public static final java.lang.String makeString(java.lang.String inString)
Deal with null strings converting them to "" instead. It also invokes String.trim() on the output.

Parameters:
inString - A String.
Returns:
A String.

isValid

public static final boolean isValid(java.lang.String inputString)
Validates that the supplied string is neither null nor the empty string.

Parameters:
inputString - A String.
Returns:
A boolean.

isEmpty

public static final boolean isEmpty(java.lang.String inputString)
Determine whether a (trimmed) string is empty

Parameters:
inputString - A String.
Returns:
A boolean.

stackTrace

public static final java.lang.String stackTrace(java.lang.Throwable e)
Returns the output of printStackTrace as a String.

Parameters:
e - A Throwable.
Returns:
A String.

stackTrace

public static final java.lang.String stackTrace(java.lang.Throwable e,
                                                boolean addPre)
Returns the output of printStackTrace as a String.

Parameters:
e - A Throwable.
addPre - a boolean to add HTML
 tags around the stacktrace
Returns:
A String.

equals

public static boolean equals(java.lang.String s1,
                             java.lang.String s2)
Compares two Strings, returns true if their values are the same.

Parameters:
s1 - The first string.
s2 - The second string.
Returns:
True if the values of both strings are the same.

firstLetterCaps

public static java.lang.String firstLetterCaps(java.lang.String data)
Makes the first letter caps and leaves the rest as is.

Parameters:
data - A String

wrapText

public static java.lang.String wrapText(java.lang.String inString,
                                        java.lang.String newline,
                                        int wrapColumn)
Takes a block of text which might have long lines in it and wraps the long lines based on the supplied wrapColumn parameter. If there are tabs in inString, you are going to get results that are a bit strange, since tabs are a single character but are displayed as 4 or 8 spaces. Remove the tabs.

Parameters:
inString - Text which is in need of word-wrapping.
newline - The characters that define a newline.
wrapColumn - The column to wrap the words at.
Returns:
The text with all the long lines word-wrapped.

wrapLine

protected static java.lang.String wrapLine(java.lang.String line,
                                           java.lang.String newline,
                                           int wrapColumn)
Wraps a single line of text. Called by wrapText(). I can't think of any good reason for exposing this to the public, since wrapText should always be used AFAIK.

Parameters:
line - A line which is in need of word-wrapping.
newline - The characters that define a newline.
wrapColumn - The column to wrap the words at.
Returns:
A line with newlines inserted.

cutString

public static java.lang.String cutString(java.lang.String inputString,
                                         int newLenght)
This static method cut's an string at newLenght -3 and adds "..." at the end of the string

Parameters:
inputString -
newLenght - the lenght of the new String
Returns:
the new String

split

public static java.lang.String[] split(java.lang.String inputString,
                                       java.lang.String delimiter)
This static method splits an string into an array of strings

Parameters:
inputString -
delimiter -
Returns:
array of strings

removeTabs

public static java.lang.String removeTabs(java.lang.String inputString)
This method replaces all tab-chars (\t) with spaces

Parameters:
inputString -
Returns:
the String without tabs

removeEndOfLine

public static java.lang.String removeEndOfLine(java.lang.String inputString)
This method replaces all End of Line Charactars (\n) with spaces

Parameters:
inputString -
Returns:
the String without \n

highlightWords

public static final java.lang.String highlightWords(java.lang.String string,
                                                    java.lang.String[] words,
                                                    java.lang.String startHighlight,
                                                    java.lang.String endHighlight)
Highlights words in a string. Words matching ignores case. The actual higlighting method is specified with the start and end higlight tags. Those might be beginning and ending HTML bold tags, or anything else.

Copyright (C) 2000 CoolServlets.com. All rights reserved.

Parameters:
string - the String to highlight words in.
words - an array of words that should be highlighted in the string.
startHighlight - the tag that should be inserted to start highlighting.
endHighlight - the tag that should be inserted to end highlighting.
Returns:
a new String with the specified words highlighted.

replace

public static final java.lang.String replace(java.lang.String line,
                                             java.lang.String oldString,
                                             java.lang.String newString)
Replaces all instances of oldString with newString in line.

Parameters:
line - the String to search to perform replacements on
oldString - the String that should be replaced by newString
newString - the String that will replace all instances of oldString
Returns:
a String will all instances of oldString replaced by newString

replaceIgnoreCase

public static final java.lang.String replaceIgnoreCase(java.lang.String line,
                                                       java.lang.String oldString,
                                                       java.lang.String newString)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case.

Copyright (C) 2000 CoolServlets.com. All rights reserved.

Parameters:
line - the String to search to perform replacements on
oldString - the String that should be replaced by newString
newString - the String that will replace all instances of oldString
Returns:
a String will all instances of oldString replaced by newString

createFilename

public static java.lang.String createFilename(java.lang.String input,
                                              java.lang.String replace)