KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > Doctype


1 package org.apache.ecs;
2
3 /*
4  * ====================================================================
5  *
6  * The Apache Software License, Version 1.1
7  *
8  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
9  * reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution, if
24  * any, must include the following acknowlegement:
25  * "This product includes software developed by the
26  * Apache Software Foundation (http://www.apache.org/)."
27  * Alternately, this acknowlegement may appear in the software itself,
28  * if and wherever such third-party acknowlegements normally appear.
29  *
30  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
31  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
32  * to endorse or promote products derived
33  * from this software without prior written permission. For written
34  * permission, please contact apache@apache.org.
35  *
36  * 5. Products derived from this software may not be called "Apache",
37  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
38  * appear in their names without prior written permission of the Apache Group.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Apache Software Foundation. For more
56  * information on the Apache Software Foundation, please see
57  * <http://www.apache.org/>.
58  *
59  */

60
61 import org.apache.ecs.*;
62
63 /**
64  * This class creates a &lt;!DOCTYPE&gt; tag.<p>
65  *
66  * Format:<br>
67      &lt;!DOCTYPE [name] [visibility] [identifier] [uri]&gt;<p>
68     <p>
69     usage:<br>
70     Document d = new Document()<br>
71         .setDoctype(new Doctype.Html40Strict())<br>
72     <p> or <p>
73     XMLDocument d = new XMLDocument()<br>
74         .addToProlog( new Doctype( "foo", "\"--/bar/baz/en\"", "\"http://qoz.net/foo.dtd\"" );<br>
75  * .addElement( new XML( ...
76  *
77  * @see Doctype.Html40Strict
78  * @see Doctype.Html40Transitional
79  * @see Doctype.Html40Frameset
80  * @see Doctype.XHtml10Strict
81  * @see Doctype.XHtml10Transitional
82  * @see Doctype.XHtml10Frameset
83  *
84  * @version $Id: Doctype.java,v 1.6 2003/04/27 09:43:30 rdonkin Exp $
85  * @author <a HREF="mailto:heuermh@shore.net">Michael Heuer</a>
86  * @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
87  * @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
88  * @author <a HREF="mailto:brucedu@netscape.net">Bruce Durling</a>
89  * @author <a HREF="mailto:bojan@binarix.com">Bojan Smojver</a>
90  * @author Yuji Kumasaka
91 */

