private TeaStackTraceLine[] getTeaStackTraceLines(Throwable t) {

        // grab the existing stack trace
        StringWriter stackTraceGrabber = new StringWriter();
        t.printStackTrace(new PrintWriter(stackTraceGrabber));
        String stackTrace = stackTraceGrabber.toString();
        int extensionIndex = stackTrace.lastIndexOf(TEA_EXCEPTION);
        boolean isTeaException = extensionIndex != -1;
        if (isTeaException) {

            // trim off all lines after the last template exception
            int endIndex = stackTrace.indexOf('\n', extensionIndex);
            int endRIndex = stackTrace.indexOf('\r', extensionIndex);

            if(endRIndex>-1 && endRIndex<endIndex)
                endIndex=endRIndex;

            if (endIndex <= 0) {
                endIndex = stackTrace.length();
            }

            stackTrace = stackTrace.substring(0, endIndex);

            // parse each line
            List<TeaStackTraceLine> teaStackTraceLines =
                new ArrayList<TeaStackTraceLine>();
            StringTokenizer tokenizer = new StringTokenizer(stackTrace, "\n");
            while (tokenizer.hasMoreElements()) {
                String line = (String)tokenizer.nextElement();
                if (line.indexOf(TEA_EXCEPTION) != -1) {
                    /*
                    TODO: make sure this works for lines that don't have
                          line numbers.  Look in ESPN logs for examples.
                    at org.teatrove.teaservlet.template.schedule.substitute(schedule.tea:78)
                    at org.teatrove.teaservlet.template.shell.story.frame.substitute(shell/story/frame.tea)
                    */
                    String tempLine = line;

                    int bracket = tempLine.indexOf('(');
                    tempLine = tempLine.substring(bracket + 1);
                    bracket = tempLine.indexOf(')');
                    tempLine = tempLine.substring(0, bracket);
                    int colonIndex = tempLine.indexOf(':');
                    String templateName = null;
                    Integer lineNumber = null;
                    if (colonIndex >= 0) {
                        templateName = tempLine.substring(0, colonIndex);
                        try {
                            lineNumber = 
                                new Integer(tempLine.substring(colonIndex + 1));
                        }
                        catch (NumberFormatException nfe) { lineNumber = null; }
                    }
                    else {
                        templateName = tempLine;
                        lineNumber = null;
                    }
                    teaStackTraceLines.add(new TeaStackTraceLine(templateName,
                                                                 lineNumber,
                                                                 line));
                }
                else {
                    teaStackTraceLines.add(new TeaStackTraceLine(null, null, line));
                }
            }
            return (TeaStackTraceLine[]) teaStackTraceLines.toArray(
                              new TeaStackTraceLine[teaStackTraceLines.size()]);
        }
        else {
            return null;
        }
    }
private TeaStackTraceLine [ ] getTeaStackTraceLines ( Throwable t ) { StringWriter stackTraceGrabber = new StringWriter ( ) ; t . printStackTrace ( new PrintWriter ( stackTraceGrabber ) ) ; String stackTrace = stackTraceGrabber . toString ( ) ; int extensionIndex = stackTrace . lastIndexOf ( TEA_EXCEPTION ) ; boolean isTeaException = extensionIndex != - 1 ; if ( isTeaException ) { int endIndex = stackTrace . indexOf ( '\n' , extensionIndex ) ; int endRIndex = stackTrace . indexOf ( '\r' , extensionIndex ) ; if ( endRIndex > - 1 && endRIndex < endIndex ) endIndex = endRIndex ; if ( endIndex <= 0 ) { endIndex = stackTrace . length ( ) ; } stackTrace = stackTrace . substring ( 0 , endIndex ) ; List < TeaStackTraceLine > teaStackTraceLines = new ArrayList < TeaStackTraceLine > ( ) ; StringTokenizer tokenizer = new StringTokenizer ( stackTrace , "\n" ) ; while ( tokenizer . hasMoreElements ( ) ) { String line = ( String ) tokenizer . nextElement ( ) ; if ( line . indexOf ( TEA_EXCEPTION ) != - 1 ) { String tempLine = line ; int bracket = tempLine . indexOf ( '(' ) ; tempLine = tempLine . substring ( bracket + 1 ) ; bracket = tempLine . indexOf ( ')' ) ; tempLine = tempLine . substring ( 0 , bracket ) ; int colonIndex = tempLine . indexOf ( ':' ) ; String templateName = null ; Integer lineNumber = null ; if ( colonIndex >= 0 ) { templateName = tempLine . substring ( 0 , colonIndex ) ; try { lineNumber = new Integer ( tempLine . substring ( colonIndex + 1 ) ) ; } catch ( NumberFormatException nfe ) { lineNumber = null ; } } else { templateName = tempLine ; lineNumber = null ; } teaStackTraceLines . add ( new TeaStackTraceLine ( templateName , lineNumber , line ) ) ; } else { teaStackTraceLines . add ( new TeaStackTraceLine ( null , null , line ) ) ; } } return ( TeaStackTraceLine [ ] ) teaStackTraceLines . toArray ( new TeaStackTraceLine [ teaStackTraceLines . size ( ) ] ) ; } else { return null ; } }
Splits the stack trace into separate lines and extracts the template
name and line number.

@param t
@return  the separated stack trace lines