public String[] split(String text, String splitValue, 
                          String[] HTMLBalanceTags) {
        
        String restOfText = text;
        int nextBreakIndex = 0;
        List<String> list = new ArrayList<String>();
        int splitValueLength = splitValue.length();

        while (restOfText.length() > 0) {
            nextBreakIndex = restOfText.indexOf(splitValue);
            if (nextBreakIndex < 0) {
                list.add(restOfText);
                break;
            }
            
            list.add(restOfText.substring(0, nextBreakIndex+splitValueLength));
            restOfText = restOfText.substring(nextBreakIndex+splitValueLength);
        }
        
        // This code makes sure that no ending HTML </> tags are left out 
        // causing malfomed pages.
        if (HTMLBalanceTags.length > 0) {
            List<String> balancedList = new ArrayList<String>();
            for (int t = 0; t < HTMLBalanceTags.length; t++) {
                // first tag pass through
                if (t < 1) {
                    balancedList = getBalancedList(HTMLBalanceTags[t], list);
                } 
                else if (balancedList.size() > 1) {
                    // after the first pass through keep trying on each
                    // subsequent tag.
                    balancedList = 
                        getBalancedList(HTMLBalanceTags[t], balancedList);
                }
            }
            
            return balancedList.toArray(new String[balancedList.size()]);
        }
        else {
            return list.toArray(new String[list.size()]);
        }
    }
public String [ ] split ( String text , String splitValue , String [ ] HTMLBalanceTags ) { String restOfText = text ; int nextBreakIndex = 0 ; List < String > list = new ArrayList < String > ( ) ; int splitValueLength = splitValue . length ( ) ; while ( restOfText . length ( ) > 0 ) { nextBreakIndex = restOfText . indexOf ( splitValue ) ; if ( nextBreakIndex < 0 ) { list . add ( restOfText ) ; break ; } list . add ( restOfText . substring ( 0 , nextBreakIndex + splitValueLength ) ) ; restOfText = restOfText . substring ( nextBreakIndex + splitValueLength ) ; } if ( HTMLBalanceTags . length > 0 ) { List < String > balancedList = new ArrayList < String > ( ) ; for ( int t = 0 ; t < HTMLBalanceTags . length ; t ++ ) { if ( t < 1 ) { balancedList = getBalancedList ( HTMLBalanceTags [ t ] , list ) ; } else if ( balancedList . size ( ) > 1 ) { balancedList = getBalancedList ( HTMLBalanceTags [ t ] , balancedList ) ; } } return balancedList . toArray ( new String [ balancedList . size ( ) ] ) ; } else { return list . toArray ( new String [ list . size ( ) ] ) ; } }
Split the given string around the given split value.  This will also
ensure any of the given HTML tags are properly closed.

@param text The text value to split
@param splitValue The values to be split on
@param HTMLBalanceTags The HTML tags to ensure are closed properly

@return The array of string values per the splitting