1 5 6 package org.w3c.tidy; 7 8 33 34 public class CheckAttribsImpl { 35 36 public static class CheckHTML implements CheckAttribs { 37 38 public void check( Lexer lexer, Node node ) 39 { 40 AttVal attval; 41 Attribute attribute; 42 43 node.checkUniqueAttributes(lexer); 44 45 for (attval = node.attributes; attval != null; attval = attval.next) 46 { 47 attribute = attval.checkAttribute(lexer, node ); 48 49 if (attribute == AttributeTable.attrXmlns) 50 lexer.isvoyager = true; 51 } 52 } 53 54 }; 55 56 public static class CheckSCRIPT implements CheckAttribs { 57 58 public void check( Lexer lexer, Node node ) 59 { 60 Attribute attribute; 61 AttVal lang, type; 62 63 node.checkUniqueAttributes(lexer); 64 65 lang = node.getAttrByName("language"); 66 type = node.getAttrByName("type"); 67 68 if (type == null) 69 { 70 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); 71 72 73 74 if (lang != null) 75 { 76 String str = lang.value; 77 if (str.length() > 10) 78 str = str.substring(0, 10); 79 if ( (Lexer.wstrcasecmp(str, "javascript") == 0) || 80 (Lexer.wstrcasecmp(str, "jscript") == 0) ) 81 { 82 node.addAttribute("type", "text/javascript"); 83 } 84 } 85 else 86 node.addAttribute("type", "text/javascript"); 87 } 88 } 89 90 }; 91 92 public static class CheckTABLE implements CheckAttribs { 93 94 public void check( Lexer lexer, Node node ) 95 { 96 AttVal attval; 97 Attribute attribute; 98 boolean hasSummary = false; 99 100 node.checkUniqueAttributes(lexer); 101 102 for (attval = node.attributes; attval != null; attval = attval.next) 103 { 104 attribute = attval.checkAttribute(lexer, node); 105 106 if (attribute == AttributeTable.attrSummary) 107 hasSummary = true; 108 } 109 110 111 if (!hasSummary && lexer.doctype != Dict.VERS_HTML20 && lexer.doctype != Dict.VERS_HTML32) 112 { 113 lexer.badAccess |= Report.MISSING_SUMMARY; 114 Report.attrError(lexer, node, "summary", Report.MISSING_ATTRIBUTE); 115 } 116 117 118 if (lexer.configuration.XmlOut) 119 { 120 attval = node.getAttrByName("border"); 121 if (attval != null) 122 { 123 if (attval.value == null) 124 attval.value = "1"; 125 } 126 } 127 } 128 129 }; 130 131 public static class CheckCaption implements CheckAttribs { 132 133 public void check( Lexer lexer, Node node ) 134 { 135 AttVal attval; 136 String value = null; 137 138 node.checkUniqueAttributes(lexer); 139 140 for (attval = node.attributes; attval != null; attval = attval.next) 141 { 142 if ( Lexer.wstrcasecmp(attval.attribute, "align") == 0 ) 143 { 144 value = attval.value; 145 break; 146 } 147 } 148 149 if (value != null) 150 { 151 if (Lexer.wstrcasecmp(value, "left") == 0 || Lexer.wstrcasecmp(value, "right") == 0) 152 lexer.versions &= (short)(Dict.VERS_HTML40_LOOSE|Dict.VERS_FRAMES); 153 else if (Lexer.wstrcasecmp(value, "top") == 0 || Lexer.wstrcasecmp(value, "bottom") == 0) 154 lexer.versions &= Dict.VERS_FROM32; 155 else 156 Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE); 157 } 158 } 159 160 }; 161 162 public static class CheckHR implements CheckAttribs { 163 164 public void check( Lexer lexer, Node node ) 165 { 166 if (node.getAttrByName("src") != null) 167 Report.attrError(lexer, node, "src", Report.PROPRIETARY_ATTR_VALUE); 168 } 169 }; 170 171 public static class CheckIMG implements CheckAttribs { 172 173 public void check( Lexer lexer, Node node ) 174 { 175 AttVal attval; 176 Attribute attribute; 177 boolean hasAlt = false; 178 boolean hasSrc = false; 179 boolean hasUseMap = false; 180 boolean hasIsMap = false; 181 boolean hasDataFld = false; 182 183 node.checkUniqueAttributes(lexer); 184 185 for (attval = node.attributes; attval != null; attval = attval.next) 186 { 187 attribute = attval.checkAttribute( lexer, node ); 188 189 if (attribute == AttributeTable.attrAlt) 190 hasAlt = true; 191 else if (attribute == AttributeTable.attrSrc) 192 hasSrc = true; 193 else if (attribute == AttributeTable.attrUsemap) 194 hasUseMap = true; 195 else if (attribute == AttributeTable.attrIsmap) 196 hasIsMap = true; 197 else if (attribute == AttributeTable.attrDatafld) 198 hasDataFld = true; 199 else if (attribute == AttributeTable.attrWidth || 200 attribute == AttributeTable.attrHeight) 201 lexer.versions &= ~Dict.VERS_HTML20; 202 } 203 204 if (!hasAlt) 205 { 206 lexer.badAccess |= Report.MISSING_IMAGE_ALT; 207 Report.attrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE); 208 if (lexer.configuration.altText != null) 209 node.addAttribute("alt", lexer.configuration.altText); 210 } 211 212 if (!hasSrc && !hasDataFld) 213 Report.attrError(lexer, node, "src", Report.MISSING_ATTRIBUTE); 214 215 if (hasIsMap && !hasUseMap) 216 Report.attrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP); 217 } 218 219 }; 220 221 public static class CheckAREA implements CheckAttribs { 222 223 public void check( Lexer lexer, Node node ) 224 { 225 AttVal attval; 226 Attribute attribute; 227 boolean hasAlt = false; 228 boolean hasHref = false; 229 230 node.checkUniqueAttributes(lexer); 231 232 for (attval = node.attributes; attval != null; attval = attval.next) 233 { 234 attribute = attval.checkAttribute( lexer, node ); 235 236 if (attribute == AttributeTable.attrAlt) 237 hasAlt = true; 238 else if (attribute == AttributeTable.attrHref) 239 hasHref = true; 240 } 241 242 if (!hasAlt) 243 { 244 lexer.badAccess |= Report.MISSING_LINK_ALT; 245 Report.attrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE); 246 } 247 if (!hasHref) 248 Report.attrError(lexer, node, "href", Report.MISSING_ATTRIBUTE); 249 } 250 251 }; 252 253 public static class CheckAnchor implements CheckAttribs { 254 255 public void check( Lexer lexer, Node node ) 256 { 257 node.checkUniqueAttributes(lexer); 258 259 lexer.fixId(node); 260 } 261 }; 262 263 public static class CheckMap implements CheckAttribs { 264 265 public void check( Lexer lexer, Node node ) 266 { 267 node.checkUniqueAttributes(lexer); 268 269 lexer.fixId(node); 270 } 271 } 272 273 public static class CheckSTYLE implements CheckAttribs { 274 275 public void check( Lexer lexer, Node node ) 276 { 277 AttVal type = node.getAttrByName("type"); 278 279 node.checkUniqueAttributes(lexer); 280 281 if (type == null) 282 { 283 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); 284 285 node.addAttribute("type", "text/css"); 286 } 287 } 288 } 289 290 public static class CheckTableCell implements CheckAttribs { 291 292 public void check( Lexer lexer, Node node ) 293 { 294 node.checkUniqueAttributes(lexer); 295 296 300 if (node.getAttrByName("width") != null || node.getAttrByName("height") != null) 301 lexer.versions &= ~Dict.VERS_HTML40_STRICT; 302 } 303 } 304 305 306 public static class CheckLINK implements CheckAttribs { 307 308 public void check( Lexer lexer, Node node ) 309 { 310 AttVal rel = node.getAttrByName("rel"); 311 312 node.checkUniqueAttributes(lexer); 313 314 if (rel != null && rel.value != null && 315 rel.value.equals("stylesheet")) 316 { 317 AttVal type = node.getAttrByName("type"); 318 319 if (type == null) 320 { 321 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); 322 323 node.addAttribute("type", "text/css"); 324 } 325 } 326 } 327 } 328 329 public static CheckAttribs getCheckHTML() 330 { 331 return _checkHTML; 332 } 333 334 public static CheckAttribs getCheckSCRIPT() 335 { 336 return _checkSCRIPT; 337 } 338 339 public static CheckAttribs getCheckTABLE() 340 { 341 return _checkTABLE; 342 } 343 344 public static CheckAttribs getCheckCaption() 345 { 346 return _checkCaption; 347 } 348 349 public static CheckAttribs getCheckIMG() 350 { 351 return _checkIMG; 352 } 353 354 public static CheckAttribs getCheckAREA() 355 { 356 return _checkAREA; 357 } 358 359 public static CheckAttribs getCheckAnchor() 360 { 361 return _checkAnchor; 362 } 363 364 public static CheckAttribs getCheckMap() 365 { 366 return _checkMap; 367 } 368 369 public static CheckAttribs getCheckSTYLE() 370 { 371 return _checkStyle; 372 } 373 374 public static CheckAttribs getCheckTableCell() 375 { 376 return _checkTableCell; 377 } 378 379 public static CheckAttribs getCheckLINK() 380 { 381 return _checkLINK; 382 } 383 384 public static CheckAttribs getCheckHR() 385 { 386 return _checkHR; 387 } 388 389 390 private static CheckAttribs _checkHTML = new CheckHTML(); 391 private static CheckAttribs _checkSCRIPT = new CheckSCRIPT(); 392 private static CheckAttribs _checkTABLE = new CheckTABLE(); 393 private static CheckAttribs _checkCaption = new CheckCaption(); 394 private static CheckAttribs _checkIMG = new CheckIMG(); 395 private static CheckAttribs _checkAREA = new CheckAREA(); 396 private static CheckAttribs _checkAnchor = new CheckAnchor(); 397 private static CheckAttribs _checkMap = new CheckMap(); 398 private static CheckAttribs _checkStyle = new CheckSTYLE(); 399 private static CheckAttribs _checkTableCell = new CheckTableCell(); 400 private static CheckAttribs _checkLINK = new CheckLINK(); 401 private static CheckAttribs _checkHR = new CheckHR(); 402 403 } 404 | Popular Tags |