2 * @(#)CheckAttribsImpl.java 1.11 2000/08/16
6 package net.sourceforge.phpdt.tidy.w3c;
10 * Check HTML attributes implementation
12 * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
13 * See Tidy.java for the copyright notice.
14 * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
15 * HTML Tidy Release 4 Aug 2000</a>
17 * @author Dave Raggett <dsr@w3.org>
18 * @author Andy Quick <ac.quick@sympatico.ca> (translation to Java)
19 * @version 1.0, 1999/05/22
20 * @version 1.0.1, 1999/05/29
21 * @version 1.1, 1999/06/18 Java Bean
22 * @version 1.2, 1999/07/10 Tidy Release 7 Jul 1999
23 * @version 1.3, 1999/07/30 Tidy Release 26 Jul 1999
24 * @version 1.4, 1999/09/04 DOM support
25 * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
26 * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
27 * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
28 * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
29 * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
30 * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
31 * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
34 public class CheckAttribsImpl {
36 public static class CheckHTML implements CheckAttribs {
38 public void check( Lexer lexer, Node node )
43 node.checkUniqueAttributes(lexer);
45 for (attval = node.attributes; attval != null; attval = attval.next)
47 attribute = attval.checkAttribute(lexer, node );
49 if (attribute == AttributeTable.attrXmlns)
50 lexer.isvoyager = true;
56 public static class CheckSCRIPT implements CheckAttribs {
58 public void check( Lexer lexer, Node node )
63 node.checkUniqueAttributes(lexer);
65 lang = node.getAttrByName("language");
66 type = node.getAttrByName("type");
70 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
72 /* check for javascript */
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) )
82 node.addAttribute("type", "text/javascript");
86 node.addAttribute("type", "text/javascript");
92 public static class CheckTABLE implements CheckAttribs {
94 public void check( Lexer lexer, Node node )
98 boolean hasSummary = false;
100 node.checkUniqueAttributes(lexer);
102 for (attval = node.attributes; attval != null; attval = attval.next)
104 attribute = attval.checkAttribute(lexer, node);
106 if (attribute == AttributeTable.attrSummary)
110 /* suppress warning for missing summary for HTML 2.0 and HTML 3.2 */
111 if (!hasSummary && lexer.doctype != Dict.VERS_HTML20 && lexer.doctype != Dict.VERS_HTML32)
113 lexer.badAccess |= Report.MISSING_SUMMARY;
114 Report.attrError(lexer, node, "summary", Report.MISSING_ATTRIBUTE);
117 /* convert <table border> to <table border="1"> */
118 if (lexer.configuration.XmlOut)
120 attval = node.getAttrByName("border");
123 if (attval.value == null)
131 public static class CheckCaption implements CheckAttribs {
133 public void check( Lexer lexer, Node node )
138 node.checkUniqueAttributes(lexer);
140 for (attval = node.attributes; attval != null; attval = attval.next)
142 if ( Lexer.wstrcasecmp(attval.attribute, "align") == 0 )
144 value = attval.value;
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;
156 Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE);
162 public static class CheckHR implements CheckAttribs {
164 public void check( Lexer lexer, Node node )
166 if (node.getAttrByName("src") != null)
167 Report.attrError(lexer, node, "src", Report.PROPRIETARY_ATTR_VALUE);
171 public static class CheckIMG implements CheckAttribs {
173 public void check( Lexer lexer, Node node )
177 boolean hasAlt = false;
178 boolean hasSrc = false;
179 boolean hasUseMap = false;
180 boolean hasIsMap = false;
181 boolean hasDataFld = false;
183 node.checkUniqueAttributes(lexer);
185 for (attval = node.attributes; attval != null; attval = attval.next)
187 attribute = attval.checkAttribute( lexer, node );
189 if (attribute == AttributeTable.attrAlt)
191 else if (attribute == AttributeTable.attrSrc)
193 else if (attribute == AttributeTable.attrUsemap)
195 else if (attribute == AttributeTable.attrIsmap)
197 else if (attribute == AttributeTable.attrDatafld)
199 else if (attribute == AttributeTable.attrWidth ||
200 attribute == AttributeTable.attrHeight)
201 lexer.versions &= ~Dict.VERS_HTML20;
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);
212 if (!hasSrc && !hasDataFld)
213 Report.attrError(lexer, node, "src", Report.MISSING_ATTRIBUTE);
215 if (hasIsMap && !hasUseMap)
216 Report.attrError(lexer, node, "ismap", Report.MISSING_IMAGEMAP);
221 public static class CheckAREA implements CheckAttribs {
223 public void check( Lexer lexer, Node node )
227 boolean hasAlt = false;
228 boolean hasHref = false;
230 node.checkUniqueAttributes(lexer);
232 for (attval = node.attributes; attval != null; attval = attval.next)
234 attribute = attval.checkAttribute( lexer, node );
236 if (attribute == AttributeTable.attrAlt)
238 else if (attribute == AttributeTable.attrHref)
244 lexer.badAccess |= Report.MISSING_LINK_ALT;
245 Report.attrError(lexer, node, "alt", Report.MISSING_ATTRIBUTE);
248 Report.attrError(lexer, node, "href", Report.MISSING_ATTRIBUTE);
253 public static class CheckAnchor implements CheckAttribs {
255 public void check( Lexer lexer, Node node )
257 node.checkUniqueAttributes(lexer);
263 public static class CheckMap implements CheckAttribs {
265 public void check( Lexer lexer, Node node )
267 node.checkUniqueAttributes(lexer);
273 public static class CheckSTYLE implements CheckAttribs {
275 public void check( Lexer lexer, Node node )
277 AttVal type = node.getAttrByName("type");
279 node.checkUniqueAttributes(lexer);
283 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
285 node.addAttribute("type", "text/css");
290 public static class CheckTableCell implements CheckAttribs {
292 public void check( Lexer lexer, Node node )
294 node.checkUniqueAttributes(lexer);
297 HTML4 strict doesn't allow mixed content for
298 elements with %block; as their content model
300 if (node.getAttrByName("width") != null || node.getAttrByName("height") != null)
301 lexer.versions &= ~Dict.VERS_HTML40_STRICT;
305 /* add missing type attribute when appropriate */
306 public static class CheckLINK implements CheckAttribs {
308 public void check( Lexer lexer, Node node )
310 AttVal rel = node.getAttrByName("rel");
312 node.checkUniqueAttributes(lexer);
314 if (rel != null && rel.value != null &&
315 rel.value.equals("stylesheet"))
317 AttVal type = node.getAttrByName("type");
321 Report.attrError(lexer, node, "type", Report.MISSING_ATTRIBUTE);
323 node.addAttribute("type", "text/css");
329 public static CheckAttribs getCheckHTML()
334 public static CheckAttribs getCheckSCRIPT()
339 public static CheckAttribs getCheckTABLE()
344 public static CheckAttribs getCheckCaption()
346 return _checkCaption;
349 public static CheckAttribs getCheckIMG()
354 public static CheckAttribs getCheckAREA()
359 public static CheckAttribs getCheckAnchor()
364 public static CheckAttribs getCheckMap()
369 public static CheckAttribs getCheckSTYLE()
374 public static CheckAttribs getCheckTableCell()
376 return _checkTableCell;
379 public static CheckAttribs getCheckLINK()
384 public static CheckAttribs getCheckHR()
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();