KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdom > DocType


1 /*--
2
3  $Id: DocType.java,v 1.31 2004/02/27 11:32:57 jhunter Exp $
4
5  Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
6  All rights reserved.
7
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions
10  are met:
11
12  1. Redistributions of source code must retain the above copyright
13     notice, this list of conditions, and the following disclaimer.
14
15  2. Redistributions in binary form must reproduce the above copyright
16     notice, this list of conditions, and the disclaimer that follows
17     these conditions in the documentation and/or other materials
18     provided with the distribution.
19
20  3. The name "JDOM" must not be used to endorse or promote products
21     derived from this software without prior written permission. For
22     written permission, please contact <request_AT_jdom_DOT_org>.
23
24  4. Products derived from this software may not be called "JDOM", nor
25     may "JDOM" appear in their name, without prior written permission
26     from the JDOM Project Management <request_AT_jdom_DOT_org>.
27
28  In addition, we request (but do not require) that you include in the
29  end-user documentation provided with the redistribution and/or in the
30  software itself an acknowledgement equivalent to the following:
31      "This product includes software developed by the
32       JDOM Project (http://www.jdom.org/)."
33  Alternatively, the acknowledgment may be graphical using the logos
34  available at http://www.jdom.org/images/logos.
35
36  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
40  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  SUCH DAMAGE.
48
49  This software consists of voluntary contributions made by many
50  individuals on behalf of the JDOM Project and was originally
51  created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
52  Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
53  on the JDOM Project, please see <http://www.jdom.org/>.
54
55  */

56
57 package org.jdom;
58
59 /**
60  * An XML DOCTYPE declaration. Method allow the user to get and set the
61  * root element name, public id, and system id.
62  *
63  * @author Brett McLaughlin
64  * @author Jason Hunter
65  * @version $Revision: 1.31 $, $Date: 2004/02/27 11:32:57 $
66  */

