2 * @(#)Report.java 1.11 2000/08/16
6 package net.sourceforge.phpdt.tidy;
10 * Error/informational message reporter.
12 * You should only need to edit the file TidyMessages.properties
13 * to localize HTML tidy.
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>
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
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;
42 import org.eclipse.core.resources.IMarker;
43 import org.eclipse.core.runtime.CoreException;
44 import org.eclipse.ui.texteditor.MarkerUtilities;
48 /* used to point to Web Accessibility Guidelines */
49 public static final String ACCESS_URL = "http://www.w3.org/WAI/GL";
51 public static final String RELEASE_DATE = "4th August 2000";
53 public static String currentFile; /* sasdjb 01May00 for GNU Emacs error parsing */
55 /* error codes for entities */
57 public static final short MISSING_SEMICOLON = 1;
58 public static final short UNKNOWN_ENTITY = 2;
59 public static final short UNESCAPED_AMPERSAND = 3;
61 /* error codes for element messages */
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;
97 /* error codes used for attribute messages */
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;
111 /* accessibility flaws */
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;
120 /* presentation flaws */
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;
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;
133 private static short optionerrors;
135 private static ResourceBundle res = null;
139 res = ResourceBundle.getBundle("net/sourceforge/phpdt/tidy/TidyMessages");
140 } catch (MissingResourceException e) {
141 throw new Error(e.toString());
145 public static void tidyPrint(PrintWriter p, String msg) {
149 public static void tidyPrintln(PrintWriter p, String msg) {
153 public static void tidyPrintln(PrintWriter p) {
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");
162 public static void tag(Lexer lexer, Node tag) {
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");
173 tidyPrint(lexer.errout, tag.element);
177 public static void tag(StringBuffer errorMessage, Lexer lexer, Node tag) {
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");
192 tidyPrint(lexer.errout, tag.element);
193 errorMessage.append(tag.element);
198 /* lexer is not defined when this is called */
199 public static void unknownOption(String option) {
202 System.err.println(MessageFormat.format(res.getString("unknown_option"), new Object[] { option }));
203 } catch (MissingResourceException e) {
204 System.err.println(e.toString());
208 /* lexer is not defined when this is called */
209 public static void badArgument(String option) {
212 System.err.println(MessageFormat.format(res.getString("bad_argument"), new Object[] { option }));
213 } catch (MissingResourceException e) {
214 System.err.println(e.toString());
218 public static void position(Lexer lexer) {
220 /* Change formatting to be parsable by GNU Emacs */
221 if (lexer.configuration.Emacs) {
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 */ {
231 MessageFormat.format(res.getString("line_column"), new Object[] { new Integer(lexer.lines), new Integer(lexer.columns)}));
233 } catch (MissingResourceException e) {
234 lexer.errout.println(e.toString());
238 public static void encodingError(Lexer lexer, short code, int c) {
241 if (lexer.configuration.ShowWarnings) {
244 if (code == WINDOWS_CHARS) {
245 lexer.badChars |= WINDOWS_CHARS;
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));
256 MarkerUtilities.setMessage(attributes, errorMessage.toString());
257 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
258 } catch (CoreException e) {
260 } catch (MissingResourceException e) {
261 lexer.errout.println(e.toString());
265 tidyPrintln(lexer.errout);
269 public static void entityError(Lexer lexer, short code, String entity, int c) {
272 if (lexer.configuration.ShowWarnings) {
274 Hashtable attributes = new Hashtable();
275 StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
276 MarkerUtilities.setLineNumber(attributes, lexer.lines);
278 if (code == MISSING_SEMICOLON) {
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());
285 } else if (code == UNKNOWN_ENTITY) {
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());
292 } else if (code == UNESCAPED_AMPERSAND) {
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());
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));
304 MarkerUtilities.setMessage(attributes, errorMessage.toString());
305 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
306 } catch (CoreException e) {
308 tidyPrintln(lexer.errout);
312 public static void attrError(Lexer lexer, Node node, String attr, short code) {
315 /* keep quiet after 6 errors */
316 if (lexer.errors > 6)
319 Hashtable attributes = new Hashtable();
320 StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
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;
331 MarkerUtilities.setLineNumber(attributes, lexer.lines);
333 if (code == UNKNOWN_ATTRIBUTE) {
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());
340 } else if (code == MISSING_ATTRIBUTE) {
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());
350 } else if (code == MISSING_ATTR_VALUE) {
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());
360 } else if (code == MISSING_IMAGEMAP) {
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());
370 lexer.badAccess |= MISSING_IMAGE_MAP;
371 } else if (code == BAD_ATTRIBUTE_VALUE) {
373 tidyPrint(lexer.errout, res.getString("warning"));
374 errorMessage.append(res.getString("warning"));
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());
381 } else if (code == XML_ATTRIBUTE_VALUE) {
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());
391 } else if (code == UNEXPECTED_GT) {
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());
403 } else if (code == UNEXPECTED_QUOTEMARK) {
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());
413 } else if (code == REPEATED_ATTRIBUTE) {
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());
423 } else if (code == PROPRIETARY_ATTR_VALUE) {
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());
433 } else if (code == UNEXPECTED_END_OF_FILE) {
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());
440 } else if (code == ID_NAME_MISMATCH) {
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());
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));
456 MarkerUtilities.setMessage(attributes, errorMessage.toString());
457 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
458 } catch (CoreException e) {
460 tidyPrintln(lexer.errout);
461 } else if (code == UNEXPECTED_GT) {
463 MarkerUtilities.setLineNumber(attributes, lexer.lines);
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));
474 MarkerUtilities.setMessage(attributes, errorMessage.toString());
475 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
476 } catch (CoreException e) {
478 } catch (MissingResourceException e) {
479 lexer.errout.println(e.toString());
481 tidyPrintln(lexer.errout);
488 public static void warning(Lexer lexer, Node element, Node node, short code) {
490 TagTable tt = lexer.configuration.tt;
494 /* keep quiet after 6 errors */
495 if (lexer.errors > 6)
498 if (lexer.configuration.ShowWarnings) {
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;
507 Hashtable attributes = new Hashtable();
508 StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
510 MarkerUtilities.setLineNumber(attributes, lexer.lines);
512 if (code == MISSING_ENDTAG_FOR) {
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());
519 } else if (code == MISSING_ENDTAG_BEFORE) {
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 }));
524 } catch (MissingResourceException e) {
525 lexer.errout.println(e.toString());
527 tag(errorMessage, lexer, node);
528 } else if (code == DISCARDING_UNEXPECTED) {
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());
535 tag(errorMessage, lexer, node);
536 } else if (code == NESTED_EMPHASIS) {
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());
543 tag(errorMessage, lexer, node);
544 } else if (code == COERCE_TO_ENDTAG) {
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());
551 } else if (code == NON_MATCHING_ENDTAG) {
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());
558 tag(errorMessage, lexer, node);
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());
565 } else if (code == TAG_NOT_ALLOWED_IN) {
567 tidyPrint(lexer.errout, res.getString("warning"));
568 errorMessage.append(res.getString("warning"));
569 } catch (MissingResourceException e) {
570 lexer.errout.println(e.toString());
572 tag(errorMessage, lexer, node);
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());
579 } else if (code == DOCTYPE_AFTER_TAGS) {
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());
586 } else if (code == MISSING_STARTTAG) {
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());
593 } else if (code == UNEXPECTED_ENDTAG) {
595 tidyPrint(lexer.errout, MessageFormat.format(res.getString("unexpected_endtag"), new Object[] { node.element }));
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());
604 } else if (code == TOO_MANY_ELEMENTS) {
606 tidyPrint(lexer.errout, MessageFormat.format(res.getString("too_many_elements"), new Object[] { node.element }));
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());
615 } else if (code == USING_BR_INPLACE_OF) {
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());
622 tag(errorMessage, lexer, node);
623 } else if (code == INSERTING_TAG) {
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());
630 } else if (code == CANT_BE_NESTED) {
632 tidyPrint(lexer.errout, res.getString("warning"));
633 errorMessage.append(res.getString("warning"));
634 } catch (MissingResourceException e) {
635 lexer.errout.println(e.toString());
637 tag(errorMessage, lexer, node);
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());
644 } else if (code == PROPRIETARY_ELEMENT) {
646 tidyPrint(lexer.errout, res.getString("warning"));
647 errorMessage.append(res.getString("warning"));
648 } catch (MissingResourceException e) {
649 lexer.errout.println(e.toString());
651 tag(errorMessage, lexer, node);
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());
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) {
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"));
671 tidyPrint(lexer.errout, res.getString("replacing_element"));
672 errorMessage.append(res.getString("replacing_element"));
675 } catch (MissingResourceException e) {
676 lexer.errout.println(e.toString());
678 tag(errorMessage, lexer, element);
680 tidyPrint(lexer.errout, res.getString("by"));
681 errorMessage.append(res.getString("by"));
682 } catch (MissingResourceException e) {
683 lexer.errout.println(e.toString());
685 tag(errorMessage, lexer, node);
686 } else if (code == TRIM_EMPTY_ELEMENT) {
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());
693 tag(errorMessage, lexer, element);
694 } else if (code == MISSING_TITLE_ELEMENT) {
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());
701 } else if (code == ILLEGAL_NESTING) {
703 tidyPrint(lexer.errout, res.getString("warning"));
704 errorMessage.append(res.getString("warning"));
705 } catch (MissingResourceException e) {
706 lexer.errout.println(e.toString());
708 tag(errorMessage, lexer, element);
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());
715 } else if (code == NOFRAMES_CONTENT) {
717 tidyPrint(lexer.errout, res.getString("warning"));
718 errorMessage.append(res.getString("warning"));
719 } catch (MissingResourceException e) {
720 lexer.errout.println(e.toString());
722 tag(errorMessage, lexer, node);
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());
729 } else if (code == INCONSISTENT_VERSION) {
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());
736 } else if (code == MALFORMED_DOCTYPE) {
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());
743 } else if (code == CONTENT_AFTER_BODY) {
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());
750 } else if (code == MALFORMED_COMMENT) {
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());
757 } else if (code == BAD_COMMENT_CHARS) {
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());
764 } else if (code == BAD_XML_COMMENT) {
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());
771 } else if (code == BAD_CDATA_CONTENT) {
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());
778 } else if (code == INCONSISTENT_NAMESPACE) {
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());
785 } else if (code == DTYPE_NOT_UPPER_CASE) {
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());
792 } else if (code == UNEXPECTED_END_OF_FILE) {
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());
799 tag(errorMessage, lexer, element);
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));
805 MarkerUtilities.setMessage(attributes, errorMessage.toString());
806 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
807 } catch (CoreException e) {
809 tidyPrintln(lexer.errout);
813 public static void error(Lexer lexer, Node element, Node node, short code) {
816 /* keep quiet after 6 errors */
817 if (lexer.errors > 6)
824 Hashtable attributes = new Hashtable();
825 StringBuffer errorMessage = new StringBuffer("Column " + lexer.columns + ": ");
827 MarkerUtilities.setLineNumber(attributes, lexer.lines);
829 if (code == SUSPECTED_MISSING_QUOTE) {
831 tidyPrint(lexer.errout, res.getString("suspected_missing_quote"));
832 errorMessage.append(res.getString("suspected_missing_quote"));
834 } catch (MissingResourceException e) {
835 lexer.errout.println(e.toString());
837 } else if (code == DUPLICATE_FRAMESET) {
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());
844 } else if (code == UNKNOWN_ELEMENT) {
846 tidyPrint(lexer.errout, res.getString("error"));
847 errorMessage.append(res.getString("error"));
848 } catch (MissingResourceException e) {
849 lexer.errout.println(e.toString());
851 tag(errorMessage, lexer, node);
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());
858 } else if (code == UNEXPECTED_ENDTAG) {
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) {
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 }));
868 } catch (MissingResourceException e) {
869 lexer.errout.println(e.toString());
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));
876 MarkerUtilities.setMessage(attributes, errorMessage.toString());
877 MarkerUtilities.createMarker(lexer.getIFile(), attributes, IMarker.PROBLEM);
878 } catch (CoreException e) {
880 tidyPrintln(lexer.errout);
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);
890 if (lexer.badChars != 0) {
891 if ((lexer.badChars & WINDOWS_CHARS) != 0) {
893 tidyPrint(lexer.errout, res.getString("badchars_summary"));
894 } catch (MissingResourceException e) {
895 lexer.errout.println(e.toString());
900 if (lexer.badForm != 0) {
902 tidyPrint(lexer.errout, res.getString("badform_summary"));
903 } catch (MissingResourceException e) {
904 lexer.errout.println(e.toString());
908 if (lexer.badAccess != 0) {
909 if ((lexer.badAccess & MISSING_SUMMARY) != 0) {
911 tidyPrint(lexer.errout, res.getString("badaccess_missing_summary"));
912 } catch (MissingResourceException e) {
913 lexer.errout.println(e.toString());
917 if ((lexer.badAccess & MISSING_IMAGE_ALT) != 0) {
919 tidyPrint(lexer.errout, res.getString("badaccess_missing_image_alt"));
920 } catch (MissingResourceException e) {
921 lexer.errout.println(e.toString());
925 if ((lexer.badAccess & MISSING_IMAGE_MAP) != 0) {
927 tidyPrint(lexer.errout, res.getString("badaccess_missing_image_map"));
928 } catch (MissingResourceException e) {
929 lexer.errout.println(e.toString());
933 if ((lexer.badAccess & MISSING_LINK_ALT) != 0) {
935 tidyPrint(lexer.errout, res.getString("badaccess_missing_link_alt"));
936 } catch (MissingResourceException e) {
937 lexer.errout.println(e.toString());
941 if (((lexer.badAccess & USING_FRAMES) != 0) && ((lexer.badAccess & USING_NOFRAMES) == 0)) {
943 tidyPrint(lexer.errout, res.getString("badaccess_frames"));
944 } catch (MissingResourceException e) {
945 lexer.errout.println(e.toString());
950 tidyPrint(lexer.errout, MessageFormat.format(res.getString("badaccess_summary"), new Object[] { ACCESS_URL }));
951 } catch (MissingResourceException e) {
952 lexer.errout.println(e.toString());
956 if (lexer.badLayout != 0) {
957 if ((lexer.badLayout & USING_LAYER) != 0) {
959 tidyPrint(lexer.errout, res.getString("badlayout_using_layer"));
960 } catch (MissingResourceException e) {
961 lexer.errout.println(e.toString());
965 if ((lexer.badLayout & USING_SPACER) != 0) {
967 tidyPrint(lexer.errout, res.getString("badlayout_using_spacer"));
968 } catch (MissingResourceException e) {
969 lexer.errout.println(e.toString());
973 if ((lexer.badLayout & USING_FONT) != 0) {
975 tidyPrint(lexer.errout, res.getString("badlayout_using_font"));
976 } catch (MissingResourceException e) {
977 lexer.errout.println(e.toString());
981 if ((lexer.badLayout & USING_NOBR) != 0) {
983 tidyPrint(lexer.errout, res.getString("badlayout_using_nobr"));
984 } catch (MissingResourceException e) {
985 lexer.errout.println(e.toString());
989 if ((lexer.badLayout & USING_BODY) != 0) {
991 tidyPrint(lexer.errout, res.getString("badlayout_using_body"));
992 } catch (MissingResourceException e) {
993 lexer.errout.println(e.toString());
999 public static void unknownOption(PrintWriter errout, char c) {
1003 MessageFormat.format(res.getString("unrecognized_option"), new Object[] { new String(new char[] { c })
1005 } catch (MissingResourceException e) {
1006 errout.println(e.toString());
1010 public static void unknownFile(PrintWriter errout, String program, String file) {
1012 tidyPrintln(errout, MessageFormat.format(res.getString("unknown_file"), new Object[] { program, file }));
1013 } catch (MissingResourceException e) {
1014 errout.println(e.toString());
1018 public static void needsAuthorIntervention(PrintWriter errout) {
1020 tidyPrintln(errout, res.getString("needs_author_intervention"));
1021 } catch (MissingResourceException e) {
1022 errout.println(e.toString());
1026 public static void missingBody(PrintWriter errout) {
1028 tidyPrintln(errout, res.getString("missing_body"));
1029 } catch (MissingResourceException e) {
1030 errout.println(e.toString());
1034 public static void reportNumberOfSlides(PrintWriter errout, int count) {
1036 tidyPrintln(errout, MessageFormat.format(res.getString("slides_found"), new Object[] { new Integer(count)}));
1037 } catch (MissingResourceException e) {
1038 errout.println(e.toString());
1042 public static void generalInfo(PrintWriter errout) {
1044 tidyPrintln(errout, res.getString("general_info"));
1045 } catch (MissingResourceException e) {
1046 errout.println(e.toString());
1050 public static void helloMessage(PrintWriter errout, String date, String filename) {
1051 currentFile = filename; /* for use with Gnu Emacs */
1054 tidyPrintln(errout, MessageFormat.format(res.getString("hello_message"), new Object[] { date, filename }));
1055 } catch (MissingResourceException e) {
1056 errout.println(e.toString());
1060 public static void reportVersion(PrintWriter errout, Lexer lexer, String filename, Node doctype) {
1063 String vers = lexer.HTMLVersionName();
1064 MutableInteger cc = new MutableInteger();
1067 if (doctype != null) {
1068 tidyPrint(errout, MessageFormat.format(res.getString("doctype_given"), new Object[] { filename }));
1070 for (i = doctype.start; i < doctype.end; ++i) {
1071 c = (int) doctype.textarray[i];
1073 /* look for UTF-8 multibyte character */
1075 i += PPrint.getUTF8(doctype.textarray, i, cc);
1079 if (c == (char) '"')
1081 else if (state == 1)
1082 errout.print((char) c);
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());
1098 public static void reportNumWarnings(PrintWriter errout, Lexer lexer) {
1099 if (lexer.warnings > 0) {
1101 tidyPrintln(errout, MessageFormat.format(res.getString("num_warnings"), new Object[] { new Integer(lexer.warnings)}));
1102 } catch (MissingResourceException e) {
1103 errout.println(e.toString());
1107 tidyPrintln(errout, res.getString("no_warnings"));
1108 } catch (MissingResourceException e) {
1109 errout.println(e.toString());
1114 public static void helpText(PrintWriter out, String prog) {
1116 tidyPrintln(out, MessageFormat.format(res.getString("help_text"), new Object[] { prog, RELEASE_DATE }));
1117 } catch (MissingResourceException e) {
1118 out.println(e.toString());
1122 public static void badTree(PrintWriter errout) {
1124 tidyPrintln(errout, res.getString("bad_tree"));
1125 } catch (MissingResourceException e) {
1126 errout.println(e.toString());