1 54 package org.w3c.tidy; 55 56 63 public final class TagCheckImpl 64 { 65 66 69 public static final TagCheck HTML = new CheckHTML(); 70 71 74 public static final TagCheck SCRIPT = new CheckSCRIPT(); 75 76 79 public static final TagCheck TABLE = new CheckTABLE(); 80 81 84 public static final TagCheck CAPTION = new CheckCaption(); 85 86 89 public static final TagCheck IMG = new CheckIMG(); 90 91 94 public static final TagCheck AREA = new CheckAREA(); 95 96 99 public static final TagCheck ANCHOR = new CheckAnchor(); 100 101 104 public static final TagCheck MAP = new CheckMap(); 105 106 109 public static final TagCheck STYLE = new CheckSTYLE(); 110 111 114 public static final TagCheck TABLECELL = new CheckTableCell(); 115 116 119 public static final TagCheck LINK = new CheckLINK(); 120 121 124 public static final TagCheck HR = new CheckHR(); 125 126 129 public static final TagCheck FORM = new CheckForm(); 130 131 134 public static final TagCheck META = new CheckMeta(); 135 136 139 private TagCheckImpl() 140 { 141 } 143 144 147 public static class CheckHTML implements TagCheck 148 { 149 150 153 private static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; 154 155 158 public void check(Lexer lexer, Node node) 159 { 160 161 AttVal attval; 162 AttVal xmlns; 163 164 xmlns = node.getAttrByName("xmlns"); 165 166 if (xmlns != null && XHTML_NAMESPACE.equals(xmlns.value)) 167 { 168 lexer.isvoyager = true; 169 if (!lexer.configuration.htmlOut) { 171 lexer.configuration.xHTML = true; } 173 lexer.configuration.xmlOut = true; 175 lexer.configuration.upperCaseTags = false; 176 lexer.configuration.upperCaseAttrs = false; 177 } 178 179 for (attval = node.attributes; attval != null; attval = attval.next) 180 { 181 attval.checkAttribute(lexer, node); 182 } 183 } 184 185 } 186 187 190 public static class CheckSCRIPT implements TagCheck 191 { 192 193 196 public void check(Lexer lexer, Node node) 197 { 198 AttVal lang, type; 199 200 node.checkAttributes(lexer); 201 202 lang = node.getAttrByName("language"); 203 type = node.getAttrByName("type"); 204 205 if (type == null) 206 { 207 AttVal missingType = new AttVal(null, null, '"', "type", ""); 208 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE); 209 210 if (lang != null) 212 { 213 String str = lang.value; 214 if ("javascript".equalsIgnoreCase(str) || "jscript".equalsIgnoreCase(str)) 215 { 216 node.addAttribute("type", "text/javascript"); 217 } 218 else if ("vbscript".equalsIgnoreCase(str)) 219 { 220 node.addAttribute("type", "text/vbscript"); 222 } 223 } 224 else 225 { 226 node.addAttribute("type", "text/javascript"); 227 } 228 } 229 } 230 231 } 232 233 236 public static class CheckTABLE implements TagCheck 237 { 238 239 242 public void check(Lexer lexer, Node node) 243 { 244 AttVal attval; 245 Attribute attribute; 246 boolean hasSummary = false; 247 248 for (attval = node.attributes; attval != null; attval = attval.next) 249 { 250 attribute = attval.checkAttribute(lexer, node); 251 252 if (attribute == AttributeTable.attrSummary) 253 { 254 hasSummary = true; 255 } 256 } 257 258 259 if (!hasSummary && lexer.doctype != Dict.VERS_HTML20 && lexer.doctype != Dict.VERS_HTML32) 260 { 261 lexer.badAccess |= Report.MISSING_SUMMARY; 262 263 } 267 268 269 if (lexer.configuration.xmlOut) 270 { 271 attval = node.getAttrByName("border"); 272 if (attval != null) 273 { 274 if (attval.value == null) 275 { 276 attval.value = "1"; 277 } 278 } 279 } 280 281 282 if ((attval = node.getAttrByName("height")) != null) 283 { 284 lexer.report.attrError(lexer, node, attval, Report.PROPRIETARY_ATTRIBUTE); 285 lexer.versions &= Dict.VERS_PROPRIETARY; 286 } 287 288 } 289 290 } 291 292 295 public static class CheckCaption implements TagCheck 296 { 297 298 301 public void check(Lexer lexer, Node node) 302 { 303 AttVal attval; 304 String value = null; 305 306 node.checkAttributes(lexer); 307 308 for (attval = node.attributes; attval != null; attval = attval.next) 309 { 310 if ("align".equalsIgnoreCase(attval.attribute)) 311 { 312 value = attval.value; 313 break; 314 } 315 } 316 317 if (value != null) 318 { 319 if ("left".equalsIgnoreCase(value) || "right".equalsIgnoreCase(value)) 320 { 321 lexer.constrainVersion(Dict.VERS_HTML40_LOOSE); 322 } 323 else if ("top".equalsIgnoreCase(value) || "bottom".equalsIgnoreCase(value)) 324 { 325 lexer.constrainVersion(~(Dict.VERS_HTML20 | Dict.VERS_HTML32)); 326 } 327 else 328 { 329 lexer.report.attrError(lexer, node, attval, Report.BAD_ATTRIBUTE_VALUE); 330 } 331 } 332 } 333 334 } 335 336 339 public static class CheckHR implements TagCheck 340 { 341 342 345 public void check(Lexer lexer, Node node) 346 { 347 AttVal av = node.getAttrByName("src"); 348 349 node.checkAttributes(lexer); 350 351 if (av != null) 352 { 353 lexer.report.attrError(lexer, node, av, Report.PROPRIETARY_ATTR_VALUE); 354 } 355 } 356 } 357 358 361 public static class CheckIMG implements TagCheck 362 { 363 364 367 public void check(Lexer lexer, Node node) 368 { 369 AttVal attval; 370 Attribute attribute; 371 boolean hasAlt = false; 372 boolean hasSrc = false; 373 boolean hasUseMap = false; 374 boolean hasIsMap = false; 375 boolean hasDataFld = false; 376 377 for (attval = node.attributes; attval != null; attval = attval.next) 378 { 379 attribute = attval.checkAttribute(lexer, node); 380 381 if (attribute == AttributeTable.attrAlt) 382 { 383 hasAlt = true; 384 } 385 else if (attribute == AttributeTable.attrSrc) 386 { 387 hasSrc = true; 388 } 389 else if (attribute == AttributeTable.attrUsemap) 390 { 391 hasUseMap = true; 392 } 393 else if (attribute == AttributeTable.attrIsmap) 394 { 395 hasIsMap = true; 396 } 397 else if (attribute == AttributeTable.attrDatafld) 398 { 399 hasDataFld = true; 400 } 401 else if (attribute == AttributeTable.attrWidth || attribute == AttributeTable.attrHeight) 402 { 403 lexer.constrainVersion(~Dict.VERS_HTML20); 404 } 405 } 406 407 if (!hasAlt) 408 { 409 lexer.badAccess |= Report.MISSING_IMAGE_ALT; 410 AttVal missingAlt = new AttVal(null, null, '"', "alt", ""); 411 lexer.report.attrError(lexer, node, missingAlt, Report.MISSING_ATTRIBUTE); 412 if (lexer.configuration.altText != null) 413 { 414 node.addAttribute("alt", lexer.configuration.altText); 415 } 416 } 417 418 if (!hasSrc && !hasDataFld) 419 { 420 AttVal missingSrc = new AttVal(null, null, '"', "src", ""); 421 lexer.report.attrError(lexer, node, missingSrc, Report.MISSING_ATTRIBUTE); 422 } 423 424 if (hasIsMap && !hasUseMap) 425 { 426 AttVal missingIsMap = new AttVal(null, null, '"', "ismap", ""); 427 lexer.report.attrError(lexer, node, missingIsMap, Report.MISSING_IMAGEMAP); 428 } 429 } 430 431 } 432 433 436 public static class CheckAREA implements TagCheck 437 { 438 439 442 public void check(Lexer lexer, Node node) 443 { 444 AttVal attval; 445 Attribute attribute; 446 boolean hasAlt = false; 447 boolean hasHref = false; 448 449 for (attval = node.attributes; attval != null; attval = attval.next) 450 { 451 attribute = attval.checkAttribute(lexer, node); 452 453 if (attribute == AttributeTable.attrAlt) 454 { 455 hasAlt = true; 456 } 457 else if (attribute == AttributeTable.attrHref) 458 { 459 hasHref = true; 460 } 461 } 462 463 if (!hasAlt) 464 { 465 lexer.badAccess |= Report.MISSING_LINK_ALT; 466 AttVal missingAlt = new AttVal(null, null, '"', "alt", ""); 467 lexer.report.attrError(lexer, node, missingAlt, Report.MISSING_ATTRIBUTE); 468 } 469 if (!hasHref) 470 { 471 AttVal missingHref = new AttVal(null, null, '"', "href", ""); 472 lexer.report.attrError(lexer, node, missingHref, Report.MISSING_ATTRIBUTE); 473 } 474 } 475 476 } 477 478 481 public static class CheckAnchor implements TagCheck 482 { 483 484 487 public void check(Lexer lexer, Node node) 488 { 489 node.checkAttributes(lexer); 490 491 lexer.fixId(node); 492 } 493 } 494 495 498 public static class CheckMap implements TagCheck 499 { 500 501 504 public void check(Lexer lexer, Node node) 505 { 506 node.checkAttributes(lexer); 507 508 lexer.fixId(node); 509 } 510 } 511 512 515 public static class CheckSTYLE implements TagCheck 516 { 517 518 521 public void check(Lexer lexer, Node node) 522 { 523 AttVal type = node.getAttrByName("type"); 524 525 node.checkAttributes(lexer); 526 527 if (type == null) 528 { 529 AttVal missingType = new AttVal(null, null, '"', "type", ""); 530 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE); 531 532 node.addAttribute("type", "text/css"); 533 } 534 } 535 } 536 537 540 public static class CheckForm implements TagCheck 541 { 542 543 546 public void check(Lexer lexer, Node node) 547 { 548 AttVal action = node.getAttrByName("action"); 549 550 node.checkAttributes(lexer); 551 552 if (action == null) 553 { 554 AttVal missingAttribute = new AttVal(null, null, '"', "action", ""); 555 lexer.report.attrError(lexer, node, missingAttribute, Report.MISSING_ATTRIBUTE); 556 } 557 } 558 } 559 560 563 public static class CheckMeta implements TagCheck 564 { 565 566 569 public void check(Lexer lexer, Node node) 570 { 571 AttVal content = node.getAttrByName("content"); 572 573 node.checkAttributes(lexer); 574 575 if (content == null) 576 { 577 AttVal missingAttribute = new AttVal(null, null, '"', "content", ""); 578 lexer.report.attrError(lexer, node, missingAttribute, Report.MISSING_ATTRIBUTE); 579 } 580 581 } 583 } 584 585 588 public static class CheckTableCell implements TagCheck 589 { 590 591 594 public void check(Lexer lexer, Node node) 595 { 596 node.checkAttributes(lexer); 597 598 600 if (node.getAttrByName("width") != null || node.getAttrByName("height") != null) 601 { 602 lexer.constrainVersion(~Dict.VERS_HTML40_STRICT); 603 } 604 } 605 } 606 607 610 public static class CheckLINK implements TagCheck 611 { 612 613 616 public void check(Lexer lexer, Node node) 617 { 618 AttVal rel = node.getAttrByName("rel"); 619 620 node.checkAttributes(lexer); 621 622 if (rel != null && rel.value != null && rel.value.equals("stylesheet")) 623 { 624 AttVal type = node.getAttrByName("type"); 625 626 if (type == null) 627 { 628 AttVal missingType = new AttVal(null, null, '"', "type", ""); 629 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE); 630 631 node.addAttribute("type", "text/css"); 632 } 633 } 634 } 635 } 636 637 } | Popular Tags |