Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/html/tidy/AttVal.java


1   /*
2    * @(#)AttVal.java   1.11 2000/08/16
3    *
4    */
5   
6   package com.port80.html.tidy;
7   
8   /**
9    *
10   * Attribute/Value linked list node
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 AttVal extends Object implements Cloneable {
35  
36    public AttVal next;
37    public Attribute dict;
38    public Node asp;
39    public Node php;
40    public char delim;
41    public String attribute;
42    public String value;
43  
44    public AttVal() {
45      this.next = null;
46      this.dict = null;
47      this.asp = null;
48      this.php = null;
49      this.delim = 0;
50      this.attribute = null;
51      this.value = null;
52    }
53  
54    public AttVal(AttVal prev, Attribute dict, char delim, String attribute, String value) {
55      this.next = null;
56      this.dict = dict;
57      this.asp = null;
58      this.php = null;
59      this.delim = delim;
60      this.attribute = attribute;
61      this.value = value;
62      if (prev != null)
63        prev.next = this;
64    }
65  
66    public AttVal(AttVal prev, Attribute dict, Node asp, Node php, char delim, String attribute, String value) {
67      this.next = null;
68      this.dict = dict;
69      this.asp = asp;
70      this.php = php;
71      this.delim = delim;
72      this.attribute = attribute;
73      this.value = value;
74      if (prev != null)
75        prev.next = this;
76    }
77  
78    protected Object clone() {
79      AttVal av = new AttVal();
80      if (next != null) {
81        av.next = (AttVal) next.clone();
82      }
83      if (attribute != null)
84        av.attribute = attribute;
85      if (value != null)
86        av.value = value;
87      av.delim = delim;
88      if (asp != null) {
89        av.asp = (Node) asp.clone();
90      }
91      if (php != null) {
92        av.php = (Node) php.clone();
93      }
94      av.dict = AttributeTable.getDefaultAttributeTable().findAttribute(this);
95      return av;
96    }
97  
98    public boolean isBoolAttribute() {
99      Attribute attribute = this.dict;
100     if (attribute != null) {
101       if (attribute.attrchk == AttrCheckImpl.getCheckBool()) {
102         return true;
103       }
104     }
105 
106     return false;
107   }
108 
109   /* ignore unknown attributes for proprietary elements */
110   public Attribute checkAttribute(Lexer lexer, Node node) {
111     TagTable tt = lexer.configuration.getTagTable();
112 
113     if (this.asp == null && this.php == null)
114       this.checkUniqueAttribute(lexer, node);
115 
116     Attribute attribute = this.dict;
117     if (attribute != null) {
118       /* title is vers 2.0 for A and LINK otherwise vers 4.0 */
119       if (attribute == AttributeTable.attrTitle && (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, Report.XML_ATTRIBUTE_VALUE);
124       } else
125         lexer.versions &= attribute.versions;
126 
127       if (attribute.attrchk != null)
128         attribute.attrchk.check(lexer, node, this);
129     } else if (
130       !lexer.configuration.XmlTags
131         && !(node.tag == null)
132         && !((node.tag.versions & Dict.VERS_PROPRIETARY) != 0)
133         && !(node.tag == tt.xmlTags)
134         && this.asp == null)
135       Report.attrError(lexer, node, this.attribute, 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.wstrcasecmp(this.attribute, attr.attribute) == 0)
154         ++count;
155     }
156 
157     if (count > 0)
158       Report.attrError(lexer, node, this.attribute, Report.REPEATED_ATTRIBUTE);
159   }
160 
161   public String toString() {
162     if (delim != '\0') {
163       return attribute + '=' + delim + value + delim;
164     } else
165       return attribute + "=" + value;
166   }
167 
168   /* --------------------- DOM ---------------------------- */
169 
170   protected org.w3c.dom.Attr adapter = null;
171 
172   protected org.w3c.dom.Attr getAdapter() {
173     if (adapter == null) {
174       adapter = new DOMAttrImpl(this);
175     }
176     return adapter;
177   }
178   /* --------------------- END DOM ------------------------ */
179 
180 }