67 public class DocType extends Content {
68
69     private static final String JavaDoc CVS_ID =
70       "@(#) $RCSfile: DocType.java,v $ $Revision: 1.31 $ $Date: 2004/02/27 11:32:57 $ $Name: $";
71
72     /** The element being constrained */
73     protected String JavaDoc elementName;
74
75     /** The public ID of the DOCTYPE */
76     protected String JavaDoc publicID;
77
78     /** The system ID of the DOCTYPE */
79     protected String JavaDoc systemID;
80
81     /** The internal subset of the DOCTYPE */
82     protected String JavaDoc internalSubset;
83
84     /**
85      * Default, no-args constructor for implementations to use if needed.
86      */

87     protected DocType() {}
88
89     /*
90      * XXX:
91      * We need to take care of entities and notations here.
92      */

93
94     /**
95      * This will create the <code>DocType</code> with
96      * the specified element name and a reference to an
97      * external DTD.
98      *
99      * @param elementName <code>String</code> name of
100      * element being constrained.
101      * @param publicID <code>String</code> public ID of
102      * referenced DTD
103      * @param systemID <code>String</code> system ID of
104      * referenced DTD
105      * @throws IllegalDataException if the given system ID is not a legal
106      * system literal or the public ID is not a legal public ID.
107      * @throws IllegalNameException if the given root element name is not a
108      * legal XML element name.
109      */

110     public DocType(String JavaDoc elementName, String JavaDoc publicID, String JavaDoc systemID) {
111         setElementName(elementName);
112         setPublicID(publicID);
113         setSystemID(systemID);
114     }
115
116     /**
117      * This will create the <code>DocType</code> with
118      * the specified element name and reference to an
119      * external DTD.
120      *
121      * @param elementName <code>String</code> name of
122      * element being constrained.
123      * @param systemID <code>String</code> system ID of
124      * referenced DTD
125      * @throws IllegalDataException if the given system ID is not a legal
126      * system literal.
127      * @throws IllegalNameException if the given root element name is not a
128      * legal XML element name.
129      */

130     public DocType(String JavaDoc elementName, String JavaDoc systemID) {
131         this(elementName, null, systemID);
132     }
133
134     /**
135      * This will create the <code>DocType</code> with
136      * the specified element name
137      *
138      * @param elementName <code>String</code> name of
139      * element being constrained.
140      * @throws IllegalNameException if the given root element name is not a
141      * legal XML element name.
142      */

143     public DocType(String JavaDoc elementName) {
144         this(elementName, null, null);
145     }
146
147     /**
148      * This will retrieve the element name being constrained.
149      *
150      * @return <code>String</code> - element name for DOCTYPE
151      */

152     public String JavaDoc getElementName() {
153         return elementName;
154     }
155
156     /**
157      * This will set the root element name declared by this
158      * DOCTYPE declaration.
159      *
160      * @return DocType <code>DocType</code> this DocType object
161      * @param elementName <code>String</code> name of
162      * root element being constrained.
163      * @throws IllegalNameException if the given root element name is not a
164      * legal XML element name.
165      */

166     public DocType setElementName(String JavaDoc elementName) {
167         // This can contain a colon so we use checkXMLName()
168
// instead of checkElementName()
169
String JavaDoc reason = Verifier.checkXMLName(elementName);
170         if (reason != null) {
171             throw new IllegalNameException(elementName, "DocType", reason);
172         }
173         this.elementName = elementName;
174         return this;
175     }
176
177     /**
178      * This will retrieve the public ID of an externally
179      * referenced DTD, or an empty <code>String</code> if
180      * none is referenced.
181      *
182      * @return <code>String</code> - public ID of referenced DTD.
183      */

184     public String JavaDoc getPublicID() {
185         return publicID;
186     }
187
188     /**
189      * This will set the public ID of an externally
190      * referenced DTD.
191      *
192      * @param publicID id to set
193      * @return DocType <code>DocType</code> this DocType object
194      * @throws IllegalDataException if the given public ID is not a legal
195      * public ID.
196      */

197     public DocType setPublicID(String JavaDoc publicID) {
198         String JavaDoc reason = Verifier.checkPublicID(publicID);
199         if (reason != null) {
200             throw new IllegalDataException(publicID, "DocType", reason);
201         }
202         this.publicID = publicID;
203
204         return this;
205     }
206
207     /**
208      * This will retrieve the system ID of an externally
209      * referenced DTD, or an empty <code>String</code> if
210      * none is referenced.
211      *
212      * @return <code>String</code> - system ID of referenced DTD.
213      */

214     public String JavaDoc getSystemID() {
215         return systemID;
216     }
217
218     /**
219      * This will set the system ID of an externally
220      * referenced DTD.
221      *
222      * @param systemID id to set
223      * @return systemID <code>String</code> system ID of
224      * referenced DTD.
225      * @throws IllegalDataException if the given system ID is not a legal
226      * system literal.
227      */

228     public DocType setSystemID(String JavaDoc systemID) {
229         String JavaDoc reason = Verifier.checkSystemLiteral(systemID);
230         if (reason != null) {
231             throw new IllegalDataException(systemID, "DocType", reason);
232         }
233         this.systemID = systemID;
234
235         return this;
236     }
237
238     /**
239      * Returns the empty string since doctypes don't have an XPath
240      * 1.0 string value.
241      * @return the empty string
242      */

243     public String JavaDoc getValue() {
244         return ""; // doctypes don't have an XPath string value
245
}
246
247     /**
248      * This sets the data for the internal subset.
249      *
250      * @param newData data for the internal subset, as a
251      * <code>String</code>.
252      */

253     public void setInternalSubset(String JavaDoc newData) {
254         internalSubset = newData;
255     }
256
257     /**
258      * This returns the data for the internal subset.
259      *
260      * @return <code>String</code> - the internal subset
261      */

262     public String JavaDoc getInternalSubset() {
263         return internalSubset;
264     }
265
266     /**
267      * This returns a <code>String</code> representation of the
268      * <code>DocType</code>, suitable for debugging.
269      *
270      * @return <code>String</code> - information about the
271      * <code>DocType</code>
272      */

273     public String JavaDoc toString() {
274         return new StringBuffer JavaDoc()
275             .append("[DocType: ")
276             .append(new org.jdom.output.XMLOutputter().outputString(this))
277             .append("]")
278             .toString();
279     }
280 }
281
Popular Tags