changed .classpath to relative PATH ECLIPSE_HOME
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / tidy / Report.java
1 /*
2  * @(#)Report.java   1.11 2000/08/16
3  *
4  */
5
6 package net.sourceforge.phpdt.tidy;
7
8 /**
9  *  
10  * Error/informational message reporter.
11  *
12  * You should only need to edit the file TidyMessages.properties
13  * to localize HTML tidy.
14  *
15  * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
16  * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
17  * HTML Tidy Release 4 Aug 2000</a>
18  *
19  * @author  Dave Raggett <dsr@w3.org>
20  * @author  Andy Quick <ac.quick@sympatico.ca> (translation to Java)
21  * @version 1.0, 1999/05/22
22  * @version 1.0.1, 1999/05/29
23  * @version 1.1, 1999/06/18 Java Bean
24  * @version 1.2, 1999/07/10 Tidy Release 7 Jul 1999
25  * @version 1.3, 1999/07/30 Tidy Release 26 Jul 1999
26  * @version 1.4, 1999/09/04 DOM support
27  * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
28  * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
29  * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
30  * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
31  * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
32  * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
33  * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
34  */
35
36 import java.io.PrintWriter;
37 import java.text.MessageFormat;
38 import java.util.Hashtable;
39 import java.util.MissingResourceException;
40 import java.util.ResourceBundle;
41
42 import org.eclipse.core.resources.IMarker;
43 import org.eclipse.core.runtime.CoreException;
44 import org.eclipse.ui.texteditor.MarkerUtilities;
45
46 public class Report {
47
48   /* used to point to Web Accessibility Guidelines */
49   public static final String ACCESS_URL = "http://www.w3.org/WAI/GL";
50
51   public static final String RELEASE_DATE = "4th August 2000";
52
53   public static String currentFile; /* sasdjb 01May00 for GNU Emacs error parsing */
54
55   /* error codes for entities */
56
57   public static final short MISSING_SEMICOLON = 1;
58   public static final short UNKNOWN_ENTITY = 2;
59   public static final short UNESCAPED_AMPERSAND = 3;
60
61   /* error codes for element messages */
62
63   public static final short MISSING_ENDTAG_FOR = 1;
64   public static final short MISSING_ENDTAG_BEFORE = 2;
65   public static final short DISCARDING_UNEXPECTED = 3;
66   public static final short NESTED_EMPHASIS = 4;
67   public static final short NON_MATCHING_ENDTAG = 5;
68   public static final short TAG_NOT_ALLOWED_IN = 6;
69   public static final short MISSING_STARTTAG = 7;
70   public static final short UNEXPECTED_ENDTAG = 8;
71   public static final short USING_BR_INPLACE_OF = 9;
72   public static final short INSERTING_TAG = 10;
73   public static final short SUSPECTED_MISSING_QUOTE = 11;
74   public static final short MISSING_TITLE_ELEMENT = 12;
75   public static final short DUPLICATE_FRAMESET = 13;
76   public static final short CANT_BE_NESTED = 14;
77   public static final short OBSOLETE_ELEMENT = 15;
78   public static final short PROPRIETARY_ELEMENT = 16;
79   public static final short UNKNOWN_ELEMENT = 17;
80   public static final short TRIM_EMPTY_ELEMENT = 18;
81   public static final short COERCE_TO_ENDTAG = 19;
82   public static final short ILLEGAL_NESTING = 20;
83   public static final short NOFRAMES_CONTENT = 21;
84   public static final short CONTENT_AFTER_BODY = 22;
85   public static final short INCONSISTENT_VERSION = 23;
86   public static final short MALFORMED_COMMENT = 24;
87   public static final short BAD_COMMENT_CHARS = 25;
88   public static final short BAD_XML_COMMENT = 26;
89   public static final short BAD_CDATA_CONTENT = 27;
90   public static final short INCONSISTENT_NAMESPACE = 28;
91   public static final short DOCTYPE_AFTER_TAGS = 29;
92   public static final short MALFORMED_DOCTYPE = 30;
93   public static final short UNEXPECTED_END_OF_FILE = 31;
94   public static final short DTYPE_NOT_UPPER_CASE = 32;
95   public static final short TOO_MANY_ELEMENTS = 33;
96
97   /* error codes used for attribute messages */
98
99   public static final short UNKNOWN_ATTRIBUTE = 1;
100   public static final short MISSING_ATTRIBUTE = 2;
101   public static final short MISSING_ATTR_VALUE = 3;
102   public static final short BAD_ATTRIBUTE_VALUE = 4;
103   public static final short UNEXPECTED_GT = 5;
104   public static final short PROPRIETARY_ATTR_VALUE = 6;
105   public static final short REPEATED_ATTRIBUTE = 7;
106   public static final short MISSING_IMAGEMAP = 8;
107   public static final short XML_ATTRIBUTE_VALUE = 9;
108   public static final short UNEXPECTED_QUOTEMARK = 10;
109   public static final short ID_NAME_MISMATCH = 11;
110
111   /* accessibility flaws */
112
113   public static final short MISSING_IMAGE_ALT = 1;
114   public static final short MISSING_LINK_ALT = 2;
115   public static final short MISSING_SUMMARY = 4;
116   public static final short MISSING_IMAGE_MAP = 8;
117   public static final short USING_FRAMES = 16;
118   public static final short USING_NOFRAMES = 32;
119
120   /* presentation flaws */
121
122   public static final short USING_SPACER = 1;
123   public static final short USING_LAYER = 2;
124   public static final short USING_NOBR = 4;
125   public static final short USING_FONT = 8;
126   public static final short USING_BODY = 16;
127
128   /* character encoding errors */
129   public static final short WINDOWS_CHARS = 1;
130   public static final short NON_ASCII = 2;
131   public static final short FOUND_UTF16 = 4;
132
133   private static short optionerrors;
134
135   private static ResourceBundle res = null;
136
137   static {
138     try {
139       res = ResourceBundle.getBundle("net/sourceforge/phpdt/tidy/TidyMessages");
140     } catch (MissingResourceException e) {
141       throw new Error(e.toString());
142     }
143   }
144
145   public static void tidyPrint(PrintWriter p, String msg) {
146     p.print(msg);
147   }
148
149   public static void tidyPrintln(PrintWriter p, String msg) {
150     p.println(msg);
151   }
152
153   public static void tidyPrintln(PrintWriter p) {
154     p.println();
155   }
156
157   public static void showVersion(PrintWriter p) {
158     tidyPrintln(p, "Java HTML Tidy release date: " + RELEASE_DATE);
159     tidyPrintln(p, "See http://www.w3.org/People/Raggett for details");
160   }
161
162   public static void tag(Lexer lexer, Node tag) {
163     if (tag != null) {
164       if (tag.type == Node.StartTag)
165         tidyPrint(lexer.errout, "<" + tag.element + ">");
166       else if (tag.type == Node.EndTag)
167         tidyPrint(lexer.errout, "</" + tag.element + ">");
168       else if (tag.type == Node.DocTypeTag)
169         tidyPrint(lexer.errout, "<!DOCTYPE>");
170       else if (tag.type == Node.TextNode)
171         tidyPrint(lexer.errout, "plain text");
172       else
173         tidyPrint(lexer.errout, tag.element);
174     }
175   }
176
177   public static void tag(StringBuffer errorMessage, Lexer lexer, Node tag) {
178     if (tag != null) {
179       if (tag.type == Node.StartTag) {
180         tidyPrint(lexer.errout, "<" + tag.element + ">");
181         errorMessage.append("<" + tag.element + ">");
182       } else if (tag.type == Node.EndTag) {
183         tidyPrint(lexer.errout, "</" + tag.element + ">");
184         errorMessage.append("</" + tag.element + ">");
185       } else if (tag.type == Node.DocTypeTag) {
186         tidyPrint(lexer.errout, "<!DOCTYPE>");
187         errorMessage.append("</" + tag.element + ">");
188       } else if (tag.type == Node.TextNode) {
189         tidyPrint(lexer.errout, "plain text");
190         errorMessage.append("plain text");
191       } else {
192         tidyPrint(lexer.errout, tag.element);
193         errorMessage.append(tag.element);
194       }
195     }
196   }
197
198   /* lexer is not defined when this is called */
199   public static void unknownOption(String option) {
200     optionerrors++;
201     try {
202       System.err.println(MessageFormat.format(res.getString("unknown_option"), new Object[] { option }));
203     } catch (MissingResourceException e) {
204       System.err.println(e.toString());
205     }
206   }
207
208   /* lexer is not defined when this is called */
209   public static void badArgument(String option) {
210     optionerrors++;
211     try {
212       System.err.println(MessageFormat.format(res.getString("bad_argument"), new Object[] { option }));
213     } catch (MissingResourceException e) {
214       System.err.println(e.toString());
215     }
216   }
217
218   public static void position(Lexer lexer) {
219     try {
220       /* Change formatting to be parsable by GNU Emacs */
221       if (lexer.configuration.Emacs) {
222         tidyPrint(
223           lexer.errout,
224           MessageFormat.format(
225             res.getString("emacs_format"),
226             new Object[] { currentFile, new Integer(lexer.lines), new Integer(lexer.columns)}));
227         tidyPrint(lexer.errout, " ");
228       } else /* traditional format */ {
229         tidyPrint(
230           lexer.errout,
231           MessageFormat.format(res.getString("line_column"), new Object[] { new Integer(lexer.lines), new Integer(lexer.columns)}));
232       }
233     } catch (MissingResourceException e) {
234       lexer.errout.println(e.toString());
235     }
236   }
237
238   public static void encodingError(Lexer lexer, short code, int c) {
239     lexer.warnings++;
240
241     if (lexer.configuration.ShowWarnings) {
242       position(lexer);
243
244       if (code == WINDOWS_CHARS) {
245         lexer.badChars |= WINDOWS_CHARS;
246         try {
247           Hashtable attributes = new Hashtable();
248           StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
249           MarkerUtilities.setLineNumber(attributes, lexer.lines);
250           tidyPrint(lexer.errout, MessageFormat.format(res.getString("illegal_char"), new Object[] { new Integer(c)}));
251           errorMessage.append(MessageFormat.format(res.getString("illegal_char"), new Object[] { new Integer(c)}));
252           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
253           // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
254           // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
255           try {
256             MarkerUtilities.setMessage(attributes, errorMessage.toString());
257             MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
258           } catch (CoreException e) {
259           }
260         } catch (MissingResourceException e) {
261           lexer.errout.println(e.toString());
262         }
263       }
264
265       tidyPrintln(lexer.errout);
266     }
267   }
268
269   public static void entityError(Lexer lexer, short code, String entity, int c) {
270     lexer.warnings++;
271
272     if (lexer.configuration.ShowWarnings) {
273       position(lexer);
274       Hashtable attributes = new Hashtable();
275       StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
276       MarkerUtilities.setLineNumber(attributes, lexer.lines);
277
278       if (code == MISSING_SEMICOLON) {
279         try {
280           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_semicolon"), new Object[] { entity }));
281           errorMessage.append(MessageFormat.format(res.getString("missing_semicolon"), new Object[] { entity }));
282         } catch (MissingResourceException e) {
283           lexer.errout.println(e.toString());
284         }
285       } else if (code == UNKNOWN_ENTITY) {
286         try {
287           tidyPrint(lexer.errout, MessageFormat.format(res.getString("unknown_entity"), new Object[] { entity }));
288           errorMessage.append(MessageFormat.format(res.getString("unknown_entity"), new Object[] { entity }));
289         } catch (MissingResourceException e) {
290           lexer.errout.println(e.toString());
291         }
292       } else if (code == UNESCAPED_AMPERSAND) {
293         try {
294           tidyPrint(lexer.errout, res.getString("unescaped_ampersand"));
295           errorMessage.append(res.getString("unescaped_ampersand"));
296         } catch (MissingResourceException e) {
297           lexer.errout.println(e.toString());
298         }
299       }
300       attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
301       // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
302       // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
303       try {
304         MarkerUtilities.setMessage(attributes, errorMessage.toString());
305         MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
306       } catch (CoreException e) {
307       }
308       tidyPrintln(lexer.errout);
309     }
310   }
311
312   public static void attrError(Lexer lexer, Node node, String attr, short code) {
313     lexer.warnings++;
314
315     /* keep quiet after 6 errors */
316     if (lexer.errors > 6)
317       return;
318
319     Hashtable attributes = new Hashtable();
320     StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
321
322     if (lexer.configuration.ShowWarnings) {
323       /* on end of file adjust reported position to end of input */
324       if (code == UNEXPECTED_END_OF_FILE) {
325         lexer.lines = lexer.in.curline;
326         lexer.columns = lexer.in.curcol;
327       }
328
329       position(lexer);
330
331       MarkerUtilities.setLineNumber(attributes, lexer.lines);
332
333       if (code == UNKNOWN_ATTRIBUTE) {
334         try {
335           tidyPrint(lexer.errout, MessageFormat.format(res.getString("unknown_attribute"), new Object[] { attr }));
336           errorMessage.append(MessageFormat.format(res.getString("unknown_attribute"), new Object[] { attr }));
337         } catch (MissingResourceException e) {
338           lexer.errout.println(e.toString());
339         }
340       } else if (code == MISSING_ATTRIBUTE) {
341         try {
342           tidyPrint(lexer.errout, res.getString("warning"));
343           errorMessage.append(res.getString("warning"));
344           tag(errorMessage, lexer, node);
345           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_attribute"), new Object[] { attr }));
346           errorMessage.append(MessageFormat.format(res.getString("missing_attribute"), new Object[] { attr }));
347         } catch (MissingResourceException e) {
348           lexer.errout.println(e.toString());
349         }
350       } else if (code == MISSING_ATTR_VALUE) {
351         try {
352           tidyPrint(lexer.errout, res.getString("warning"));
353           errorMessage.append(res.getString("warning"));
354           tag(errorMessage, lexer, node);
355           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_attr_value"), new Object[] { attr }));
356           errorMessage.append(MessageFormat.format(res.getString("missing_attr_value"), new Object[] { attr }));
357         } catch (MissingResourceException e) {
358           lexer.errout.println(e.toString());
359         }
360       } else if (code == MISSING_IMAGEMAP) {
361         try {
362           tidyPrint(lexer.errout, res.getString("warning"));
363           errorMessage.append(res.getString("warning"));
364           tag(errorMessage, lexer, node);
365           tidyPrint(lexer.errout, res.getString("missing_imagemap"));
366           errorMessage.append(res.getString("missing_imagemap"));
367         } catch (MissingResourceException e) {
368           lexer.errout.println(e.toString());
369         }
370         lexer.badAccess |= MISSING_IMAGE_MAP;
371       } else if (code == BAD_ATTRIBUTE_VALUE) {
372         try {
373           tidyPrint(lexer.errout, res.getString("warning"));
374           errorMessage.append(res.getString("warning"));
375           tag(lexer, node);
376           tidyPrint(lexer.errout, MessageFormat.format(res.getString("bad_attribute_value"), new Object[] { attr }));
377           errorMessage.append(MessageFormat.format(res.getString("bad_attribute_value"), new Object[] { attr }));
378         } catch (MissingResourceException e) {
379           lexer.errout.println(e.toString());
380         }
381       } else if (code == XML_ATTRIBUTE_VALUE) {
382         try {
383           tidyPrint(lexer.errout, res.getString("warning"));
384           errorMessage.append(res.getString("warning"));
385           tag(errorMessage, lexer, node);
386           tidyPrint(lexer.errout, MessageFormat.format(res.getString("xml_attribute_value"), new Object[] { attr }));
387           errorMessage.append(MessageFormat.format(res.getString("xml_attribute_value"), new Object[] { attr }));
388         } catch (MissingResourceException e) {
389           lexer.errout.println(e.toString());
390         }
391       } else if (code == UNEXPECTED_GT) {
392         try {
393           tidyPrint(lexer.errout, res.getString("error"));
394           errorMessage.append(res.getString("error"));
395           tag(errorMessage, lexer, node);
396           tidyPrint(lexer.errout, res.getString("unexpected_gt"));
397           errorMessage.append(res.getString("unexpected_gt"));
398         } catch (MissingResourceException e) {
399           lexer.errout.println(e.toString());
400         }
401         lexer.errors++;
402         ;
403       } else if (code == UNEXPECTED_QUOTEMARK) {
404         try {
405           tidyPrint(lexer.errout, res.getString("warning"));
406           errorMessage.append(res.getString("warning"));
407           tag(errorMessage, lexer, node);
408           tidyPrint(lexer.errout, res.getString("unexpected_quotemark"));
409           errorMessage.append(res.getString("unexpected_quotemark"));
410         } catch (MissingResourceException e) {
411           lexer.errout.println(e.toString());
412         }
413       } else if (code == REPEATED_ATTRIBUTE) {
414         try {
415           tidyPrint(lexer.errout, res.getString("warning"));
416           errorMessage.append(res.getString("warning"));
417           tag(errorMessage, lexer, node);
418           tidyPrint(lexer.errout, res.getString("repeated_attribute"));
419           errorMessage.append(res.getString("repeated_attribute"));
420         } catch (MissingResourceException e) {
421           lexer.errout.println(e.toString());
422         }
423       } else if (code == PROPRIETARY_ATTR_VALUE) {
424         try {
425           tidyPrint(lexer.errout, res.getString("warning"));
426           errorMessage.append(res.getString("warning"));
427           tag(errorMessage, lexer, node);
428           tidyPrint(lexer.errout, MessageFormat.format(res.getString("proprietary_attr_value"), new Object[] { attr }));
429           errorMessage.append(MessageFormat.format(res.getString("proprietary_attr_value"), new Object[] { attr }));
430         } catch (MissingResourceException e) {
431           lexer.errout.println(e.toString());
432         }
433       } else if (code == UNEXPECTED_END_OF_FILE) {
434         try {
435           tidyPrint(lexer.errout, res.getString("unexpected_end_of_file"));
436           errorMessage.append(res.getString("unexpected_end_of_file"));
437         } catch (MissingResourceException e) {
438           lexer.errout.println(e.toString());
439         }
440       } else if (code == ID_NAME_MISMATCH) {
441         try {
442           tidyPrint(lexer.errout, res.getString("warning"));
443           errorMessage.append(res.getString("warning"));
444           tag(errorMessage, lexer, node);
445           tidyPrint(lexer.errout, res.getString("id_name_mismatch"));
446           errorMessage.append(res.getString("id_name_mismatch"));
447         } catch (MissingResourceException e) {
448           lexer.errout.println(e.toString());
449         }
450       }
451
452       // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
453       attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
454       // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
455       try {
456         MarkerUtilities.setMessage(attributes, errorMessage.toString());
457         MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
458       } catch (CoreException e) {
459       }
460       tidyPrintln(lexer.errout);
461     } else if (code == UNEXPECTED_GT) {
462       position(lexer);
463       MarkerUtilities.setLineNumber(attributes, lexer.lines);
464       try {
465         tidyPrint(lexer.errout, res.getString("error"));
466         errorMessage.append(res.getString("error"));
467         tag(errorMessage, lexer, node);
468         tidyPrint(lexer.errout, res.getString("unexpected_gt"));
469         errorMessage.append(res.getString("unexpected_gt"));
470         attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
471         // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
472         // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
473         try {
474           MarkerUtilities.setMessage(attributes, errorMessage.toString());
475           MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
476         } catch (CoreException e) {
477         }
478       } catch (MissingResourceException e) {
479         lexer.errout.println(e.toString());
480       }
481       tidyPrintln(lexer.errout);
482       lexer.errors++;
483       ;
484     }
485
486   }
487
488   public static void warning(Lexer lexer, Node element, Node node, short code) {
489
490     TagTable tt = lexer.configuration.tt;
491
492     lexer.warnings++;
493
494     /* keep quiet after 6 errors */
495     if (lexer.errors > 6)
496       return;
497
498     if (lexer.configuration.ShowWarnings) {
499
500       /* on end of file adjust reported position to end of input */
501       if (code == UNEXPECTED_END_OF_FILE) {
502         lexer.lines = lexer.in.curline;
503         lexer.columns = lexer.in.curcol;
504       }
505
506       position(lexer);
507       Hashtable attributes = new Hashtable();
508       StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
509
510       MarkerUtilities.setLineNumber(attributes, lexer.lines);
511
512       if (code == MISSING_ENDTAG_FOR) {
513         try {
514           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_endtag_for"), new Object[] { element.element }));
515           errorMessage.append(MessageFormat.format(res.getString("missing_endtag_for"), new Object[] { element.element }));
516         } catch (MissingResourceException e) {
517           lexer.errout.println(e.toString());
518         }
519       } else if (code == MISSING_ENDTAG_BEFORE) {
520         try {
521           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_endtag_before"), new Object[] { element.element }));
522           errorMessage.append(MessageFormat.format(res.getString("missing_endtag_before"), new Object[] { element.element }));
523
524         } catch (MissingResourceException e) {
525           lexer.errout.println(e.toString());
526         }
527         tag(errorMessage, lexer, node);
528       } else if (code == DISCARDING_UNEXPECTED) {
529         try {
530           tidyPrint(lexer.errout, res.getString("discarding_unexpected"));
531           errorMessage.append(res.getString("discarding_unexpected"));
532         } catch (MissingResourceException e) {
533           lexer.errout.println(e.toString());
534         }
535         tag(errorMessage, lexer, node);
536       } else if (code == NESTED_EMPHASIS) {
537         try {
538           tidyPrint(lexer.errout, res.getString("nested_emphasis"));
539           errorMessage.append(res.getString("nested_emphasis"));
540         } catch (MissingResourceException e) {
541           lexer.errout.println(e.toString());
542         }
543         tag(errorMessage, lexer, node);
544       } else if (code == COERCE_TO_ENDTAG) {
545         try {
546           tidyPrint(lexer.errout, MessageFormat.format(res.getString("coerce_to_endtag"), new Object[] { element.element }));
547           errorMessage.append(MessageFormat.format(res.getString("coerce_to_endtag"), new Object[] { element.element }));
548         } catch (MissingResourceException e) {
549           lexer.errout.println(e.toString());
550         }
551       } else if (code == NON_MATCHING_ENDTAG) {
552         try {
553           tidyPrint(lexer.errout, res.getString("non_matching_endtag_1"));
554           errorMessage.append(res.getString("non_matching_endtag_1"));
555         } catch (MissingResourceException e) {
556           lexer.errout.println(e.toString());
557         }
558         tag(errorMessage, lexer, node);
559         try {
560           tidyPrint(lexer.errout, MessageFormat.format(res.getString("non_matching_endtag_2"), new Object[] { element.element }));
561           errorMessage.append(MessageFormat.format(res.getString("non_matching_endtag_2"), new Object[] { element.element }));
562         } catch (MissingResourceException e) {
563           lexer.errout.println(e.toString());
564         }
565       } else if (code == TAG_NOT_ALLOWED_IN) {
566         try {
567           tidyPrint(lexer.errout, res.getString("warning"));
568           errorMessage.append(res.getString("warning"));
569         } catch (MissingResourceException e) {
570           lexer.errout.println(e.toString());
571         }
572         tag(errorMessage, lexer, node);
573         try {
574           tidyPrint(lexer.errout, MessageFormat.format(res.getString("tag_not_allowed_in"), new Object[] { element.element }));
575           errorMessage.append(MessageFormat.format(res.getString("tag_not_allowed_in"), new Object[] { element.element }));
576         } catch (MissingResourceException e) {
577           lexer.errout.println(e.toString());
578         }
579       } else if (code == DOCTYPE_AFTER_TAGS) {
580         try {
581           tidyPrint(lexer.errout, res.getString("doctype_after_tags"));
582           errorMessage.append(res.getString("doctype_after_tags"));
583         } catch (MissingResourceException e) {
584           lexer.errout.println(e.toString());
585         }
586       } else if (code == MISSING_STARTTAG) {
587         try {
588           tidyPrint(lexer.errout, MessageFormat.format(res.getString("missing_starttag"), new Object[] { node.element }));
589           errorMessage.append(MessageFormat.format(res.getString("missing_starttag"), new Object[] { node.element }));
590         } catch (MissingResourceException e) {
591           lexer.errout.println(e.toString());
592         }
593       } else if (code == UNEXPECTED_ENDTAG) {
594         try {
595           tidyPrint(lexer.errout, MessageFormat.format(res.getString("unexpected_endtag"), new Object[] { node.element }));
596           if (element != null)
597             tidyPrint(
598               lexer.errout,
599               MessageFormat.format(res.getString("unexpected_endtag_suffix"), new Object[] { element.element }));
600           errorMessage.append(MessageFormat.format(res.getString("unexpected_endtag"), new Object[] { node.element }));
601         } catch (MissingResourceException e) {
602           lexer.errout.println(e.toString());
603         }
604       } else if (code == TOO_MANY_ELEMENTS) {
605         try {
606           tidyPrint(lexer.errout, MessageFormat.format(res.getString("too_many_elements"), new Object[] { node.element }));
607           if (element != null)
608             tidyPrint(
609               lexer.errout,
610               MessageFormat.format(res.getString("too_many_elements_suffix"), new Object[] { element.element }));
611           errorMessage.append(MessageFormat.format(res.getString("too_many_elements"), new Object[] { node.element }));
612         } catch (MissingResourceException e) {
613           lexer.errout.println(e.toString());
614         }
615       } else if (code == USING_BR_INPLACE_OF) {
616         try {
617           tidyPrint(lexer.errout, res.getString("using_br_inplace_of"));
618           errorMessage.append(res.getString("using_br_inplace_of"));
619         } catch (MissingResourceException e) {
620           lexer.errout.println(e.toString());
621         }
622         tag(errorMessage, lexer, node);
623       } else if (code == INSERTING_TAG) {
624         try {
625           tidyPrint(lexer.errout, MessageFormat.format(res.getString("inserting_tag"), new Object[] { node.element }));
626           errorMessage.append(MessageFormat.format(res.getString("inserting_tag"), new Object[] { node.element }));
627         } catch (MissingResourceException e) {
628           lexer.errout.println(e.toString());
629         }
630       } else if (code == CANT_BE_NESTED) {
631         try {
632           tidyPrint(lexer.errout, res.getString("warning"));
633           errorMessage.append(res.getString("warning"));
634         } catch (MissingResourceException e) {
635           lexer.errout.println(e.toString());
636         }
637         tag(errorMessage, lexer, node);
638         try {
639           tidyPrint(lexer.errout, res.getString("cant_be_nested"));
640           errorMessage.append(res.getString("cant_be_nested"));
641         } catch (MissingResourceException e) {
642           lexer.errout.println(e.toString());
643         }
644       } else if (code == PROPRIETARY_ELEMENT) {
645         try {
646           tidyPrint(lexer.errout, res.getString("warning"));
647           errorMessage.append(res.getString("warning"));
648         } catch (MissingResourceException e) {
649           lexer.errout.println(e.toString());
650         }
651         tag(errorMessage, lexer, node);
652         try {
653           tidyPrint(lexer.errout, res.getString("proprietary_element"));
654           errorMessage.append(res.getString("proprietary_element"));
655         } catch (MissingResourceException e) {
656           lexer.errout.println(e.toString());
657         }
658
659         if (node.tag == tt.tagLayer)
660           lexer.badLayout |= USING_LAYER;
661         else if (node.tag == tt.tagSpacer)
662           lexer.badLayout |= USING_SPACER;
663         else if (node.tag == tt.tagNobr)
664           lexer.badLayout |= USING_NOBR;
665       } else if (code == OBSOLETE_ELEMENT) {
666         try {
667           if (element.tag != null && (element.tag.model & Dict.CM_OBSOLETE) != 0) {
668             tidyPrint(lexer.errout, res.getString("obsolete_element"));
669             errorMessage.append(res.getString("obsolete_element"));
670           } else {
671             tidyPrint(lexer.errout, res.getString("replacing_element"));
672             errorMessage.append(res.getString("replacing_element"));
673           }
674
675         } catch (MissingResourceException e) {
676           lexer.errout.println(e.toString());
677         }
678         tag(errorMessage, lexer, element);
679         try {
680           tidyPrint(lexer.errout, res.getString("by"));
681           errorMessage.append(res.getString("by"));
682         } catch (MissingResourceException e) {
683           lexer.errout.println(e.toString());
684         }
685         tag(errorMessage, lexer, node);
686       } else if (code == TRIM_EMPTY_ELEMENT) {
687         try {
688           tidyPrint(lexer.errout, res.getString("trim_empty_element"));
689           errorMessage.append(res.getString("trim_empty_element"));
690         } catch (MissingResourceException e) {
691           lexer.errout.println(e.toString());
692         }
693         tag(errorMessage, lexer, element);
694       } else if (code == MISSING_TITLE_ELEMENT) {
695         try {
696           tidyPrint(lexer.errout, res.getString("missing_title_element"));
697           errorMessage.append(res.getString("missing_title_element"));
698         } catch (MissingResourceException e) {
699           lexer.errout.println(e.toString());
700         }
701       } else if (code == ILLEGAL_NESTING) {
702         try {
703           tidyPrint(lexer.errout, res.getString("warning"));
704           errorMessage.append(res.getString("warning"));
705         } catch (MissingResourceException e) {
706           lexer.errout.println(e.toString());
707         }
708         tag(errorMessage, lexer, element);
709         try {
710           tidyPrint(lexer.errout, res.getString("illegal_nesting"));
711           errorMessage.append(res.getString("illegal_nesting"));
712         } catch (MissingResourceException e) {
713           lexer.errout.println(e.toString());
714         }
715       } else if (code == NOFRAMES_CONTENT) {
716         try {
717           tidyPrint(lexer.errout, res.getString("warning"));
718           errorMessage.append(res.getString("warning"));
719         } catch (MissingResourceException e) {
720           lexer.errout.println(e.toString());
721         }
722         tag(errorMessage, lexer, node);
723         try {
724           tidyPrint(lexer.errout, res.getString("noframes_content"));
725           errorMessage.append(res.getString("noframes_content"));
726         } catch (MissingResourceException e) {
727           lexer.errout.println(e.toString());
728         }
729       } else if (code == INCONSISTENT_VERSION) {
730         try {
731           tidyPrint(lexer.errout, res.getString("inconsistent_version"));
732           errorMessage.append(res.getString("inconsistent_version"));
733         } catch (MissingResourceException e) {
734           lexer.errout.println(e.toString());
735         }
736       } else if (code == MALFORMED_DOCTYPE) {
737         try {
738           tidyPrint(lexer.errout, res.getString("malformed_doctype"));
739           errorMessage.append(res.getString("malformed_doctype"));
740         } catch (MissingResourceException e) {
741           lexer.errout.println(e.toString());
742         }
743       } else if (code == CONTENT_AFTER_BODY) {
744         try {
745           tidyPrint(lexer.errout, res.getString("content_after_body"));
746           errorMessage.append(res.getString("content_after_body"));
747         } catch (MissingResourceException e) {
748           lexer.errout.println(e.toString());
749         }
750       } else if (code == MALFORMED_COMMENT) {
751         try {
752           tidyPrint(lexer.errout, res.getString("malformed_comment"));
753           errorMessage.append(res.getString("malformed_comment"));
754         } catch (MissingResourceException e) {
755           lexer.errout.println(e.toString());
756         }
757       } else if (code == BAD_COMMENT_CHARS) {
758         try {
759           tidyPrint(lexer.errout, res.getString("bad_comment_chars"));
760           errorMessage.append(res.getString("bad_comment_chars"));
761         } catch (MissingResourceException e) {
762           lexer.errout.println(e.toString());
763         }
764       } else if (code == BAD_XML_COMMENT) {
765         try {
766           tidyPrint(lexer.errout, res.getString("bad_xml_comment"));
767           errorMessage.append(res.getString("bad_xml_comment"));
768         } catch (MissingResourceException e) {
769           lexer.errout.println(e.toString());
770         }
771       } else if (code == BAD_CDATA_CONTENT) {
772         try {
773           tidyPrint(lexer.errout, res.getString("bad_cdata_content"));
774           errorMessage.append(res.getString("bad_cdata_content"));
775         } catch (MissingResourceException e) {
776           lexer.errout.println(e.toString());
777         }
778       } else if (code == INCONSISTENT_NAMESPACE) {
779         try {
780           tidyPrint(lexer.errout, res.getString("inconsistent_namespace"));
781           errorMessage.append(res.getString("inconsistent_namespace"));
782         } catch (MissingResourceException e) {
783           lexer.errout.println(e.toString());
784         }
785       } else if (code == DTYPE_NOT_UPPER_CASE) {
786         try {
787           tidyPrint(lexer.errout, res.getString("dtype_not_upper_case"));
788           errorMessage.append(res.getString("dtype_not_upper_case"));
789         } catch (MissingResourceException e) {
790           lexer.errout.println(e.toString());
791         }
792       } else if (code == UNEXPECTED_END_OF_FILE) {
793         try {
794           tidyPrint(lexer.errout, res.getString("unexpected_end_of_file"));
795           errorMessage.append(res.getString("unexpected_end_of_file"));
796         } catch (MissingResourceException e) {
797           lexer.errout.println(e.toString());
798         }
799         tag(errorMessage, lexer, element);
800       }
801       //       attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
802       attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
803       //  attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
804       try {
805         MarkerUtilities.setMessage(attributes, errorMessage.toString());
806         MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
807       } catch (CoreException e) {
808       }
809       tidyPrintln(lexer.errout);
810     }
811   }
812
813   public static void error(Lexer lexer, Node element, Node node, short code) {
814     lexer.warnings++;
815
816     /* keep quiet after 6 errors */
817     if (lexer.errors > 6)
818       return;
819
820     lexer.errors++;
821
822     position(lexer);
823
824     Hashtable attributes = new Hashtable();
825     StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
826
827     MarkerUtilities.setLineNumber(attributes, lexer.lines);
828
829     if (code == SUSPECTED_MISSING_QUOTE) {
830       try {
831         tidyPrint(lexer.errout, res.getString("suspected_missing_quote"));
832         errorMessage.append(res.getString("suspected_missing_quote"));
833
834       } catch (MissingResourceException e) {
835         lexer.errout.println(e.toString());
836       }
837     } else if (code == DUPLICATE_FRAMESET) {
838       try {
839         tidyPrint(lexer.errout, res.getString("duplicate_frameset"));
840         errorMessage.append(res.getString("duplicate_frameset"));
841       } catch (MissingResourceException e) {
842         lexer.errout.println(e.toString());
843       }
844     } else if (code == UNKNOWN_ELEMENT) {
845       try {
846         tidyPrint(lexer.errout, res.getString("error"));
847         errorMessage.append(res.getString("error"));
848       } catch (MissingResourceException e) {
849         lexer.errout.println(e.toString());
850       }
851       tag(errorMessage, lexer, node);
852       try {
853         tidyPrint(lexer.errout, res.getString("unknown_element"));
854         errorMessage.append(res.getString("unknown_element"));
855       } catch (MissingResourceException e) {
856         lexer.errout.println(e.toString());
857       }
858     } else if (code == UNEXPECTED_ENDTAG) {
859       try {
860         tidyPrint(lexer.errout, MessageFormat.format(res.getString("unexpected_endtag"), new Object[] { node.element }));
861         errorMessage.append(MessageFormat.format(res.getString("unexpected_endtag"), new Object[] { node.element }));
862         if (element != null) {
863           tidyPrint(
864             lexer.errout,
865             MessageFormat.format(res.getString("unexpected_endtag_suffix"), new Object[] { element.element }));
866           errorMessage.append(MessageFormat.format(res.getString("unexpected_endtag_suffix"), new Object[] { element.element }));
867         }
868       } catch (MissingResourceException e) {
869         lexer.errout.println(e.toString());
870       }
871     }
872     attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
873     // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
874     // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
875     try {
876       MarkerUtilities.setMessage(attributes, errorMessage.toString());
877       MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
878     } catch (CoreException e) {
879     }
880     tidyPrintln(lexer.errout);
881   }
882
883   public static void errorSummary(Lexer lexer) {
884     /* adjust badAccess to that its null if frames are ok */
885     if ((lexer.badAccess & (USING_FRAMES | USING_NOFRAMES)) != 0) {
886       if (!(((lexer.badAccess & USING_FRAMES) != 0) && ((lexer.badAccess & USING_NOFRAMES) == 0)))
887         lexer.badAccess &= ~(USING_FRAMES | USING_NOFRAMES);
888     }
889
890     if (lexer.badChars != 0) {
891       if ((lexer.badChars & WINDOWS_CHARS) != 0) {
892         try {
893           tidyPrint(lexer.errout, res.getString("badchars_summary"));
894         } catch (MissingResourceException e) {
895           lexer.errout.println(e.toString());
896         }
897       }
898     }
899
900     if (lexer.badForm != 0) {
901       try {
902         tidyPrint(lexer.errout, res.getString("badform_summary"));
903       } catch (MissingResourceException e) {
904         lexer.errout.println(e.toString());
905       }
906     }
907
908     if (lexer.badAccess != 0) {
909       if ((lexer.badAccess & MISSING_SUMMARY) != 0) {
910         try {
911           tidyPrint(lexer.errout, res.getString("badaccess_missing_summary"));
912         } catch (MissingResourceException e) {
913           lexer.errout.println(e.toString());
914         }
915       }
916
917       if ((lexer.badAccess & MISSING_IMAGE_ALT) != 0) {
918         try {
919           tidyPrint(lexer.errout, res.getString("badaccess_missing_image_alt"));
920         } catch (MissingResourceException e) {
921           lexer.errout.println(e.toString());
922         }
923       }
924
925       if ((lexer.badAccess & MISSING_IMAGE_MAP) != 0) {
926         try {
927           tidyPrint(lexer.errout, res.getString("badaccess_missing_image_map"));
928         } catch (MissingResourceException e) {
929           lexer.errout.println(e.toString());
930         }
931       }
932
933       if ((lexer.badAccess & MISSING_LINK_ALT) != 0) {
934         try {
935           tidyPrint(lexer.errout, res.getString("badaccess_missing_link_alt"));
936         } catch (MissingResourceException e) {
937           lexer.errout.println(e.toString());
938         }
939       }
940
941       if (((lexer.badAccess & USING_FRAMES) != 0) && ((lexer.badAccess & USING_NOFRAMES) == 0)) {
942         try {
943           tidyPrint(lexer.errout, res.getString("badaccess_frames"));
944         } catch (MissingResourceException e) {
945           lexer.errout.println(e.toString());
946         }
947       }
948
949       try {
950         tidyPrint(lexer.errout, MessageFormat.format(res.getString("badaccess_summary"), new Object[] { ACCESS_URL }));
951       } catch (MissingResourceException e) {
952         lexer.errout.println(e.toString());
953       }
954     }
955
956     if (lexer.badLayout != 0) {
957       if ((lexer.badLayout & USING_LAYER) != 0) {
958         try {
959           tidyPrint(lexer.errout, res.getString("badlayout_using_layer"));
960         } catch (MissingResourceException e) {
961           lexer.errout.println(e.toString());
962         }
963       }
964
965       if ((lexer.badLayout & USING_SPACER) != 0) {
966         try {
967           tidyPrint(lexer.errout, res.getString("badlayout_using_spacer"));
968         } catch (MissingResourceException e) {
969           lexer.errout.println(e.toString());
970         }
971       }
972
973       if ((lexer.badLayout & USING_FONT) != 0) {
974         try {
975           tidyPrint(lexer.errout, res.getString("badlayout_using_font"));
976         } catch (MissingResourceException e) {
977           lexer.errout.println(e.toString());
978         }
979       }
980
981       if ((lexer.badLayout & USING_NOBR) != 0) {
982         try {
983           tidyPrint(lexer.errout, res.getString("badlayout_using_nobr"));
984         } catch (MissingResourceException e) {
985           lexer.errout.println(e.toString());
986         }
987       }
988
989       if ((lexer.badLayout & USING_BODY) != 0) {
990         try {
991           tidyPrint(lexer.errout, res.getString("badlayout_using_body"));
992         } catch (MissingResourceException e) {
993           lexer.errout.println(e.toString());
994         }
995       }
996     }
997   }
998
999   public static void unknownOption(PrintWriter errout, char c) {
1000     try {
1001       tidyPrintln(
1002         errout,
1003         MessageFormat.format(res.getString("unrecognized_option"), new Object[] { new String(new char[] { c })
1004       }));
1005     } catch (MissingResourceException e) {
1006       errout.println(e.toString());
1007     }
1008   }
1009
1010   public static void unknownFile(PrintWriter errout, String program, String file) {
1011     try {
1012       tidyPrintln(errout, MessageFormat.format(res.getString("unknown_file"), new Object[] { program, file }));
1013     } catch (MissingResourceException e) {
1014       errout.println(e.toString());
1015     }
1016   }
1017
1018   public static void needsAuthorIntervention(PrintWriter errout) {
1019     try {
1020       tidyPrintln(errout, res.getString("needs_author_intervention"));
1021     } catch (MissingResourceException e) {
1022       errout.println(e.toString());
1023     }
1024   }
1025
1026   public static void missingBody(PrintWriter errout) {
1027     try {
1028       tidyPrintln(errout, res.getString("missing_body"));
1029     } catch (MissingResourceException e) {
1030       errout.println(e.toString());
1031     }
1032   }
1033
1034   public static void reportNumberOfSlides(PrintWriter errout, int count) {
1035     try {
1036       tidyPrintln(errout, MessageFormat.format(res.getString("slides_found"), new Object[] { new Integer(count)}));
1037     } catch (MissingResourceException e) {
1038       errout.println(e.toString());
1039     }
1040   }
1041
1042   public static void generalInfo(PrintWriter errout) {
1043     try {
1044       tidyPrintln(errout, res.getString("general_info"));
1045     } catch (MissingResourceException e) {
1046       errout.println(e.toString());
1047     }
1048   }
1049
1050   public static void helloMessage(PrintWriter errout, String date, String filename) {
1051     currentFile = filename; /* for use with Gnu Emacs */
1052
1053     try {
1054       tidyPrintln(errout, MessageFormat.format(res.getString("hello_message"), new Object[] { date, filename }));
1055     } catch (MissingResourceException e) {
1056       errout.println(e.toString());
1057     }
1058   }
1059
1060   public static void reportVersion(PrintWriter errout, Lexer lexer, String filename, Node doctype) {
1061     int i, c;
1062     int state = 0;
1063     String vers = lexer.HTMLVersionName();
1064     MutableInteger cc = new MutableInteger();
1065
1066     try {
1067       if (doctype != null) {
1068         tidyPrint(errout, MessageFormat.format(res.getString("doctype_given"), new Object[] { filename }));
1069
1070         for (i = doctype.start; i < doctype.end; ++i) {
1071           c = (int) doctype.textarray[i];
1072
1073           /* look for UTF-8 multibyte character */
1074           if (c < 0) {
1075             i += PPrint.getUTF8(doctype.textarray, i, cc);
1076             c = cc.value;
1077           }
1078
1079           if (c == (char) '"')
1080             ++state;
1081           else if (state == 1)
1082             errout.print((char) c);
1083         }
1084
1085         errout.print('"');
1086       }
1087
1088       tidyPrintln(
1089         errout,
1090         MessageFormat.format(
1091           res.getString("report_version"),
1092           new Object[] { filename, (vers != null ? vers : "HTML proprietary")}));
1093     } catch (MissingResourceException e) {
1094       errout.println(e.toString());
1095     }
1096   }
1097
1098   public static void reportNumWarnings(PrintWriter errout, Lexer lexer) {
1099     if (lexer.warnings > 0) {
1100       try {
1101         tidyPrintln(errout, MessageFormat.format(res.getString("num_warnings"), new Object[] { new Integer(lexer.warnings)}));
1102       } catch (MissingResourceException e) {
1103         errout.println(e.toString());
1104       }
1105     } else {
1106       try {
1107         tidyPrintln(errout, res.getString("no_warnings"));
1108       } catch (MissingResourceException e) {
1109         errout.println(e.toString());
1110       }
1111     }
1112   }
1113
1114   public static void helpText(PrintWriter out, String prog) {
1115     try {
1116       tidyPrintln(out, MessageFormat.format(res.getString("help_text"), new Object[] { prog, RELEASE_DATE }));
1117     } catch (MissingResourceException e) {
1118       out.println(e.toString());
1119     }
1120   }
1121
1122   public static void badTree(PrintWriter errout) {
1123     try {
1124       tidyPrintln(errout, res.getString("bad_tree"));
1125     } catch (MissingResourceException e) {
1126       errout.println(e.toString());
1127     }
1128   }
1129
1130 }