1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 package org.w3c.tidy.servlet.data;
56
57
58
59 import org.w3c.tidy.TidyMessage;
60 import org.w3c.tidy.TidyMessageListener;
61 import org.w3c.tidy.servlet.ResponseRecord;
62
63 import java.util.List;
64 import java.util.Vector;
65
66
67 /***
68 * Data to store Validation results and error.
69 * @todo Create the API interface for adding additional attributes like JSP name, action
70 *
71 * @author Vlad Skarzhevskyy <a href="mailto:skarzhevskyy@gmail.com">skarzhevskyy@gmail.com</a>
72 * @version $Revision: 1.2 $ ($Author: vlads $)
73 */
74 public class DefaultResponseRecord implements TidyMessageListener, ResponseRecord
75 {
76
77 private Object requestID;
78
79 private int parseErrors;
80
81 private int parseWarnings;
82
83 private String html;
84
85 private String htmlResult;
86
87 private String report;
88
89 private List messages;
90
91 private long parsTime;
92
93 private long when;
94
95 public DefaultResponseRecord()
96 {
97 messages = new Vector();
98 when = System.currentTimeMillis();
99 }
100
101 public void messageReceived(TidyMessage message)
102 {
103 if (message.getLevel().equals(TidyMessage.Level.ERROR))
104 {
105 parseErrors++;
106 }
107 else if (message.getLevel().equals(TidyMessage.Level.WARNING))
108 {
109 parseWarnings++;
110 }
111 messages.add(message);
112 }
113
114 /***
115 * @return Returns the requestID.
116 */
117 public Object getRequestID()
118 {
119 return requestID;
120 }
121
122 /***
123 * @param requestID The requestID to set.
124 */
125 public void setRequestID(Object requestID)
126 {
127 this.requestID = requestID;
128 }
129
130 /***
131 * @return Returns the html.
132 */
133 public String getHtmlInput()
134 {
135 return html;
136 }
137
138 /***
139 * @param html The html to set.
140 */
141 public void setHtmlInput(String html)
142 {
143 this.html = html;
144 }
145
146 /***
147 * @return Returns the parseErrors.
148 */
149 public int getParseErrors()
150 {
151 return parseErrors;
152 }
153
154 /***
155 * @param parseErrors The parseErrors to set.
156 */
157 public void setParseErrors(int parseErrors)
158 {
159 this.parseErrors = parseErrors;
160 }
161
162 /***
163 * @return Returns the parseWarnings.
164 */
165 public int getParseWarnings()
166 {
167 return parseWarnings;
168 }
169
170 /***
171 * @param parseWarnings The parseWarnings to set.
172 */
173 public void setParseWarnings(int parseWarnings)
174 {
175 this.parseWarnings = parseWarnings;
176 }
177
178 /***
179 * @return Returns the report.
180 */
181 public String getReport()
182 {
183 return report;
184 }
185
186 /***
187 * @param report The report to set.
188 */
189 public void setReport(String report)
190 {
191 this.report = report;
192 }
193
194 /***
195 * @return Returns the messages.
196 */
197 public List getMessages()
198 {
199 return messages;
200 }
201
202 /***
203 * @return Returns the parsTime.
204 */
205 public long getParsTime()
206 {
207 return parsTime;
208 }
209
210 /***
211 * @param parsTime The parsTime to set.
212 */
213 public void setParsTime(long parsTime)
214 {
215 this.parsTime = parsTime;
216 }
217
218 /***
219 * @return Returns the when.
220 */
221 public long getWhen()
222 {
223 return when;
224 }
225
226 /***
227 * @return Returns the htmlResult.
228 */
229 public String getHtmlOutput()
230 {
231 return htmlResult;
232 }
233
234 /***
235 * @param html The htmlResult to set.
236 */
237 public void setHtmlOutput(String html)
238 {
239 this.htmlResult = html;
240 }
241
242 /***
243 * @return Returns the part of ImageName shown as icon or null to use default implementation
244 */
245 public String getImageName()
246 {
247 String imageName = "unknown";
248 if (getParseErrors() != 0)
249 {
250 imageName = "error";
251 }
252 else if (getParseWarnings() != 0)
253 {
254 imageName = "warning";
255 }
256 else
257 {
258 imageName = "ok";
259 }
260 return imageName;
261 }
262 }