1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.client;
|
3
|
|
import org.apache.cactus.WebTestResult;
|
4
|
|
|
5
|
|
/**
|
6
|
|
* Parse a string representing a Test result and transform it into a
|
7
|
|
* <code>WebTestResult</code> object.
|
8
|
|
*
|
9
|
|
* @see WebTestResult
|
10
|
|
*
|
11
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
12
|
|
*
|
13
|
|
* @version $Id: WebTestResultParser.java,v 1.5 2002/07/21 12:09:16 vmassol Exp $
|
14
|
|
*/
|
15
|
|
public class WebTestResultParser {
|
16
|
|
/**
|
17
|
|
* Parsed exception class name
|
18
|
|
*/
|
19
|
|
protected String exceptionClassname;
|
20
|
|
/**
|
21
|
|
* Parsed exception message
|
22
|
|
*/
|
23
|
|
protected String exceptionMessage;
|
24
|
|
/**
|
25
|
|
* Parsed exception stack trace
|
26
|
|
*/
|
27
|
|
protected String exceptionStacktrace;
|
28
|
|
/**
|
29
|
|
* Parse a string and transform it into a <code>WebTestResult</code> object.
|
30
|
|
*
|
31
|
|
* @param theData the string to parse
|
32
|
|
* @return the <code>WebTestResult</code> object corresponding to the data
|
33
|
|
* string
|
34
|
|
* @exception ParsingException if an error happens during parsing
|
35
|
|
*/
|
36
|
179
|
public WebTestResult parse(String theData) throws ParsingException {
|
37
|
179
|
String buffer;
|
38
|
179
|
WebTestResult result;
|
39
|
179
|
buffer = this.readRootElement(theData);
|
40
|
179
|
if (buffer.length() == 0) {
|
41
|
166
|
result = new WebTestResult();
|
42
|
|
} else {
|
43
|
13
|
buffer = this.readExceptionClassname(buffer);
|
44
|
13
|
buffer = this.readExceptionMessage(buffer);
|
45
|
13
|
buffer = this.readExceptionStacktrace(buffer);
|
46
|
13
|
result = new WebTestResult(this.exceptionClassname, this.exceptionMessage,
|
47
|
|
this.exceptionStacktrace);
|
48
|
|
}
|
49
|
179
|
return result;
|
50
|
|
}
|
51
|
|
|
52
|
|
/**
|
53
|
|
* Read the {@link WebTestResult#XML_ROOT_ELEMENT} portion.
|
54
|
|
*
|
55
|
|
* @param theData the string buffer to parse
|
56
|
|
* @return the string buffer minus what has been read
|
57
|
|
* @exception ParsingException if an error happens during parsing
|
58
|
|
*/
|
59
|
183
|
protected String readRootElement(String theData) throws ParsingException {
|
60
|
183
|
String startRootString = "<webresult>";
|
61
|
183
|
String endRootString = "</webresult>";
|
62
|
183
|
String buffer;
|
63
|
183
|
String trimmedData = theData.trim();
|
64
|
183
|
if (trimmedData.startsWith(startRootString) && trimmedData.endsWith(endRootString)) {
|
65
|
183
|
buffer = trimmedData.substring(startRootString.length(),
|
66
|
|
trimmedData.length() - endRootString.length());
|
67
|
|
} else {
|
68
|
0
|
throw new ParsingException("Not a valid response");
|
69
|
|
}
|
70
|
183
|
return buffer;
|
71
|
|
}
|
72
|
|
|
73
|
|
/**
|
74
|
|
* Read the {@link WebTestResult#XML_EXCEPTION_CLASSNAME_ATTRIBUTE} portion
|
75
|
|
* and extract the exception classname.
|
76
|
|
*
|
77
|
|
* @param theData the string buffer to parse
|
78
|
|
* @return the string buffer minus what has been read
|
79
|
|
* @exception ParsingException if an error happens during parsing
|
80
|
|
*/
|
81
|
15
|
protected String readExceptionClassname(String theData) throws ParsingException {
|
82
|
15
|
String startString = "<exception classname=\"";
|
83
|
15
|
String endString = "</exception>";
|
84
|
15
|
String buffer;
|
85
|
15
|
if (theData.startsWith(startString) && theData.endsWith(endString)) {
|
86
|
15
|
int pos = theData.indexOf('\"', startString.length());
|
87
|
15
|
this.exceptionClassname = theData.substring(startString.length(), pos);
|
88
|
15
|
buffer = theData.substring(startString.length() + this.exceptionClassname.length() + 2,
|
89
|
|
theData.length() - endString.length());
|
90
|
|
} else {
|
91
|
0
|
throw new ParsingException("Not a valid response");
|
92
|
|
}
|
93
|
15
|
return buffer;
|
94
|
|
}
|
95
|
|
|
96
|
|
/**
|
97
|
|
* Read the {@link WebTestResult#XML_EXCEPTION_MESSAGE_ELEMENT} portion
|
98
|
|
* and extract the exception message.
|
99
|
|
*
|
100
|
|
* @param theData the string buffer to parse
|
101
|
|
* @return the string buffer minus what has been read
|
102
|
|
* @exception ParsingException if an error happens during parsing
|
103
|
|
*/
|
104
|
14
|
protected String readExceptionMessage(String theData) throws ParsingException {
|
105
|
14
|
String startString = "<message><![CDATA[";
|
106
|
14
|
String endString = "]]></message>";
|
107
|
14
|
String buffer;
|
108
|
14
|
if (theData.startsWith(startString)) {
|
109
|
14
|
int pos = theData.indexOf(endString, startString.length());
|
110
|
14
|
this.exceptionMessage = theData.substring(startString.length(), pos);
|
111
|
14
|
buffer = theData.substring(pos + endString.length());
|
112
|
|
} else {
|
113
|
0
|
throw new ParsingException("Not a valid response");
|
114
|
|
}
|
115
|
14
|
return buffer;
|
116
|
|
}
|
117
|
|
|
118
|
|
/**
|
119
|
|
* Read the {@link WebTestResult#XML_EXCEPTION_STACKTRACE_ELEMENT} portion
|
120
|
|
* and extract the exception stacktrace.
|
121
|
|
*
|
122
|
|
* @param theData the string buffer to parse
|
123
|
|
* @return the string buffer minus what has been read
|
124
|
|
* @exception ParsingException if an error happens during parsing
|
125
|
|
*/
|
126
|
13
|
protected String readExceptionStacktrace(String theData) throws ParsingException {
|
127
|
13
|
String startString = "<stacktrace><![CDATA[";
|
128
|
13
|
String endString = "]]></stacktrace>";
|
129
|
13
|
String buffer;
|
130
|
13
|
if (theData.startsWith(startString)) {
|
131
|
13
|
int pos = theData.indexOf(endString, startString.length());
|
132
|
13
|
this.exceptionStacktrace = theData.substring(startString.length(), pos);
|
133
|
13
|
buffer = theData.substring(pos + endString.length());
|
134
|
|
} else {
|
135
|
0
|
throw new ParsingException("Not a valid response");
|
136
|
|
}
|
137
|
13
|
return buffer;
|
138
|
|
}
|
139
|
|
|
140
|
|
/**
|
141
|
|
* Parse a string representing a Test result and transform it into a
|
142
|
|
* <code>WebTestResult</code> object.
|
143
|
|
*
|
144
|
|
* @see WebTestResult
|
145
|
|
*
|
146
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
147
|
|
*
|
148
|
|
* @version $Id: WebTestResultParser.java,v 1.5 2002/07/21 12:09:16 vmassol Exp $
|
149
|
|
*/
|
150
|
183
|
public WebTestResultParser() {
|
151
|
183
|
super();
|
152
|
|
}
|
153
|
|
}
|