92 public class Doctype extends SinglePartElement implements Printable
93 {
94     public static final String JavaDoc elementName = "!DOCTYPE";
95     public static final String JavaDoc PUBLIC = "PUBLIC";
96     
97     protected String JavaDoc name;
98     protected String JavaDoc visibility;
99     protected String JavaDoc identifier;
100     protected String JavaDoc uri;
101
102     {
103         setElementType(elementName);
104         setCase(Element.UPPERCASE);
105     }
106     
107     /**
108      * Basic Constructor.
109      *
110      */

111     public Doctype()
112     {
113         updateElementType();
114     }
115
116
117     /**
118      * Constructor.
119      *
120      * @param name Root element of the XML document.
121      * @param id Public identifier.
122      * @param uri URI of the DTD.
123      */

124     public Doctype( String JavaDoc name, String JavaDoc id, String JavaDoc uri )
125     {
126         this.name = name;
127         this.visibility = PUBLIC;
128         this.identifier = id;
129         this.uri = uri;
130         updateElementType();
131     }
132     
133     /**
134      * Constructor.
135      *
136      * @param name Root element of the XML document.
137      * @param id Public identifier.
138      * @param uri URI of the DTD.
139      */

140     public Doctype( String JavaDoc name, String JavaDoc visibility, String JavaDoc id, String JavaDoc uri )
141     {
142         this.name = name;
143         this.visibility = visibility;
144         this.identifier = id;
145         this.uri = uri;
146         updateElementType();
147     }
148
149     /**
150      * Should be called when any of the fields are changed.
151      *
152      */

153     protected void updateElementType()
154     {
155         setElementType( elementName
156                         + " " + name
157                         + " " + visibility
158                         + " " + identifier
159                         + " " + uri );
160     }
161
162     /**
163      * Updates the name of the root element.
164      *
165      * @param name Name of the root element.
166      * @return a value of type 'Doctype'
167      */

168     public Doctype setName( String JavaDoc name )
169     {
170         this.name = name;
171         updateElementType();
172         return( this );
173     }
174     /**
175      * Updates the name of the root element.
176      *
177      * @param name Name of the root element.
178      * @return a value of type 'Doctype'
179      */

180     public Doctype setVisibility( String JavaDoc visibility )
181     {
182         this.visibility = visibility;
183         updateElementType();
184         return( this );
185     }
186     
187     /**
188      * Updates the name of the public identifier.
189      *
190      * @param identifier The public identifier.
191      * @return a value of type 'Doctype'
192      */

193     public Doctype setIdentifier( String JavaDoc identifier )
194     {
195         this.identifier = identifier;
196         updateElementType();
197         return( this );
198     }
199     
200     /**
201      * Updates the URI of the dtd.
202      *
203      * @param uri URI of the dtd.
204      * @return a value of type 'Doctype'
205      */

206     public Doctype setUri( String JavaDoc uri )
207     {
208         this.uri = uri;
209         updateElementType();
210         return(this);
211     }
212
213     /**
214      * Adds and Element to the element.
215      *
216      * @param hashcode name of the element for hash table.
217      * @param element Adds an Element to the element.
218      * @return a value of type 'Doctype'
219      */

220     public Doctype addElement( String JavaDoc hashcode, Element element )
221     {
222         addElementToRegistry( hashcode, element );
223         return(this);
224     }
225
226     /**
227      * Adds an Element to the element.
228      *
229      * @param hashcode name of the element for the hash table.
230      * @param element Adds an Element to the element.
231      * @return a value of type 'Doctype'
232      */

233     public Doctype addElement( String JavaDoc hashcode, String JavaDoc element )
234     {
235         addElementToRegistry(hashcode,element);
236         return(this);
237     }
238     
239     /**
240      * Adds an Element to the element.
241      *
242      * @param element Adds an Element to the element.
243      * @return a value of type 'Doctype'
244      */

245     public Doctype addElement(Element element)
246     {
247         addElementToRegistry(element);
248         return(this);
249     }
250
251     /**
252      * Adds an Element to the element.
253      *
254      * @param element Adds an Element to the element.
255      * @return a value of type 'Doctype'
256      */

257     public Doctype addElement(String JavaDoc element)
258     {
259         addElementToRegistry(element);
260         return(this);
261     }
262     
263     /**
264      * Removes an Element from the element.
265      *
266      * @param hashcode the name of the element to be removed.
267      * @return a value of type 'Doctype'
268      */

269     public Doctype removeElement(String JavaDoc hashcode)
270     {
271         removeElementFromRegistry(hashcode);
272         return(this);
273     }
274
275     /**
276      * The HTML 4.0 Strict DTD includes all elements and attributes
277      * that have not been deprecated or do not appear in frameset
278      * documents.
279      * <p>
280      * See: <a HREF="http://www.w3.org/TR/REC-html40/sgml/dtd.html">
281      * http://www.w3.org/TR/REC-html40/sgml/dtd.html</a>
282      */

283     public static class Html40Strict extends Doctype {
284
285         public Html40Strict() {
286             this.name = "HTML";
287             this.visibility = PUBLIC;
288             this.identifier = "\"-//W3C//DTD HTML 4.0//EN\"";
289             this.uri = "\"http://www.w3.org/TR/REC-html40/strict.dtd\"";
290             this.updateElementType();
291         }
292     }
293
294     /**
295      * The HTML 4.0 Transitional DTD includes everything in the
296      * strict DTD plus deprecated elements and attributes (most of
297      * which concern visual presentation).
298      * <p>
299      * See: <a HREF="http://www.w3.org/TR/REC-html40/sgml/loosedtd.html">
300      * http://www.w3.org/TR/REC-html40/sgml/loosedtd.html</a>
301      */

302     public static class Html40Transitional extends Doctype {
303
304         public Html40Transitional() {
305             this.name = "HTML";
306             this.visibility = PUBLIC;
307             this.identifier = "\"-//W3C//DTD HTML 4.0 Transitional//EN\"";
308             this.uri = "\"http://www.w3.org/TR/REC-html40/loose.dtd\"";
309             this.updateElementType();
310         }
311     }
312
313     /**
314      * The HTML 4.0 Frameset DTD includes everything in the transitional
315      * DTD plus frames as well.
316      * <p>
317      * See: <a HREF="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html">
318      * http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html</a>
319      */

320     public static class Html40Frameset extends Doctype {
321
322         public Html40Frameset() {
323             this.name = "HTML";
324             this.visibility = PUBLIC;
325             this.identifier = "\"-//W3C//DTD HTML 4.0 Frameset//EN\"";
326             this.uri = "\"http://www.w3.org/TR/REC-html40/frameset.dtd\"";
327             this.updateElementType();
328         }
329     }
330
331     /**
332      * The HTML 4.01 Strict DTD includes all elements and attributes
333      * that have not been deprecated or do not appear in frameset
334      * documents.
335      * <p>
336      * See: <a HREF="http://www.w3.org/TR/html4/">
337      * http://www.w3.org/TR/html4/</a>
338      */

339     public static class Html401Strict extends Doctype {
340
341         public Html401Strict() {
342             this.name = "HTML";
343             this.visibility = PUBLIC;
344             this.identifier = "\"-//W3C//DTD HTML 4.01//EN\"";
345             this.uri = "\"http://www.w3.org/TR/html4/strict.dtd\"";
346             this.updateElementType();
347         }
348     }
349
350     /**
351      * The HTML 4.01 Transitional DTD includes everything in the
352      * strict DTD plus deprecated elements and attributes (most of
353      * which concern visual presentation).
354      * <p>
355      * See: <a HREF="http://www.w3.org/TR/html4/">
356      * http://www.w3.org/TR/html4/</a>
357      */

358     public static class Html401Transitional extends Doctype {
359
360         public Html401Transitional() {
361             this.name = "HTML";
362             this.visibility = PUBLIC;
363             this.identifier = "\"-//W3C//DTD HTML 4.01 Transitional//EN\"";
364             this.uri = "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\"";
365             this.updateElementType();
366         }
367     }
368
369     /**
370      * The HTML 4.01 Frameset DTD includes everything in the transitional
371      * DTD plus frames as well.
372      * <p>
373      * See: <a HREF="http://www.w3.org/TR/html4/">
374      * http://www.w3.org/TR/html4/</a>
375      */

376     public static class Html401Frameset extends Doctype {
377
378         public Html401Frameset() {
379             this.name = "HTML";
380             this.visibility = PUBLIC;
381             this.identifier = "\"-//W3C//DTD HTML 4.01 Frameset//EN\"";
382             this.uri = "\"http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd\"";
383             this.updateElementType();
384         }
385     }
386
387     /**
388      * The XHTML 1.0 Strict DTD
389      * This is the same as HTML 4.0 Strict except for changes due
390      * to the differences between XML and SGML.
391      * <p>
392      * See: <a HREF="http://www.w3.org/TR/xhtml1">
393      * http://www.w3.org/TR/xhtml1</a>
394      */

395     public static class XHtml10Strict extends Doctype {
396
397         public XHtml10Strict() {
398             this.name = "html";
399             this.visibility = PUBLIC;
400             this.identifier = "\"-//W3C//DTD XHTML 1.0 Strict//EN\"";
401             this.uri = "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"";
402             this.updateElementType();
403         }
404     }
405
406     /**
407      * The XHTML 1.0 Transitional DTD
408      * This is the same as HTML 4.0 Transitional except for changes due
409      * to the differences between XML and SGML.
410      * <p>
411      * See: <a HREF="http://www.w3.org/TR/xhtml1">
412      * http://www.w3.org/TR/xhtml1</a>
413      */

414     public static class XHtml10Transitional extends Doctype {
415
416         public XHtml10Transitional() {
417             this.name = "html";
418             this.visibility = PUBLIC;
419             this.identifier = "\"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
420             this.uri =
421                 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"";
422             this.updateElementType();
423         }
424     }
425
426     /**
427      * The XHTML 1.0 Frameset DTD
428      * This is the same as HTML 4.0 Frameset except for changes due
429      * to the differences between XML and SGML.
430      * <p>
431      * See: <a HREF="http://www.w3.org/TR/xhtml1">
432      * http://www.w3.org/TR/xhtml1</a>
433      */

434     public static class XHtml10Frameset extends Doctype {
435
436         public XHtml10Frameset() {
437             this.name = "html";
438             this.visibility = PUBLIC;
439             this.identifier = "\"-//W3C//DTD XHTML 1.0 Frameset//EN\"";
440             this.uri =
441                 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\"";
442             this.updateElementType();
443         }
444     }
445 }
446
Popular Tags