|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TidyMessage.java | 50% | 59% | 76.9% | 63% |
|
1 | /* | |
2 | * Java HTML Tidy - JTidy | |
3 | * HTML parser and pretty printer | |
4 | * | |
5 | * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts | |
6 | * Institute of Technology, Institut National de Recherche en | |
7 | * Informatique et en Automatique, Keio University). All Rights | |
8 | * Reserved. | |
9 | * | |
10 | * Contributing Author(s): | |
11 | * | |
12 | * Dave Raggett <dsr@w3.org> | |
13 | * Andy Quick <ac.quick@sympatico.ca> (translation to Java) | |
14 | * Gary L Peskin <garyp@firstech.com> (Java development) | |
15 | * Sami Lempinen <sami@lempinen.net> (release management) | |
16 | * Fabrizio Giustina <fgiust at users.sourceforge.net> | |
17 | * | |
18 | * The contributing author(s) would like to thank all those who | |
19 | * helped with testing, bug fixes, and patience. This wouldn't | |
20 | * have been possible without all of you. | |
21 | * | |
22 | * COPYRIGHT NOTICE: | |
23 | * | |
24 | * This software and documentation is provided "as is," and | |
25 | * the copyright holders and contributing author(s) make no | |
26 | * representations or warranties, express or implied, including | |
27 | * but not limited to, warranties of merchantability or fitness | |
28 | * for any particular purpose or that the use of the software or | |
29 | * documentation will not infringe any third party patents, | |
30 | * copyrights, trademarks or other rights. | |
31 | * | |
32 | * The copyright holders and contributing author(s) will not be | |
33 | * liable for any direct, indirect, special or consequential damages | |
34 | * arising out of any use of the software or documentation, even if | |
35 | * advised of the possibility of such damage. | |
36 | * | |
37 | * Permission is hereby granted to use, copy, modify, and distribute | |
38 | * this source code, or portions hereof, documentation and executables, | |
39 | * for any purpose, without fee, subject to the following restrictions: | |
40 | * | |
41 | * 1. The origin of this source code must not be misrepresented. | |
42 | * 2. Altered versions must be plainly marked as such and must | |
43 | * not be misrepresented as being the original source. | |
44 | * 3. This Copyright notice may not be removed or altered from any | |
45 | * source or altered source distribution. | |
46 | * | |
47 | * The copyright holders and contributing author(s) specifically | |
48 | * permit, without fee, and encourage the use of this source code | |
49 | * as a component for supporting the Hypertext Markup Language in | |
50 | * commercial products. If you use this source code in a product, | |
51 | * acknowledgment is not required but would be appreciated. | |
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 | 3415 | public TidyMessage(int errorCode, int line, int column, Level level, String message) |
101 | { | |
102 | 3415 | this.errorCode = errorCode; |
103 | 3415 | this.line = line; |
104 | 3415 | this.column = column; |
105 | 3415 | this.level = level; |
106 | 3415 | this.message = message; |
107 | } | |
108 | ||
109 | /** | |
110 | * Getter for <code>errorCode</code>. | |
111 | * @return Returns the errorCode. | |
112 | */ | |
113 | 2042 | public int getErrorCode() |
114 | { | |
115 | 2042 | return this.errorCode; |
116 | } | |
117 | ||
118 | /** | |
119 | * Getter for <code>column</code>. | |
120 | * @return Returns the column. | |
121 | */ | |
122 | 6118 | public int getColumn() |
123 | { | |
124 | 6118 | return this.column; |
125 | } | |
126 | ||
127 | /** | |
128 | * Getter for <code>level</code>. | |
129 | * @return Returns the level. | |
130 | */ | |
131 | 2042 | public Level getLevel() |
132 | { | |
133 | 2042 | return this.level; |
134 | } | |
135 | ||
136 | /** | |
137 | * Getter for <code>line</code>. | |
138 | * @return Returns the line. | |
139 | */ | |
140 | 6118 | public int getLine() |
141 | { | |
142 | 6118 | return this.line; |
143 | } | |
144 | ||
145 | /** | |
146 | * Getter for <code>message</code>. | |
147 | * @return Returns the message. | |
148 | */ | |
149 | 22 | public String getMessage() |
150 | { | |
151 | 22 | 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 | 4 | private Level(int code) |
192 | { | |
193 | 4 | this.code = (short) code; |
194 | } | |
195 | ||
196 | /** | |
197 | * Returns the int value for this level. | |
198 | * @return int value for this level | |
199 | */ | |
200 | 4 | public short getCode() |
201 | { | |
202 | 4 | 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 | 1040 | public static Level fromCode(int code) |
211 | { | |
212 | 1040 | switch (code) |
213 | { | |
214 | 494 | case 0 : |
215 | 494 | return SUMMARY; |
216 | 7 | case 1 : |
217 | 7 | return INFO; |
218 | 526 | case 2 : |
219 | 526 | return WARNING; |
220 | 13 | case 3 : |
221 | 13 | return ERROR; |
222 | ||
223 | 0 | default : |
224 | 0 | return null; |
225 | } | |
226 | } | |
227 | ||
228 | /** | |
229 | * @see java.lang.Comparable#compareTo(Object) | |
230 | */ | |
231 | 0 | public int compareTo(Object object) |
232 | { | |
233 | 0 | return this.code - ((Level) object).code; |
234 | } | |
235 | ||
236 | /** | |
237 | * @see java.lang.Object#equals(Object) | |
238 | */ | |
239 | 1019 | public boolean equals(Object object) |
240 | { | |
241 | 1019 | if (!(object instanceof Level)) |
242 | { | |
243 | 0 | return false; |
244 | } | |
245 | 1019 | return this.code == ((Level) object).code; |
246 | } | |
247 | ||
248 | /** | |
249 | * @see java.lang.Object#toString() | |
250 | */ | |
251 | 0 | public String toString() |
252 | { | |
253 | 0 | switch (code) |
254 | { | |
255 | 0 | case 0 : |
256 | 0 | return "SUMMARY"; |
257 | 0 | case 1 : |
258 | 0 | return "INFO"; |
259 | 0 | case 2 : |
260 | 0 | return "WARNING"; |
261 | 0 | case 3 : |
262 | 0 | return "ERROR"; |
263 | ||
264 | 0 | default : |
265 | // should not happen | |
266 | 0 | return "?"; |
267 | } | |
268 | } | |
269 | ||
270 | /** | |
271 | * @see java.lang.Object#hashCode() | |
272 | */ | |
273 | 0 | public int hashCode() |
274 | { | |
275 | // new instances should not be created | |
276 | 0 | return super.hashCode(); |
277 | } | |
278 | } | |
279 | ||
280 | } |
|