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 package org.w3c.tidy;
55
56 /**
57 * Message sent to listeners for validation errors/warnings and info.
58 * @see Tidy#setMessageListener(TidyMessageListener)
59 * @author Fabrizio Giustina
60 * @version $Revision: 779 $ ($Author: fgiust $)
61 */
62 public final class TidyMessage
63 {
64
65 /**
66 * Line in the source file (can be 0 if the message is not related to a particular line, such as a summary message).
67 */
68 private int line;
69
70 /**
71 * Column in the source file (can be 0 if the message is not related to a particular column, such as a summary
72 * message).
73 */
74 private int column;
75
76 /**
77 * Level for this message. Can be TidyMessage.Level.SUMMARY | TidyMessage.Level.INFO | TidyMessage.Level.WARNING |
78 * TidyMessage.Level.ERROR.
79 */
80 private Level level;
81
82 /**
83 * Formatted text for this message.
84 */
85 private String message;
86
87 /**
88 * Tidy internal error code.
89 */
90 private int errorCode;
91
92 /**
93 * Instantiates a new message.
94 * @param errorCode Tidy internal error code.
95 * @param line Line number in the source file
96 * @param column Column number in the source file
97 * @param level severity
98 * @param message message text
99 */
100 public TidyMessage(int errorCode, int line, int column, Level level, String message)
101 {
102 this.errorCode = errorCode;
103 this.line = line;
104 this.column = column;
105 this.level = level;
106 this.message = message;
107 }
108
109 /**
110 * Getter for <code>errorCode</code>.
111 * @return Returns the errorCode.
112 */
113 public int getErrorCode()
114 {
115 return this.errorCode;
116 }
117
118 /**
119 * Getter for <code>column</code>.
120 * @return Returns the column.
121 */
122 public int getColumn()
123 {
124 return this.column;
125 }
126
127 /**
128 * Getter for <code>level</code>.
129 * @return Returns the level.
130 */
131 public Level getLevel()
132 {
133 return this.level;
134 }
135
136 /**
137 * Getter for <code>line</code>.
138 * @return Returns the line.
139 */
140 public int getLine()
141 {
142 return this.line;
143 }
144
145 /**
146 * Getter for <code>message</code>.
147 * @return Returns the message.
148 */
149 public String getMessage()
150 {
151 return this.message;
152 }
153
154 /**
155 * Message severity enumeration.
156 * @author fgiust
157 * @version $Revision: 779 $ ($Author: fgiust $)
158 */
159 public static final class Level implements Comparable
160 {
161
162 /**
163 * level = summary (0).
164 */
165 public static final Level SUMMARY = new Level(0);
166
167 /**
168 * level = info (1).
169 */
170 public static final Level INFO = new Level(1);
171
172 /**
173 * level = warning (2).
174 */
175 public static final Level WARNING = new Level(2);
176
177 /**
178 * level = error (3).
179 */
180 public static final Level ERROR = new Level(3);
181
182 /**
183 * short value for this level.
184 */
185 private short code;
186
187 /**
188 * Instantiates a new message with the given code.
189 * @param code int value for this level
190 */
191 private Level(int code)
192 {
193 this.code = (short) code;
194 }
195
196 /**
197 * Returns the int value for this level.
198 * @return int value for this level
199 */
200 public short getCode()
201 {
202 return this.code;
203 }
204
205 /**
206 * Returns the Level instance corresponding to the given int value.
207 * @param code int value for the level
208 * @return Level instance
209 */
210 public static Level fromCode(int code)
211 {
212 switch (code)
213 {
214 case 0 :
215 return SUMMARY;
216 case 1 :
217 return INFO;
218 case 2 :
219 return WARNING;
220 case 3 :
221 return ERROR;
222
223 default :
224 return null;
225 }
226 }
227
228 /**
229 * @see java.lang.Comparable#compareTo(Object)
230 */
231 public int compareTo(Object object)
232 {
233 return this.code - ((Level) object).code;
234 }
235
236 /**
237 * @see java.lang.Object#equals(Object)
238 */
239 public boolean equals(Object object)
240 {
241 if (!(object instanceof Level))
242 {
243 return false;
244 }
245 return this.code == ((Level) object).code;
246 }
247
248 /**
249 * @see java.lang.Object#toString()
250 */
251 public String toString()
252 {
253 switch (code)
254 {
255 case 0 :
256 return "SUMMARY";
257 case 1 :
258 return "INFO";
259 case 2 :
260 return "WARNING";
261 case 3 :
262 return "ERROR";
263
264 default :
265
266 return "?";
267 }
268 }
269
270 /**
271 * @see java.lang.Object#hashCode()
272 */
273 public int hashCode()
274 {
275
276 return super.hashCode();
277 }
278 }
279
280 }