01: package net.sourceforge.cruisecontrol.dashboard.saxhandler;
02:
03: import java.util.Map;
04:
05: import org.apache.commons.lang.StringUtils;
06: import org.xml.sax.Attributes;
07: import org.xml.sax.SAXException;
08:
09: public class StackTraceExtractor extends SAXBasedExtractor {
10:
11: public static final String KEY_STACKTRACE = "stacktrace.stacktrace";
12:
13: public static final String KEY_ERROR = "stacktrace.error";
14:
15: private boolean readingBuild;
16:
17: private boolean readingStatckTrace;
18:
19: private String stackTrace = "";
20:
21: private String error = "";
22:
23: public void startElement(String uri, String localName,
24: String qName, Attributes attributes) throws SAXException {
25: if ("build".equals(qName)) {
26: readingBuild = true;
27: error = StringUtils.defaultString(attributes
28: .getValue("error"));
29: }
30: if ("stacktrace".equals(qName)) {
31: readingStatckTrace = true;
32: }
33: }
34:
35: public void characters(char[] ch, int start, int length)
36: throws SAXException {
37: if (readingBuild && readingStatckTrace) {
38: String text = new String(ch, start, length);
39: if (StringUtils.isBlank(text)) {
40: return;
41: }
42: stackTrace += text;
43: }
44: }
45:
46: public void endElement(String uri, String localName, String qName)
47: throws SAXException {
48: if ("build".equals(qName)) {
49: readingBuild = false;
50: }
51: if ("stacktrace".equals(qName)) {
52: readingStatckTrace = false;
53: }
54: }
55:
56: public void report(Map resultSet) {
57: resultSet.put(KEY_STACKTRACE, stackTrace);
58: resultSet.put(KEY_ERROR, error);
59: }
60: }
|