KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > w3c > tidy > AttrCheckImpl


1 /*
2  * @(#)AttrCheckImpl.java 1.11 2000/08/16
3  *
4  */

5
6 package org.w3c.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         {
40             if (attval.value == null)
41                 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
42             else if (lexer.configuration.FixBackslash)
43             {
44                 attval.value = attval.value.replace('\\','/');
45             }
46         }
47
48     };
49
50     public static class CheckScript implements AttrCheck {
51
52         public void check( Lexer lexer, Node node, AttVal attval)
53         {
54         }
55
56     };
57
58     public static class CheckAlign implements AttrCheck {
59
60         public void check( Lexer lexer, Node node, AttVal attval)
61         {
62             String JavaDoc value;
63
64             /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
65             if (node.tag != null && ((node.tag.model & Dict.CM_IMG) != 0))
66             {
67                 getCheckValign().check(lexer, node, attval);
68                 return;
69             }
70
71             value = attval.value;
72
73             if (value == null)
74                 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
75             else if (! (Lexer.wstrcasecmp(value, "left") == 0 ||
76                         Lexer.wstrcasecmp(value, "center") == 0 ||
77                         Lexer.wstrcasecmp(value, "right") == 0 ||
78                         Lexer.wstrcasecmp(value, "justify") == 0))
79                   Report.attrError(lexer, node, attval.value, Report.BAD_ATTRIBUTE_VALUE);
80         }
81
82     };
83
84     public static class CheckValign implements AttrCheck {
85
86         public void check( Lexer lexer, Node node, AttVal attval)
87         {
88             String JavaDoc value;
89
90             value = attval.value;
91
92             if (value == null)
93                 Report.attrError(lexer, node, attval.attribute, Report.MISSING_ATTR_VALUE);
94             else if (Lexer.wstrcasecmp(value, "top") == 0 ||
95                    Lexer.wstrcasecmp(value, "middle") == 0 ||
96                    Lexer.wstrcasecmp(value, "bottom") == 0 ||
97                    Lexer.wstrcasecmp(value, "baseline") == 0)
98             {
99                 /* all is fine */
100             }
101             else if (Lexer.wstrcasecmp(value, "left") == 0 ||
102                       Lexer.wstrcasecmp(value, "right") == 0)
103             {
104                 if (!(node.tag != null && ((node.tag.model & Dict.CM_IMG) != 0)))
105                     Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE);
106             }
107             else if (Lexer.wstrcasecmp(value, "texttop") == 0 ||
108                    Lexer.wstrcasecmp(value, "absmiddle") == 0 ||
109                    Lexer.wstrcasecmp(value, "absbottom") == 0 ||
110                    Lexer.wstrcasecmp(value, "textbottom") == 0)
111             {
112                 lexer.versions &= Dict.VERS_PROPRIETARY;
113                 Report.attrError(lexer, node, value, Report.PROPRIETARY_ATTR_VALUE);
114             }
115             else
116                   Report.attrError(lexer, node, value, Report.BAD_ATTRIBUTE_VALUE);
117         }
118
119     };
120
121     public static class CheckBool implements AttrCheck {
122
123         public void check( Lexer lexer, Node node, AttVal attval)
124         {
125         }
126
127     };
128
129     public static class CheckId implements AttrCheck {
130
131         public void check( Lexer lexer, Node node, AttVal attval)
132         {
133         }
134
135     };
136
137     public static class CheckName implements AttrCheck {
138
139         public void check( Lexer lexer, Node node, AttVal attval)
140         {
141         }
142
143     };
144
145     public static AttrCheck getCheckUrl()
146     {
147         return _checkUrl;
148     }
149
150     public static AttrCheck getCheckScript()
151     {
152         return _checkScript;
153     }
154
155     public static AttrCheck getCheckAlign()
156     {
157         return _checkAlign;
158     }
159
160     public static AttrCheck getCheckValign()
161     {
162         return _checkValign;
163     }
164
165     public static AttrCheck getCheckBool()
166     {
167         return _checkBool;
168     }
169
170     public static AttrCheck getCheckId()
171     {
172         return _checkId;
173     }
174
175     public static AttrCheck getCheckName()
176     {
177         return _checkName;
178     }
179
180
181     private static AttrCheck _checkUrl = new CheckUrl();
182     private static AttrCheck _checkScript = new CheckScript();
183     private static AttrCheck _checkAlign = new CheckAlign();
184     private static AttrCheck _checkValign = new CheckValign();
185     private static AttrCheck _checkBool = new CheckBool();
186     private static AttrCheck _checkId = new CheckId();
187     private static AttrCheck _checkName = new CheckName();
188
189 }
190
Popular Tags