001: /*
002: * @(#)AttrCheckImpl.java 1.11 2000/08/16
003: *
004: */
005:
006: package org.w3c.tidy;
007:
008: /**
009: *
010: * Check attribute values implementations
011: *
012: * (c) 1998-2000 (W3C) MIT, INRIA, Keio University
013: * See Tidy.java for the copyright notice.
014: * Derived from <a href="http://www.w3.org/People/Raggett/tidy">
015: * HTML Tidy Release 4 Aug 2000</a>
016: *
017: * @author Dave Raggett <dsr@w3.org>
018: * @author Andy Quick <ac.quick@sympatico.ca> (translation to Java)
019: * @version 1.0, 1999/05/22
020: * @version 1.0.1, 1999/05/29
021: * @version 1.1, 1999/06/18 Java Bean
022: * @version 1.2, 1999/07/10 Tidy Release 7 Jul 1999
023: * @version 1.3, 1999/07/30 Tidy Release 26 Jul 1999
024: * @version 1.4, 1999/09/04 DOM support
025: * @version 1.5, 1999/10/23 Tidy Release 27 Sep 1999
026: * @version 1.6, 1999/11/01 Tidy Release 22 Oct 1999
027: * @version 1.7, 1999/12/06 Tidy Release 30 Nov 1999
028: * @version 1.8, 2000/01/22 Tidy Release 13 Jan 2000
029: * @version 1.9, 2000/06/03 Tidy Release 30 Apr 2000
030: * @version 1.10, 2000/07/22 Tidy Release 8 Jul 2000
031: * @version 1.11, 2000/08/16 Tidy Release 4 Aug 2000
032: */
033:
034: public class AttrCheckImpl {
035:
036: public static class CheckUrl implements AttrCheck {
037:
038: public void check(Lexer lexer, Node node, AttVal attval) {
039: if (attval.value == null)
040: Report.attrError(lexer, node, attval.attribute,
041: Report.MISSING_ATTR_VALUE);
042: else if (lexer.configuration.FixBackslash) {
043: attval.value = attval.value.replace('\\', '/');
044: }
045: }
046:
047: };
048:
049: public static class CheckScript implements AttrCheck {
050:
051: public void check(Lexer lexer, Node node, AttVal attval) {
052: }
053:
054: };
055:
056: public static class CheckAlign implements AttrCheck {
057:
058: public void check(Lexer lexer, Node node, AttVal attval) {
059: String value;
060:
061: /* IMG, OBJECT, APPLET and EMBED use align for vertical position */
062: if (node.tag != null
063: && ((node.tag.model & Dict.CM_IMG) != 0)) {
064: getCheckValign().check(lexer, node, attval);
065: return;
066: }
067:
068: value = attval.value;
069:
070: if (value == null)
071: Report.attrError(lexer, node, attval.attribute,
072: Report.MISSING_ATTR_VALUE);
073: else if (!(Lexer.wstrcasecmp(value, "left") == 0
074: || Lexer.wstrcasecmp(value, "center") == 0
075: || Lexer.wstrcasecmp(value, "right") == 0 || Lexer
076: .wstrcasecmp(value, "justify") == 0))
077: Report.attrError(lexer, node, attval.value,
078: Report.BAD_ATTRIBUTE_VALUE);
079: }
080:
081: };
082:
083: public static class CheckValign implements AttrCheck {
084:
085: public void check(Lexer lexer, Node node, AttVal attval) {
086: String value;
087:
088: value = attval.value;
089:
090: if (value == null)
091: Report.attrError(lexer, node, attval.attribute,
092: Report.MISSING_ATTR_VALUE);
093: else if (Lexer.wstrcasecmp(value, "top") == 0
094: || Lexer.wstrcasecmp(value, "middle") == 0
095: || Lexer.wstrcasecmp(value, "bottom") == 0
096: || Lexer.wstrcasecmp(value, "baseline") == 0) {
097: /* all is fine */
098: } else if (Lexer.wstrcasecmp(value, "left") == 0
099: || Lexer.wstrcasecmp(value, "right") == 0) {
100: if (!(node.tag != null && ((node.tag.model & Dict.CM_IMG) != 0)))
101: Report.attrError(lexer, node, value,
102: Report.BAD_ATTRIBUTE_VALUE);
103: } else if (Lexer.wstrcasecmp(value, "texttop") == 0
104: || Lexer.wstrcasecmp(value, "absmiddle") == 0
105: || Lexer.wstrcasecmp(value, "absbottom") == 0
106: || Lexer.wstrcasecmp(value, "textbottom") == 0) {
107: lexer.versions &= Dict.VERS_PROPRIETARY;
108: Report.attrError(lexer, node, value,
109: Report.PROPRIETARY_ATTR_VALUE);
110: } else
111: Report.attrError(lexer, node, value,
112: Report.BAD_ATTRIBUTE_VALUE);
113: }
114:
115: };
116:
117: public static class CheckBool implements AttrCheck {
118:
119: public void check(Lexer lexer, Node node, AttVal attval) {
120: }
121:
122: };
123:
124: public static class CheckId implements AttrCheck {
125:
126: public void check(Lexer lexer, Node node, AttVal attval) {
127: }
128:
129: };
130:
131: public static class CheckName implements AttrCheck {
132:
133: public void check(Lexer lexer, Node node, AttVal attval) {
134: }
135:
136: };
137:
138: public static AttrCheck getCheckUrl() {
139: return _checkUrl;
140: }
141:
142: public static AttrCheck getCheckScript() {
143: return _checkScript;
144: }
145:
146: public static AttrCheck getCheckAlign() {
147: return _checkAlign;
148: }
149:
150: public static AttrCheck getCheckValign() {
151: return _checkValign;
152: }
153:
154: public static AttrCheck getCheckBool() {
155: return _checkBool;
156: }
157:
158: public static AttrCheck getCheckId() {
159: return _checkId;
160: }
161:
162: public static AttrCheck getCheckName() {
163: return _checkName;
164: }
165:
166: private static AttrCheck _checkUrl = new CheckUrl();
167: private static AttrCheck _checkScript = new CheckScript();
168: private static AttrCheck _checkAlign = new CheckAlign();
169: private static AttrCheck _checkValign = new CheckValign();
170: private static AttrCheck _checkBool = new CheckBool();
171: private static AttrCheck _checkId = new CheckId();
172: private static AttrCheck _checkName = new CheckName();
173:
174: }
|