KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)Report.java 1.11 2000/08/16
3  *
4  */

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