View Javadoc

1   /*
2    *  Java HTML Tidy - JTidy
3    *  HTML parser and pretty printer
4    *
5    *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6    *  Institute of Technology, Institut National de Recherche en
7    *  Informatique et en Automatique, Keio University). All Rights
8    *  Reserved.
9    *
10   *  Contributing Author(s):
11   *
12   *     Dave Raggett <dsr@w3.org>
13   *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14   *     Gary L Peskin <garyp@firstech.com> (Java development)
15   *     Sami Lempinen <sami@lempinen.net> (release management)
16   *     Fabrizio Giustina <fgiust at users.sourceforge.net>
17   *
18   *  The contributing author(s) would like to thank all those who
19   *  helped with testing, bug fixes, and patience.  This wouldn't
20   *  have been possible without all of you.
21   *
22   *  COPYRIGHT NOTICE:
23   * 
24   *  This software and documentation is provided "as is," and
25   *  the copyright holders and contributing author(s) make no
26   *  representations or warranties, express or implied, including
27   *  but not limited to, warranties of merchantability or fitness
28   *  for any particular purpose or that the use of the software or
29   *  documentation will not infringe any third party patents,
30   *  copyrights, trademarks or other rights. 
31   *
32   *  The copyright holders and contributing author(s) will not be
33   *  liable for any direct, indirect, special or consequential damages
34   *  arising out of any use of the software or documentation, even if
35   *  advised of the possibility of such damage.
36   *
37   *  Permission is hereby granted to use, copy, modify, and distribute
38   *  this source code, or portions hereof, documentation and executables,
39   *  for any purpose, without fee, subject to the following restrictions:
40   *
41   *  1. The origin of this source code must not be misrepresented.
42   *  2. Altered versions must be plainly marked as such and must
43   *     not be misrepresented as being the original source.
44   *  3. This Copyright notice may not be removed or altered from any
45   *     source or altered source distribution.
46   * 
47   *  The copyright holders and contributing author(s) specifically
48   *  permit, without fee, and encourage the use of this source code
49   *  as a component for supporting the Hypertext Markup Language in
50   *  commercial products. If you use this source code in a product,
51   *  acknowledgment is not required but would be appreciated.
52   *
53   */
54  package org.w3c.tidy;
55  
56  /**
57   * Tag dictionary node. If the document uses just HTML 2.0 tags and attributes described it as HTML 2.0 Similarly for
58   * HTML 3.2 and the 3 flavors of HTML 4.0. If there are proprietary tags and attributes then describe it as HTML
59   * Proprietary. If it includes the xml-lang or xmlns attributes but is otherwise HTML 2.0, 3.2 or 4.0 then describe it
60   * as one of the flavors of Voyager (strict, loose or frameset).
61   * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
62   * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
63   * @author Fabrizio Giustina
64   * @version $Revision: 779 $ ($Author: fgiust $)
65   */
66  public class Dict
67  {
68  
69      /**
70       * Content model: unknown.
71       */
72      public static final int CM_UNKNOWN = 0;
73  
74      /**
75       * Content model: empty.
76       */
77      public static final int CM_EMPTY = (1 << 0);
78  
79      /**
80       * Content model: html.
81       */
82      public static final int CM_HTML = (1 << 1);
83  
84      /**
85       * Content model: head.
86       */
87      public static final int CM_HEAD = (1 << 2);
88  
89      /**
90       * Content model: block.
91       */
92      public static final int CM_BLOCK = (1 << 3);
93  
94      /**
95       * Content model: inline.
96       */
97      public static final int CM_INLINE = (1 << 4);
98  
99      /**
100      * Content model: list.
101      */
102     public static final int CM_LIST = (1 << 5);
103 
104     /**
105      * Content model: definition list.
106      */
107     public static final int CM_DEFLIST = (1 << 6);
108 
109     /**
110      * Content model: table.
111      */
112     public static final int CM_TABLE = (1 << 7);
113 
114     /**
115      * Content model: rowgroup.
116      */
117     public static final int CM_ROWGRP = (1 << 8);
118 
119     /**
120      * Content model: row.
121      */
122     public static final int CM_ROW = (1 << 9);
123 
124     /**
125      * Content model: field.
126      */
127     public static final int CM_FIELD = (1 << 10);
128 
129     /**
130      * Content model: object.
131      */
132     public static final int CM_OBJECT = (1 << 11);
133 
134     /**
135      * Content model: param.
136      */
137     public static final int CM_PARAM = (1 << 12);
138 
139     /**
140      * Content model: frames.
141      */
142     public static final int CM_FRAMES = (1 << 13);
143 
144     /**
145      * Content model: heading.
146      */
147     public static final int CM_HEADING = (1 << 14);
148 
149     /**
150      * Content model: opt.
151      */
152     public static final int CM_OPT = (1 << 15);
153 
154     /**
155      * Content model: img.
156      */
157     public static final int CM_IMG = (1 << 16);
158 
159     /**
160      * Content model: mixed.
161      */
162     public static final int CM_MIXED = (1 << 17);
163 
164     /**
165      * Content model: no indent.
166      */
167     public static final int CM_NO_INDENT = (1 << 18);
168 
169     /**
170      * Content model: obsolete.
171      */
172     public static final int CM_OBSOLETE = (1 << 19);
173 
174     /**
175      * Content model: new.
176      */
177     public static final int CM_NEW = (1 << 20);
178 
179     /**
180      * Content model: omitst.
181      */
182     public static final int CM_OMITST = (1 << 21);
183 
184     /**
185      * Version: unknown.
186      */
187     public static final short VERS_UNKNOWN = 0;
188 
189     /**
190      * Version: html 2.0.
191      */
192     public static final short VERS_HTML20 = 1;
193 
194     /**
195      * Version: html 3.2.
196      */
197     public static final short VERS_HTML32 = 2;
198 
199     /**
200      * Version: html 4.0 strict.
201      */
202     public static final short VERS_HTML40_STRICT = 4;
203 
204     /**
205      * Version: html 4.0 transitional.
206      */
207     public static final short VERS_HTML40_LOOSE = 8;
208 
209     /**
210      * Version: html 4.0 frameset.
211      */
212     public static final short VERS_FRAMESET = 16;
213 
214     /**
215      * Version: xml.
216      */
217     public static final short VERS_XML = 32;
218 
219     /**
220      * Version: netscape.
221      */
222     public static final short VERS_NETSCAPE = 64;
223 
224     /**
225      * Version: microsoft.
226      */
227     public static final short VERS_MICROSOFT = 128;
228 
229     /**
230      * Version: sun.
231      */
232     public static final short VERS_SUN = 256;
233 
234     /**
235      * Version: malformed.
236      */
237     public static final short VERS_MALFORMED = 512;
238 
239     /**
240      * Version: xhtml 1.1.
241      */
242     public static final short VERS_XHTML11 = 1024;
243 
244     /**
245      * Version: xhtml basic.
246      */
247     public static final short VERS_BASIC = 2048;
248 
249     /**
250      * all tags and attributes are ok in proprietary version of HTML.
251      */
252     public static final short VERS_PROPRIETARY = (VERS_NETSCAPE | VERS_MICROSOFT | VERS_SUN);
253 
254     /**
255      * tags/attrs in HTML4 but not in earlier version.
256      */
257     public static final short VERS_HTML40 = (VERS_HTML40_STRICT | VERS_HTML40_LOOSE | VERS_FRAMESET);
258 
259     /**
260      * tags/attrs which are in all versions of HTML except strict.
261      */
262     public static final short VERS_LOOSE = (VERS_HTML32 | VERS_HTML40_LOOSE | VERS_FRAMESET);
263 
264     /**
265      * tags/attrs in HTML 4 loose and frameset.
266      */
267     public static final short VERS_IFRAME = (VERS_HTML40_LOOSE | VERS_FRAMESET);
268 
269     /**
270      * tags/attrs in all versions from HTML 3.2 onwards.
271      */
272     public static final short VERS_FROM32 = (VERS_HTML40_STRICT | VERS_LOOSE);
273 
274     /**
275      * versions with on... attributes.
276      */
277     public static final short VERS_EVENTS = (VERS_HTML40 | VERS_XHTML11);
278 
279     /**
280      * tags/attrs in any version.
281      */
282     public static final short VERS_ALL = (VERS_HTML20 | VERS_HTML32 | VERS_HTML40 | VERS_XHTML11 | VERS_BASIC);
283 
284     /**
285      * types of tags that the user can define: empty tag.
286      */
287     public static final short TAGTYPE_EMPTY = 1;
288 
289     /**
290      * types of tags that the user can define: inline tag.
291      */
292     public static final short TAGTYPE_INLINE = 2;
293 
294     /**
295      * types of tags that the user can define: block tag.
296      */
297     public static final short TAGTYPE_BLOCK = 4;
298 
299     /**
300      * types of tags that the user can define: pre tag.
301      */
302     public static final short TAGTYPE_PRE = 8;
303 
304     /**
305      * Tag name.
306      */
307     protected String name;
308 
309     /**
310      * Version in which this tag is defined.
311      */
312     protected short versions;
313 
314     /**
315      * model (CM_* constants).
316      */
317     protected int model;
318 
319     /**
320      * Parser for this tag.
321      */
322     private Parser parser;
323 
324     /**
325      * Validator for this tag.
326      */
327     private TagCheck chkattrs;
328 
329     /**
330      * Instantiates a new Tag definition.
331      * @param name tag name
332      * @param versions version in which this tag is defined
333      * @param model model (CM_* constants)
334      * @param parser parser for this tag
335      * @param chkattrs validator for this tag (can be null)
336      */
337     public Dict(String name, short versions, int model, Parser parser, TagCheck chkattrs)
338     {
339         this.name = name;
340         this.versions = versions;
341         this.model = model;
342         this.parser = parser;
343         this.chkattrs = chkattrs;
344     }
345 
346     /**
347      * Getter for <code>chkattrs</code>.
348      * @return Returns the chkattrs.
349      */
350     public TagCheck getChkattrs()
351     {
352         return this.chkattrs;
353     }
354 
355     /**
356      * Getter for <code>model</code>.
357      * @return Returns the model.
358      */
359     public int getModel()
360     {
361         return this.model;
362     }
363 
364     /**
365      * Getter for <code>name</code>.
366      * @return Returns the name.
367      */
368     public String getName()
369     {
370         return this.name;
371     }
372 
373     /**
374      * Getter for <code>parser</code>.
375      * @return Returns the parser.
376      */
377     public Parser getParser()
378     {
379         return this.parser;
380     }
381 
382     /**
383      * Setter for <code>chkattrs</code>.
384      * @param chkattrs The chkattrs to set.
385      */
386     public void setChkattrs(TagCheck chkattrs)
387     {
388         this.chkattrs = chkattrs;
389     }
390     /**
391      * Getter for <code>versions</code>.
392      * @return Returns the versions.
393      */
394     public short getVersions()
395     {
396         return this.versions;
397     }
398     /**
399      * Setter for <code>parser</code>.
400      * @param parser The parser to set.
401      */
402     public void setParser(Parser parser)
403     {
404         this.parser = parser;
405     }
406 }