Source code: com/port80/html/tidy/AttrCheckImpl.java
1 /*
2 * @(#)AttrCheckImpl.java 1.11 2000/08/16
3 *
4 */
5
6 package com.port80.html.tidy;
7
8 /**
9 *
10 * Check attribute values implementations
11 *
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>
16 *
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
32 */
33
34 public class AttrCheckImpl {
35
36 public static class CheckUrl implements AttrCheck {
37
38 public void check(Lexer lexer, Node node, AttVal attval) {
39 if (attval.value == null)
40 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
41 else if (lexer.configuration.FixBackslash) {
42 attval.value = attval.value.replace('\\', '/');
43 }
44 }
45
46 };
47
48 public static class CheckScript implements AttrCheck {
49
50 public void check(Lexer lexer, Node node, AttVal attval) {
51 }
52
53 };
54
55 public static class CheckAlign implements AttrCheck {
56
57 public void check(Lexer lexer, Node node, AttVal attval) {
58 String value;
59
60 /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
61 if (node.tag != null && ((node.tag.model & Dict.CM_IMG) != 0)) {
62 getCheckValign().check(lexer, node, attval);
63 return;
64 }
65
66 value = attval.value;
67
68 if (value == null)
69 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
70 else if (
71 !(Lexer.wstrcasecmp(value, "left") == 0
72 || Lexer.wstrcasecmp(value, "center") == 0
73 || Lexer.wstrcasecmp(value, "right") == 0
74 || Lexer.wstrcasecmp(value, "justify") == 0))
75 Report.attrError(lexer, node, attval.value, Report.BAD_ATTRIBUTE_VALUE);
76 }
77
78 };
79
80 public static class CheckValign implements AttrCheck {
81
82 public void check(Lexer lexer, Node node, AttVal attval) {
83 String value;
84
85 value = attval.value;
86
87 if (value == null)
88 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
89 else if (
90 Lexer.wstrcasecmp(value, "top") == 0
91 || Lexer.wstrcasecmp(value, "middle") == 0
92 || Lexer.wstrcasecmp(value, "bottom") == 0
93 || Lexer.wstrcasecmp(value, "baseline") == 0) {
94 /* all is fine */
95 } else if (Lexer.wstrcasecmp(value, "left") == 0 || Lexer.wstrcasecmp(value, "right") == 0) {
96 if (!(node.tag != null && ((node.tag.model & Dict.CM_IMG) != 0)))
97 Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE);
98 } else if (
99 Lexer.wstrcasecmp(value, "texttop") == 0
100 || Lexer.wstrcasecmp(value, "absmiddle") == 0
101 || Lexer.wstrcasecmp(value, "absbottom") == 0
102 || Lexer.wstrcasecmp(value, "textbottom") == 0) {
103 lexer.versions &= Dict.VERS_PROPRIETARY;
104 Report.attrError(lexer, node, value, Report.PROPRIETARY_ATTR_VALUE);
105 } else
106 Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE);
107 }
108
109 };
110
111 public static class CheckBool implements AttrCheck {
112
113 public void check(Lexer lexer, Node node, AttVal attval) {
114 }
115
116 };
117
118 public static class CheckId implements AttrCheck {
119
120 public void check(Lexer lexer, Node node, AttVal attval) {
121 }
122
123 };
124
125 public static class CheckName implements AttrCheck {
126
127 public void check(Lexer lexer, Node node, AttVal attval) {
128 }
129
130 };
131
132 public static AttrCheck getCheckUrl() {
133 return _checkUrl;
134 }
135
136 public static AttrCheck getCheckScript() {
137 return _checkScript;
138 }
139
140 public static AttrCheck getCheckAlign() {
141 return _checkAlign;
142 }
143
144 public static AttrCheck getCheckValign() {
145 return _checkValign;
146 }
147
148 public static AttrCheck getCheckBool() {
149 return _checkBool;
150 }
151
152 public static AttrCheck getCheckId() {
153 return _checkId;
154 }
155
156 public static AttrCheck getCheckName() {
157 return _checkName;
158 }
159
160 private static AttrCheck _checkUrl = new CheckUrl();
161 private static AttrCheck _checkScript = new CheckScript();
162 private static AttrCheck _checkAlign = new CheckAlign();
163 private static AttrCheck _checkValign = new CheckValign();
164 private static AttrCheck _checkBool = new CheckBool();
165 private static AttrCheck _checkId = new CheckId();
166 private static AttrCheck _checkName = new CheckName();
167
168 }