1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| package org.w3c.tidy; |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| public final class TagCheckImpl |
64 |
| { |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| public static final TagCheck HTML = new CheckHTML(); |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| public static final TagCheck SCRIPT = new CheckSCRIPT(); |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| public static final TagCheck TABLE = new CheckTABLE(); |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| public static final TagCheck CAPTION = new CheckCaption(); |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| public static final TagCheck IMG = new CheckIMG(); |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| public static final TagCheck AREA = new CheckAREA(); |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| public static final TagCheck ANCHOR = new CheckAnchor(); |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| public static final TagCheck MAP = new CheckMap(); |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| public static final TagCheck STYLE = new CheckSTYLE(); |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| public static final TagCheck TABLECELL = new CheckTableCell(); |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| public static final TagCheck LINK = new CheckLINK(); |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| public static final TagCheck HR = new CheckHR(); |
125 |
| |
126 |
| |
127 |
| |
128 |
| |
129 |
| public static final TagCheck FORM = new CheckForm(); |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| public static final TagCheck META = new CheckMeta(); |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
0
| private TagCheckImpl()
|
140 |
| { |
141 |
| |
142 |
| } |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
| public static class CheckHTML implements TagCheck |
148 |
| { |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| private static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; |
154 |
| |
155 |
| |
156 |
| |
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)
|
170 |
| { |
171 |
64
| lexer.configuration.xHTML = true;
|
172 |
| } |
173 |
| |
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 |
| |
189 |
| |
190 |
| public static class CheckSCRIPT implements TagCheck |
191 |
| { |
192 |
| |
193 |
| |
194 |
| |
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 |
| |
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 |
| |
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 |
| |
235 |
| |
236 |
| public static class CheckTABLE implements TagCheck |
237 |
| { |
238 |
| |
239 |
| |
240 |
| |
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 |
| |
259 |
72
| if (!hasSummary && lexer.doctype != Dict.VERS_HTML20 && lexer.doctype != Dict.VERS_HTML32)
|
260 |
| { |
261 |
48
| lexer.badAccess |= Report.MISSING_SUMMARY;
|
262 |
| |
263 |
| |
264 |
| |
265 |
| |
266 |
| } |
267 |
| |
268 |
| |
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 |
| |
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 |
| |
294 |
| |
295 |
| public static class CheckCaption implements TagCheck |
296 |
| { |
297 |
| |
298 |
| |
299 |
| |
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 |
| |
338 |
| |
339 |
| public static class CheckHR implements TagCheck |
340 |
| { |
341 |
| |
342 |
| |
343 |
| |
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 |
| |
360 |
| |
361 |
| public static class CheckIMG implements TagCheck |
362 |
| { |
363 |
| |
364 |
| |
365 |
| |
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 |
| |
435 |
| |
436 |
| public static class CheckAREA implements TagCheck |
437 |
| { |
438 |
| |
439 |
| |
440 |
| |
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 |
| |
480 |
| |
481 |
| public static class CheckAnchor implements TagCheck |
482 |
| { |
483 |
| |
484 |
| |
485 |
| |
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 |
| |
497 |
| |
498 |
| public static class CheckMap implements TagCheck |
499 |
| { |
500 |
| |
501 |
| |
502 |
| |
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 |
| |
514 |
| |
515 |
| public static class CheckSTYLE implements TagCheck |
516 |
| { |
517 |
| |
518 |
| |
519 |
| |
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 |
| |
539 |
| |
540 |
| public static class CheckForm implements TagCheck |
541 |
| { |
542 |
| |
543 |
| |
544 |
| |
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 |
| |
562 |
| |
563 |
| public static class CheckMeta implements TagCheck |
564 |
| { |
565 |
| |
566 |
| |
567 |
| |
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 |
| |
582 |
| } |
583 |
| } |
584 |
| |
585 |
| |
586 |
| |
587 |
| |
588 |
| public static class CheckTableCell implements TagCheck |
589 |
| { |
590 |
| |
591 |
| |
592 |
| |
593 |
| |
594 |
1066
| public void check(Lexer lexer, Node node)
|
595 |
| { |
596 |
1066
| node.checkAttributes(lexer);
|
597 |
| |
598 |
| |
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 |
| |
609 |
| |
610 |
| public static class CheckLINK implements TagCheck |
611 |
| { |
612 |
| |
613 |
| |
614 |
| |
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 |
| } |