| 1 5 6 package org.w3c.tidy; 7 8 35 36 import java.text.MessageFormat ; 37 import java.util.ResourceBundle ; 38 import java.util.MissingResourceException ; 39 import java.io.PrintWriter ; 40 41 public class Report { 42 43 44 public static final String ACCESS_URL = "http://www.w3.org/WAI/GL"; 45 46 public static final String RELEASE_DATE = "4th August 2000"; 47 48 public static String currentFile; 49 50 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 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 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 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 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 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 res = null; 131 132 static { 133 try { 134 res = ResourceBundle.getBundle("org/w3c/tidy/TidyMessages"); 135 } 136 catch (MissingResourceException e) { 137 throw new Error (e.toString()); 138 } 139 } 140 141 public static void tidyPrint( PrintWriter p, String msg ) 142 { 143 p.print( msg ); 144 } 145 146 public static void tidyPrintln( PrintWriter p, String msg ) 147 { 148 p.println( msg ); 149 } 150 151 public static void tidyPrintln( PrintWriter p ) 152 { 153 p.println(); 154 } 155 156 public static void showVersion(PrintWriter 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 180 public static void unknownOption(String option) 181 { 182 optionerrors++; 183 try { 184 System.err.println( 185 MessageFormat.format( res.getString("unknown_option"), 186 new Object [] {option} )); 187 } 188 catch ( MissingResourceException e ) { 189 System.err.println( e.toString() ); 190 } 191 } 192 193 194 public static void badArgument(String option) 195 { 196 optionerrors++; 197 try { 198 System.err.println( 199 MessageFormat.format( res.getString("bad_argument"), 200 new Object [] {option} )); 201 } 202 catch ( MissingResourceException e ) { 203 System.err.println( e.toString() ); 204 } 205 } 206 207 208 public static void position(Lexer lexer) 209 { 210 try { 211 212 if (lexer.configuration.Emacs) 213 { 214 tidyPrint(lexer.errout, 215 MessageFormat.format( res.getString("emacs_format"), 216 new Object [] {currentFile, new Integer (lexer.lines), 217 new Integer (lexer.columns)} )); 218 tidyPrint(lexer.errout, " "); 219 } 220 else 221 { 222 tidyPrint(lexer.errout, 223 MessageFormat.format( res.getString("line_column"), 224 new Object [] {new Integer (lexer.lines), new Integer (lexer.columns)} )); 225 } 226 } 227 catch ( MissingResourceException 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 [] {new Integer (c)} )); 247 } 248 catch ( MissingResourceException 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 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 [] {entity} )); 272 } 273 catch ( MissingResourceException 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 [] {entity} )); 283 } 284 catch ( MissingResourceException 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 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 attr, short code) 304 { 305 lexer.warnings++; 306 307 308 if (lexer.errors > 6) 309 return; 310 311 if (lexer.configuration.ShowWarnings) 312 { 313 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 [] {attr} )); 328 } 329 catch ( MissingResourceException 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 [] {attr} )); 342 } 343 catch ( MissingResourceException 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 [] {attr} )); 356 } 357 catch ( MissingResourceException 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 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 [] {attr} )); 384 } 385 catch ( MissingResourceException 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 [] {attr} )); 398 } 399 catch ( MissingResourceException 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 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 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 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 [] {attr} )); 452 } 453 catch ( MissingResourceException 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 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 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 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 509 if (lexer.errors > 6) 510 return; 511 512 if (lexer.configuration.ShowWarnings) 513 { 514 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 [] {element.element} )); 529 } 530 catch ( MissingResourceException 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 [] {element.element} )); 540 } 541 catch ( MissingResourceException 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 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 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 [] {element.element} )); 574 } 575 catch ( MissingResourceException 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 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 [] {element.element} )); 593 } 594 catch ( MissingResourceException 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 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 [] {element.element} )); 612 } 613 catch ( MissingResourceException 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 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 [] {node.element} )); 633 } 634 catch ( MissingResourceException 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 [] {node.element} )); 644 if (element != null) 645 tidyPrint(lexer.errout, 646 MessageFormat.format( res.getString("unexpected_endtag_suffix"), 647 new Object [] {element.element} )); 648 } 649 catch ( MissingResourceException 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 [] {node.element} )); 659 &
|