com.cassinidivision.core.cassinijava
Class StringHelper

java.lang.Object
  extended bycom.cassinidivision.core.cassinijava.StringHelper

public class StringHelper
extends Object

A suite of handy String utilities.


Constructor Summary
StringHelper()
           
 
Method Summary
static String fixXHTML(String helpedString)
          Fixes a batch of HTML from the mangling done by IE's DHTML environment, so that it will once again be valid XML.
static int indexOfAnyString(String helpedString, Vector strings, int startIndex)
          Search a string for various substrings and return the index of the first found.
static String mostlyUniqueAlphanumericString()
          Returns a unique string value according to the current hostname, IP address and some other factors (including random factors).
static String stringByEscapingXMLCharactersInString(String helpedString)
          Escape various XML special characters (including &, <, >, ' and ").
static String stringFromStringByReplacingStringWithString(String helpedString, String from, String to)
          Search and replace all instances of the "from" string in "helpedString" with the "to" string.
static int stringIsEqualToStringUpToIndex(String string1, String string2)
          Compare two strings and return the index of the first character found where they differ.
static String stringWithContentsOfFile(String path)
          Read a file and return the contents as a string.
static String substringBetweenStringAndString(String helpedString, String from, String to)
          Returns the substring from the first instance of the "from" string and the next instance of the "to" string.
static String substringUptoString(String helpedString, String marker)
          Returns a substring of the given string up to (but not including) the marker string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

public StringHelper()
Method Detail

mostlyUniqueAlphanumericString

public static String mostlyUniqueAlphanumericString()
Returns a unique string value according to the current hostname, IP address and some other factors (including random factors). Currently used to generate unique OCE session IDs, amongst other things.

Returns:
The unique string generated.

substringBetweenStringAndString

public static String substringBetweenStringAndString(String helpedString,
                                                     String from,
                                                     String to)
Returns the substring from the first instance of the "from" string and the next instance of the "to" string.

Parameters:
helpedString - The string from which to extract substrings.
from - The beginning markerpoint.
to - The end markerpoint.
Returns:
The substring between the markerpoints.

substringUptoString

public static String substringUptoString(String helpedString,
                                         String marker)
Returns a substring of the given string up to (but not including) the marker string.

Parameters:
helpedString - The string to examine.
marker - The markerpoint.
Returns:
The prefix substring up to the markerpoint.

stringFromStringByReplacingStringWithString

public static String stringFromStringByReplacingStringWithString(String helpedString,
                                                                 String from,
                                                                 String to)
Search and replace all instances of the "from" string in "helpedString" with the "to" string.

Parameters:
helpedString - The string for examination.
from - The value of the original substring(s).
to - The value for the replacement substring(s).
Returns:
A version of the original string with all substitutions undertaken.

stringByEscapingXMLCharactersInString

public static String stringByEscapingXMLCharactersInString(String helpedString)
Escape various XML special characters (including &, <, >, ' and ").

Parameters:
helpedString - The string for examination.
Returns:
The escaped version of the original string.

indexOfAnyString

public static int indexOfAnyString(String helpedString,
                                   Vector strings,
                                   int startIndex)
Search a string for various substrings and return the index of the first found.

Parameters:
helpedString -
strings -
startIndex -
Returns:
index of the first match found, or -1 if no matches were found.

fixXHTML

public static String fixXHTML(String helpedString)
Fixes a batch of HTML from the mangling done by IE's DHTML environment, so that it will once again be valid XML. Specifically: - Fixes use of nbsp elements - Fixes BR and IMG tags which are not shown as empty (assumes all such tags are supposed to be empty). - Re-quotes any unquoted attributes.

Parameters:
helpedString -
Returns:
String containing corrected XHTML.

stringIsEqualToStringUpToIndex

public static int stringIsEqualToStringUpToIndex(String string1,
                                                 String string2)
Compare two strings and return the index of the first character found where they differ. The index range is 0 to (length of string)-1

Parameters:
string1 - One string.
string2 - Another string.
Returns:
The index of the first character (in both strings) that differs.

stringWithContentsOfFile

public static String stringWithContentsOfFile(String path)
                                       throws IOException
Read a file and return the contents as a string. May throw a RuntimeException if a problem occurs.

Parameters:
path - The full pathname to the file.
Returns:
A string representing the contents of the file.
Throws:
IOException