001: /*
002: * @(#)AttVal.java 1.11 2000/08/16
003: *
004: */
005:
006: package org.w3c.tidy;
007:
008: /**
009: *
010: * Attribute/Value linked list node
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 AttVal extends Object implements Cloneable {
035:
036: public AttVal next;
037: public Attribute dict;
038: public Node asp;
039: public Node php;
040: public int delim;
041: public String attribute;
042: public String value;
043:
044: public AttVal() {
045: this .next = null;
046: this .dict = null;
047: this .asp = null;
048: this .php = null;
049: this .delim = 0;
050: this .attribute = null;
051: this .value = null;
052: }
053:
054: public AttVal(AttVal next, Attribute dict, int delim,
055: String attribute, String value) {
056: this .next = next;
057: this .dict = dict;
058: this .asp = null;
059: this .php = null;
060: this .delim = delim;
061: this .attribute = attribute;
062: this .value = value;
063: }
064:
065: public AttVal(AttVal next, Attribute dict, Node asp, Node php,
066: int delim, String attribute, String value) {
067: this .next = next;
068: this .dict = dict;
069: this .asp = asp;
070: this .php = php;
071: this .delim = delim;
072: this .attribute = attribute;
073: this .value = value;
074: }
075:
076: protected Object clone() {
077: AttVal av = new AttVal();
078: if (next != null) {
079: av.next = (AttVal) next.clone();
080: }
081: if (attribute != null)
082: av.attribute = attribute;
083: if (value != null)
084: av.value = value;
085: av.delim = delim;
086: if (asp != null) {
087: av.asp = (Node) asp.clone();
088: }
089: if (php != null) {
090: av.php = (Node) php.clone();
091: }
092: av.dict = AttributeTable.getDefaultAttributeTable()
093: .findAttribute(this );
094: return av;
095: }
096:
097: public boolean isBoolAttribute() {
098: Attribute attribute = this .dict;
099: if (attribute != null) {
100: if (attribute.attrchk == AttrCheckImpl.getCheckBool()) {
101: return true;
102: }
103: }
104:
105: return false;
106: }
107:
108: /* ignore unknown attributes for proprietary elements */
109: public Attribute checkAttribute(Lexer lexer, Node node) {
110: TagTable tt = lexer.configuration.tt;
111:
112: if (this .asp == null && this .php == null)
113: this .checkUniqueAttribute(lexer, node);
114:
115: Attribute attribute = this .dict;
116: if (attribute != null) {
117: /* title is vers 2.0 for A and LINK otherwise vers 4.0 */
118: if (attribute == AttributeTable.attrTitle
119: && (node.tag == tt.tagA || node.tag == tt.tagLink))
120: lexer.versions &= Dict.VERS_ALL;
121: else if ((attribute.versions & Dict.VERS_XML) != 0) {
122: if (!(lexer.configuration.XmlTags || lexer.configuration.XmlOut))
123: Report.attrError(lexer, node, this .attribute,
124: Report.XML_ATTRIBUTE_VALUE);
125: } else
126: lexer.versions &= attribute.versions;
127:
128: if (attribute.attrchk != null)
129: attribute.attrchk.check(lexer, node, this );
130: } else if (!lexer.configuration.XmlTags
131: && !(node.tag == null)
132: && this .asp == null
133: && !(node.tag != null && ((node.tag.versions & Dict.VERS_PROPRIETARY) != 0)))
134: Report.attrError(lexer, node, this .attribute,
135: Report.UNKNOWN_ATTRIBUTE);
136:
137: return attribute;
138: }
139:
140: /*
141: the same attribute name can't be used
142: more than once in each element
143: */
144: public void checkUniqueAttribute(Lexer lexer, Node node) {
145: AttVal attr;
146: int count = 0;
147:
148: for (attr = this .next; attr != null; attr = attr.next) {
149: if (this .attribute != null
150: && attr.attribute != null
151: && attr.asp == null
152: && attr.php == null
153: && Lexer
154: .wstrcasecmp(this .attribute, attr.attribute) == 0)
155: ++count;
156: }
157:
158: if (count > 0)
159: Report.attrError(lexer, node, this .attribute,
160: Report.REPEATED_ATTRIBUTE);
161: }
162:
163: /* --------------------- DOM ---------------------------- */
164:
165: protected org.w3c.dom.Attr adapter = null;
166:
167: protected org.w3c.dom.Attr getAdapter() {
168: if (adapter == null) {
169: adapter = new DOMAttrImpl(this );
170: }
171: return adapter;
172: }
173: /* --------------------- END DOM ------------------------ */
174:
175: }
|