KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > w3c > tidy > TidyMessage


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: 1.10 $ ($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 JavaDoc 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 JavaDoc 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 JavaDoc getMessage()
150     {
151         return this.message;
152     }
153
154     /**
155      * Message severity enumeration.
156      * @author fgiust
157      * @version $Revision: 1.10 $ ($Author: fgiust $)
158      */

159     public static final class Level implements Comparable JavaDoc
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 JavaDoc 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 JavaDoc 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 JavaDoc 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                     // should not happen
266
return "?";
267             }
268         }
269
270         /**
271          * @see java.lang.Object#hashCode()
272          */

273         public int hashCode()
274         {
275             // new instances should not be created
276
return super.hashCode();
277         }
278     }
279
280 }
Popular Tags