001: /*--
002:
003: $Id: DocType.java,v 1.1 2005/04/27 09:32:38 wittek Exp $
004:
005: Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without
009: modification, are permitted provided that the following conditions
010: are met:
011:
012: 1. Redistributions of source code must retain the above copyright
013: notice, this list of conditions, and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright
016: notice, this list of conditions, and the disclaimer that follows
017: these conditions in the documentation and/or other materials
018: provided with the distribution.
019:
020: 3. The name "JDOM" must not be used to endorse or promote products
021: derived from this software without prior written permission. For
022: written permission, please contact <request_AT_jdom_DOT_org>.
023:
024: 4. Products derived from this software may not be called "JDOM", nor
025: may "JDOM" appear in their name, without prior written permission
026: from the JDOM Project Management <request_AT_jdom_DOT_org>.
027:
028: In addition, we request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by the
032: JDOM Project (http://www.jdom.org/)."
033: Alternatively, the acknowledgment may be graphical using the logos
034: available at http://www.jdom.org/images/logos.
035:
036: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
040: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: SUCH DAMAGE.
048:
049: This software consists of voluntary contributions made by many
050: individuals on behalf of the JDOM Project and was originally
051: created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
052: Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
053: on the JDOM Project, please see <http://www.jdom.org/>.
054:
055: */
056:
057: package org.jdom;
058:
059: /**
060: * An XML DOCTYPE declaration. Method allow the user to get and set the
061: * root element name, public id, and system id.
062: *
063: * @author Brett McLaughlin
064: * @author Jason Hunter
065: * @version $Revision: 1.1 $, $Date: 2005/04/27 09:32:38 $
066: */
067: public class DocType extends Content {
068:
069: private static final String CVS_ID = "@(#) $RCSfile: DocType.java,v $ $Revision: 1.1 $ $Date: 2005/04/27 09:32:38 $ $Name: $";
070:
071: /** The element being constrained */
072: protected String elementName;
073:
074: /** The public ID of the DOCTYPE */
075: protected String publicID;
076:
077: /** The system ID of the DOCTYPE */
078: protected String systemID;
079:
080: /** The internal subset of the DOCTYPE */
081: protected String internalSubset;
082:
083: /**
084: * Default, no-args constructor for implementations to use if needed.
085: */
086: protected DocType() {
087: }
088:
089: /*
090: * XXX:
091: * We need to take care of entities and notations here.
092: */
093:
094: /**
095: * This will create the <code>DocType</code> with
096: * the specified element name and a reference to an
097: * external DTD.
098: *
099: * @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 elementName, String publicID, String 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 elementName, String 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 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 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 elementName) {
167: // This can contain a colon so we use checkXMLName()
168: // instead of checkElementName()
169: String reason = Verifier.checkXMLName(elementName);
170: if (reason != null) {
171: throw new IllegalNameException(elementName, "DocType",
172: reason);
173: }
174: this .elementName = elementName;
175: return this ;
176: }
177:
178: /**
179: * This will retrieve the public ID of an externally
180: * referenced DTD, or an empty <code>String</code> if
181: * none is referenced.
182: *
183: * @return <code>String</code> - public ID of referenced DTD.
184: */
185: public String getPublicID() {
186: return publicID;
187: }
188:
189: /**
190: * This will set the public ID of an externally
191: * referenced DTD.
192: *
193: * @param publicID id to set
194: * @return DocType <code>DocType</code> this DocType object
195: * @throws IllegalDataException if the given public ID is not a legal
196: * public ID.
197: */
198: public DocType setPublicID(String publicID) {
199: String reason = Verifier.checkPublicID(publicID);
200: if (reason != null) {
201: throw new IllegalDataException(publicID, "DocType", reason);
202: }
203: this .publicID = publicID;
204:
205: return this ;
206: }
207:
208: /**
209: * This will retrieve the system ID of an externally
210: * referenced DTD, or an empty <code>String</code> if
211: * none is referenced.
212: *
213: * @return <code>String</code> - system ID of referenced DTD.
214: */
215: public String getSystemID() {
216: return systemID;
217: }
218:
219: /**
220: * This will set the system ID of an externally
221: * referenced DTD.
222: *
223: * @param systemID id to set
224: * @return systemID <code>String</code> system ID of
225: * referenced DTD.
226: * @throws IllegalDataException if the given system ID is not a legal
227: * system literal.
228: */
229: public DocType setSystemID(String systemID) {
230: String reason = Verifier.checkSystemLiteral(systemID);
231: if (reason != null) {
232: throw new IllegalDataException(systemID, "DocType", reason);
233: }
234: this .systemID = systemID;
235:
236: return this ;
237: }
238:
239: /**
240: * Returns the empty string since doctypes don't have an XPath
241: * 1.0 string value.
242: * @return the empty string
243: */
244: public String getValue() {
245: return ""; // doctypes don't have an XPath string value
246: }
247:
248: /**
249: * This sets the data for the internal subset.
250: *
251: * @param newData data for the internal subset, as a
252: * <code>String</code>.
253: */
254: public void setInternalSubset(String newData) {
255: internalSubset = newData;
256: }
257:
258: /**
259: * This returns the data for the internal subset.
260: *
261: * @return <code>String</code> - the internal subset
262: */
263: public String getInternalSubset() {
264: return internalSubset;
265: }
266:
267: /**
268: * This returns a <code>String</code> representation of the
269: * <code>DocType</code>, suitable for debugging.
270: *
271: * @return <code>String</code> - information about the
272: * <code>DocType</code>
273: */
274: public String toString() {
275: return new StringBuffer().append("[DocType: ").append(
276: new org.jdom.output.XMLOutputter().outputString(this ))
277: .append("]").toString();
278: }
279: }
|