Clover coverage report - Maven Clover report
Coverage timestamp: Tue Aug 1 2006 15:09:51 CEST
file stats: LOC: 637   Methods: 15
NCLOC: 336   Classes: 15
 
 Source file Conditionals Statements Methods TOTAL
TagCheckImpl.java 72.6% 80.1% 80% 77.5%
coverage coverage
 1    /*
 2    * Java HTML Tidy - JTidy
 3    * HTML parser and pretty printer
 4    *
 5    * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
 6    * Institute of Technology, Institut National de Recherche en
 7    * Informatique et en Automatique, Keio University). All Rights
 8    * Reserved.
 9    *
 10    * Contributing Author(s):
 11    *
 12    * Dave Raggett <dsr@w3.org>
 13    * Andy Quick <ac.quick@sympatico.ca> (translation to Java)
 14    * Gary L Peskin <garyp@firstech.com> (Java development)
 15    * Sami Lempinen <sami@lempinen.net> (release management)
 16    * Fabrizio Giustina <fgiust at users.sourceforge.net>
 17    *
 18    * The contributing author(s) would like to thank all those who
 19    * helped with testing, bug fixes, and patience. This wouldn't
 20    * have been possible without all of you.
 21    *
 22    * COPYRIGHT NOTICE:
 23    *
 24    * This software and documentation is provided "as is," and
 25    * the copyright holders and contributing author(s) make no
 26    * representations or warranties, express or implied, including
 27    * but not limited to, warranties of merchantability or fitness
 28    * for any particular purpose or that the use of the software or
 29    * documentation will not infringe any third party patents,
 30    * copyrights, trademarks or other rights.
 31    *
 32    * The copyright holders and contributing author(s) will not be
 33    * liable for any direct, indirect, special or consequential damages
 34    * arising out of any use of the software or documentation, even if
 35    * advised of the possibility of such damage.
 36    *
 37    * Permission is hereby granted to use, copy, modify, and distribute
 38    * this source code, or portions hereof, documentation and executables,
 39    * for any purpose, without fee, subject to the following restrictions:
 40    *
 41    * 1. The origin of this source code must not be misrepresented.
 42    * 2. Altered versions must be plainly marked as such and must
 43    * not be misrepresented as being the original source.
 44    * 3. This Copyright notice may not be removed or altered from any
 45    * source or altered source distribution.
 46    *
 47    * The copyright holders and contributing author(s) specifically
 48    * permit, without fee, and encourage the use of this source code
 49    * as a component for supporting the Hypertext Markup Language in
 50    * commercial products. If you use this source code in a product,
 51    * acknowledgment is not required but would be appreciated.
 52    *
 53    */
 54    package org.w3c.tidy;
 55   
 56    /**
 57    * Check HTML attributes implementation.
 58    * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
 59    * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
 60    * @author Fabrizio Giustina
 61    * @version $Revision: 779 $ ($Author: fgiust $)
 62    */
 63    public final class TagCheckImpl
 64    {
 65   
 66    /**
 67    * CheckHTML instance.
 68    */
 69    public static final TagCheck HTML = new CheckHTML();
 70   
 71    /**
 72    * CheckSCRIPT instance.
 73    */
 74    public static final TagCheck SCRIPT = new CheckSCRIPT();
 75   
 76    /**
 77    * CheckTABLE instance.
 78    */
 79    public static final TagCheck TABLE = new CheckTABLE();
 80   
 81    /**
 82    * CheckCaption instance.
 83    */
 84    public static final TagCheck CAPTION = new CheckCaption();
 85   
 86    /**
 87    * CheckIMG instance.
 88    */
 89    public static final TagCheck IMG = new CheckIMG();
 90   
 91    /**
 92    * CheckAREA instance.
 93    */
 94    public static final TagCheck AREA = new CheckAREA();
 95   
 96    /**
 97    * CheckAnchor instance.
 98    */
 99    public static final TagCheck ANCHOR = new CheckAnchor();
 100   
 101    /**
 102    * CheckMap instance.
 103    */
 104    public static final TagCheck MAP = new CheckMap();
 105   
 106    /**
 107    * CheckSTYLE instance.
 108    */
 109    public static final TagCheck STYLE = new CheckSTYLE();
 110   
 111    /**
 112    * CheckTableCell instance.
 113    */
 114    public static final TagCheck TABLECELL = new CheckTableCell();
 115   
 116    /**
 117    * CheckLINK instance.
 118    */
 119    public static final TagCheck LINK = new CheckLINK();
 120   
 121    /**
 122    * CheckHR instance.
 123    */
 124    public static final TagCheck HR = new CheckHR();
 125   
 126    /**
 127    * CheckForm instance.
 128    */
 129    public static final TagCheck FORM = new CheckForm();
 130   
 131    /**
 132    * CheckMeta instance.
 133    */
 134    public static final TagCheck META = new CheckMeta();
 135   
 136    /**
 137    * don't instantiate.
 138    */
 139  0 private TagCheckImpl()
 140    {
 141    // unused
 142    }
 143   
 144    /**
 145    * Checker implementation for html tag.
 146    */
 147    public static class CheckHTML implements TagCheck
 148    {
 149   
 150    /**
 151    * xhtml namepace String.
 152    */
 153    private static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
 154   
 155    /**
 156    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 157    */
 158  211 public void check(Lexer lexer, Node node)
 159    {
 160   
 161  211 AttVal attval;
 162  211 AttVal xmlns;
 163   
 164  211 xmlns = node.getAttrByName("xmlns");
 165   
 166  211 if (xmlns != null && XHTML_NAMESPACE.equals(xmlns.value))
 167    {
 168  64 lexer.isvoyager = true;
 169  64 if (!lexer.configuration.htmlOut) // Unless user has specified plain HTML output,
 170    {
 171  64 lexer.configuration.xHTML = true; // output format will be XHTML.
 172    }
 173    // adjust other config options, just as in Configuration
 174  64 lexer.configuration.xmlOut = true;
 175  64 lexer.configuration.upperCaseTags = false;
 176  64 lexer.configuration.upperCaseAttrs = false;
 177    }
 178   
 179  211 for (attval = node.attributes; attval != null; attval = attval.next)
 180    {
 181  109 attval.checkAttribute(lexer, node);
 182    }
 183    }
 184   
 185    }
 186   
 187    /**
 188    * Checker implementation for script tags.
 189    */
 190    public static class CheckSCRIPT implements TagCheck
 191    {
 192   
 193    /**
 194    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 195    */
 196  28 public void check(Lexer lexer, Node node)
 197    {
 198  28 AttVal lang, type;
 199   
 200  28 node.checkAttributes(lexer);
 201   
 202  28 lang = node.getAttrByName("language");
 203  28 type = node.getAttrByName("type");
 204   
 205  28 if (type == null)
 206    {
 207  11 AttVal missingType = new AttVal(null, null, '"', "type", "");
 208  11 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE);
 209   
 210    // check for javascript
 211  11 if (lang != null)
 212    {
 213  7 String str = lang.value;
 214  7 if ("javascript".equalsIgnoreCase(str) || "jscript".equalsIgnoreCase(str))
 215    {
 216  4 node.addAttribute("type", "text/javascript");
 217    }
 218  3 else if ("vbscript".equalsIgnoreCase(str))
 219    {
 220    // per Randy Waki 8/6/01
 221  0 node.addAttribute("type", "text/vbscript");
 222    }
 223    }
 224    else
 225    {
 226  4 node.addAttribute("type", "text/javascript");
 227    }
 228    }
 229    }
 230   
 231    }
 232   
 233    /**
 234    * Checker implementation for table.
 235    */
 236    public static class CheckTABLE implements TagCheck
 237    {
 238   
 239    /**
 240    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 241    */
 242  72 public void check(Lexer lexer, Node node)
 243    {
 244  72 AttVal attval;
 245  72 Attribute attribute;
 246  72 boolean hasSummary = false;
 247   
 248  72 for (attval = node.attributes; attval != null; attval = attval.next)
 249    {
 250  224 attribute = attval.checkAttribute(lexer, node);
 251   
 252  224 if (attribute == AttributeTable.attrSummary)
 253    {
 254  23 hasSummary = true;
 255    }
 256    }
 257   
 258    /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
 259  72 if (!hasSummary && lexer.doctype != Dict.VERS_HTML20 && lexer.doctype != Dict.VERS_HTML32)
 260    {
 261  48 lexer.badAccess |= Report.MISSING_SUMMARY;
 262   
 263    // summary is not required, should be only an accessibility warning
 264    // AttVal missingSummary = new AttVal(null, null, '"', "summary", "");
 265    // lexer.report.attrError(lexer, node, missingSummary, Report.MISSING_ATTRIBUTE);
 266    }
 267   
 268    /* convert <table border> to <table border="1"> */
 269  72 if (lexer.configuration.xmlOut)
 270    {
 271  6 attval = node.getAttrByName("border");
 272  6 if (attval != null)
 273    {
 274  1 if (attval.value == null)
 275    {
 276  0 attval.value = "1";
 277    }
 278    }
 279    }
 280   
 281    /* <table height="..."> is proprietary */
 282  ? if ((attval = node.getAttrByName("height")) != null)
 283    {
 284  7 lexer.report.attrError(lexer, node, attval, Report.PROPRIETARY_ATTRIBUTE);
 285  7 lexer.versions &= Dict.VERS_PROPRIETARY;
 286    }
 287   
 288    }
 289   
 290    }
 291   
 292    /**
 293    * Checker implementation for table caption.
 294    */
 295    public static class CheckCaption implements TagCheck
 296    {
 297   
 298    /**
 299    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 300    */
 301  0 public void check(Lexer lexer, Node node)
 302    {
 303  0 AttVal attval;
 304  0 String value = null;
 305   
 306  0 node.checkAttributes(lexer);
 307   
 308  0 for (attval = node.attributes; attval != null; attval = attval.next)
 309    {
 310  0 if ("align".equalsIgnoreCase(attval.attribute))
 311    {
 312  0 value = attval.value;
 313  0 break;
 314    }
 315    }
 316   
 317  0 if (value != null)
 318    {
 319  0 if ("left".equalsIgnoreCase(value) || "right".equalsIgnoreCase(value))
 320    {
 321  0 lexer.constrainVersion(Dict.VERS_HTML40_LOOSE);
 322    }
 323  0 else if ("top".equalsIgnoreCase(value) || "bottom".equalsIgnoreCase(value))
 324    {
 325  0 lexer.constrainVersion(~(Dict.VERS_HTML20 | Dict.VERS_HTML32));
 326    }
 327    else
 328    {
 329  0 lexer.report.attrError(lexer, node, attval, Report.BAD_ATTRIBUTE_VALUE);
 330    }
 331    }
 332    }
 333   
 334    }
 335   
 336    /**
 337    * Checker implementation for hr.
 338    */
 339    public static class CheckHR implements TagCheck
 340    {
 341   
 342    /**
 343    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 344    */
 345  61 public void check(Lexer lexer, Node node)
 346    {
 347  61 AttVal av = node.getAttrByName("src");
 348   
 349  61 node.checkAttributes(lexer);
 350   
 351  61 if (av != null)
 352    {
 353  0 lexer.report.attrError(lexer, node, av, Report.PROPRIETARY_ATTR_VALUE);
 354    }
 355    }
 356    }
 357   
 358    /**
 359    * Checker implementation for image tags.
 360    */
 361    public static class CheckIMG implements TagCheck
 362    {
 363   
 364    /**
 365    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 366    */
 367  188 public void check(Lexer lexer, Node node)
 368    {
 369  188 AttVal attval;
 370  188 Attribute attribute;
 371  188 boolean hasAlt = false;
 372  188 boolean hasSrc = false;
 373  188 boolean hasUseMap = false;
 374  188 boolean hasIsMap = false;
 375  188 boolean hasDataFld = false;
 376   
 377  188 for (attval = node.attributes; attval != null; attval = attval.next)
 378    {
 379  787 attribute = attval.checkAttribute(lexer, node);
 380   
 381  787 if (attribute == AttributeTable.attrAlt)
 382    {
 383  49 hasAlt = true;
 384    }
 385  738 else if (attribute == AttributeTable.attrSrc)
 386    {
 387  188 hasSrc = true;
 388    }
 389  550 else if (attribute == AttributeTable.attrUsemap)
 390    {
 391  1 hasUseMap = true;
 392    }
 393  549 else if (attribute == AttributeTable.attrIsmap)
 394    {
 395  1 hasIsMap = true;
 396    }
 397  548 else if (attribute == AttributeTable.attrDatafld)
 398    {
 399  0 hasDataFld = true;
 400    }
 401  548 else if (attribute == AttributeTable.attrWidth || attribute == AttributeTable.attrHeight)
 402    {
 403  318 lexer.constrainVersion(~Dict.VERS_HTML20);
 404    }
 405    }
 406   
 407  188 if (!hasAlt)
 408    {
 409  139 lexer.badAccess |= Report.MISSING_IMAGE_ALT;
 410  139 AttVal missingAlt = new AttVal(null, null, '"', "alt", "");
 411  139 lexer.report.attrError(lexer, node, missingAlt, Report.MISSING_ATTRIBUTE);
 412  139 if (lexer.configuration.altText != null)
 413    {
 414  1 node.addAttribute("alt", lexer.configuration.altText);
 415    }
 416    }
 417   
 418  188 if (!hasSrc && !hasDataFld)
 419    {
 420  0 AttVal missingSrc = new AttVal(null, null, '"', "src", "");
 421  0 lexer.report.attrError(lexer, node, missingSrc, Report.MISSING_ATTRIBUTE);
 422    }
 423   
 424  188 if (hasIsMap && !hasUseMap)
 425    {
 426  0 AttVal missingIsMap = new AttVal(null, null, '"', "ismap", "");
 427  0 lexer.report.attrError(lexer, node, missingIsMap, Report.MISSING_IMAGEMAP);
 428    }
 429    }
 430   
 431    }
 432   
 433    /**
 434    * Checker implementation for area.
 435    */
 436    public static class CheckAREA implements TagCheck
 437    {
 438   
 439    /**
 440    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 441    */
 442  1 public void check(Lexer lexer, Node node)
 443    {
 444  1 AttVal attval;
 445  1 Attribute attribute;
 446  1 boolean hasAlt = false;
 447  1 boolean hasHref = false;
 448   
 449  1 for (attval = node.attributes; attval != null; attval = attval.next)
 450    {
 451  5 attribute = attval.checkAttribute(lexer, node);
 452   
 453  5 if (attribute == AttributeTable.attrAlt)
 454    {
 455  0 hasAlt = true;
 456    }
 457  5 else if (attribute == AttributeTable.attrHref)
 458    {
 459  1 hasHref = true;
 460    }
 461    }
 462   
 463  1 if (!hasAlt)
 464    {
 465  1 lexer.badAccess |= Report.MISSING_LINK_ALT;
 466  1 AttVal missingAlt = new AttVal(null, null, '"', "alt", "");
 467  1 lexer.report.attrError(lexer, node, missingAlt, Report.MISSING_ATTRIBUTE);
 468    }
 469  1 if (!hasHref)
 470    {
 471  0 AttVal missingHref = new AttVal(null, null, '"', "href", "");
 472  0 lexer.report.attrError(lexer, node, missingHref, Report.MISSING_ATTRIBUTE);
 473    }
 474    }
 475   
 476    }
 477   
 478    /**
 479    * Checker implementation for anchors.
 480    */
 481    public static class CheckAnchor implements TagCheck
 482    {
 483   
 484    /**
 485    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 486    */
 487  1113 public void check(Lexer lexer, Node node)
 488    {
 489  1113 node.checkAttributes(lexer);
 490   
 491  1113 lexer.fixId(node);
 492    }
 493    }
 494   
 495    /**
 496    * Checker implementation for image maps.
 497    */
 498    public static class CheckMap implements TagCheck
 499    {
 500   
 501    /**
 502    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 503    */
 504  0 public void check(Lexer lexer, Node node)
 505    {
 506  0 node.checkAttributes(lexer);
 507   
 508  0 lexer.fixId(node);
 509    }
 510    }
 511   
 512    /**
 513    * Checker implementation for style tags.
 514    */
 515    public static class CheckSTYLE implements TagCheck
 516    {
 517   
 518    /**
 519    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 520    */
 521  6 public void check(Lexer lexer, Node node)
 522    {
 523  6 AttVal type = node.getAttrByName("type");
 524   
 525  6 node.checkAttributes(lexer);
 526   
 527  6 if (type == null)
 528    {
 529  3 AttVal missingType = new AttVal(null, null, '"', "type", "");
 530  3 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE);
 531   
 532  3 node.addAttribute("type", "text/css");
 533    }
 534    }
 535    }
 536   
 537    /**
 538    * Checker implementation for forms. Reports missing action attribute.
 539    */
 540    public static class CheckForm implements TagCheck
 541    {
 542   
 543    /**
 544    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 545    */
 546  17 public void check(Lexer lexer, Node node)
 547    {
 548  17 AttVal action = node.getAttrByName("action");
 549   
 550  17 node.checkAttributes(lexer);
 551   
 552  17 if (action == null)
 553    {
 554  4 AttVal missingAttribute = new AttVal(null, null, '"', "action", "");
 555  4 lexer.report.attrError(lexer, node, missingAttribute, Report.MISSING_ATTRIBUTE);
 556    }
 557    }
 558    }
 559   
 560    /**
 561    * Checker implementation for meta tags. Reports missing content attribute.
 562    */
 563    public static class CheckMeta implements TagCheck
 564    {
 565   
 566    /**
 567    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 568    */
 569  51 public void check(Lexer lexer, Node node)
 570    {
 571  51 AttVal content = node.getAttrByName("content");
 572   
 573  51 node.checkAttributes(lexer);
 574   
 575  51 if (content == null)
 576    {
 577  0 AttVal missingAttribute = new AttVal(null, null, '"', "content", "");
 578  0 lexer.report.attrError(lexer, node, missingAttribute, Report.MISSING_ATTRIBUTE);
 579    }
 580   
 581    // name or http-equiv attribute must also be set
 582    }
 583    }
 584   
 585    /**
 586    * Checker implementation for table cells.
 587    */
 588    public static class CheckTableCell implements TagCheck
 589    {
 590   
 591    /**
 592    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 593    */
 594  1066 public void check(Lexer lexer, Node node)
 595    {
 596  1066 node.checkAttributes(lexer);
 597   
 598    // HTML4 strict doesn't allow mixed content for elements with %block; as their content model
 599   
 600  1066 if (node.getAttrByName("width") != null || node.getAttrByName("height") != null)
 601    {
 602  21 lexer.constrainVersion(~Dict.VERS_HTML40_STRICT);
 603    }
 604    }
 605    }
 606   
 607    /**
 608    * add missing type attribute when appropriate.
 609    */
 610    public static class CheckLINK implements TagCheck
 611    {
 612   
 613    /**
 614    * @see org.w3c.tidy.TagCheck#check(org.w3c.tidy.Lexer, org.w3c.tidy.Node)
 615    */
 616  14 public void check(Lexer lexer, Node node)
 617    {
 618  14 AttVal rel = node.getAttrByName("rel");
 619   
 620  14 node.checkAttributes(lexer);
 621   
 622  14 if (rel != null && rel.value != null && rel.value.equals("stylesheet"))
 623    {
 624  2 AttVal type = node.getAttrByName("type");
 625   
 626  2 if (type == null)
 627    {
 628  1 AttVal missingType = new AttVal(null, null, '"', "type", "");
 629  1 lexer.report.attrError(lexer, node, missingType, Report.MISSING_ATTRIBUTE);
 630   
 631  1 node.addAttribute("type", "text/css");
 632    }
 633    }
 634    }
 635    }
 636   
 637    }