( String script, Object result, Exception error, StringBuffer scriptOutput )
| 154 | /** |
| 155 | */ |
| 156 | String formatScriptResultHTML( |
| 157 | String script, Object result, Exception error, |
| 158 | StringBuffer scriptOutput ) |
| 159 | throws IOException |
| 160 | { |
| 161 | SimpleTemplate tmplt; |
| 162 | |
| 163 | if ( error != null ) |
| 164 | { |
| 165 | tmplt = new SimpleTemplate( |
| 166 | getClass().getResource("error.template") ); |
| 167 | |
| 168 | String errString; |
| 169 | |
| 170 | if ( error instanceof bsh.EvalError ) |
| 171 | { |
| 172 | int lineNo = ((EvalError)error).getErrorLineNumber(); |
| 173 | String msg = error.getMessage(); |
| 174 | int contextLines = 4; |
| 175 | errString = escape(msg); |
| 176 | if ( lineNo > -1 ) |
| 177 | errString += "<hr>" |
| 178 | + showScriptContextHTML( script, lineNo, contextLines ); |
| 179 | } else |
| 180 | errString = escape( error.toString() ); |
| 181 | |
| 182 | tmplt.replace("error", errString ); |
| 183 | } else { |
| 184 | tmplt = new SimpleTemplate( |
| 185 | getClass().getResource("result.template") ); |
| 186 | tmplt.replace( "value", escape(String.valueOf(result)) ); |
| 187 | tmplt.replace( "output", escape(scriptOutput.toString()) ); |
| 188 | } |
| 189 | |
| 190 | return tmplt.toString(); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | Show context number lines of string before and after target line. |
no test coverage detected