package org.jdom; import java.io.Serializable; /** *

DocType represents an XML * DOCTYPE declaration. *

* * @author Brett McLaughlin * @author Jason Hunter * @version 1.0 */ public class DocType implements Serializable, Cloneable { private static final String CVS_ID = "@(#) $RCSfile: DocType.java,v $ $Revision: 1.14 $ $Date: 2001/04/27 18:21:19 $ $Name: $"; /** The element being constrained */ protected String elementName; /** The public ID of the DOCTYPE */ protected String publicID; /** The system ID of the DOCTYPE */ protected String systemID; /** The document having this DOCTYPE */ protected Document document; /** The internal subset of the DOCTYPE */ protected String internalSubset; /** *

* Default, no-args constructor for implementations * to use if needed. *

*/ protected DocType() {} /** *

* This will create the DocType with * the specified element name *

* * @param elementName String name of * element being constrained. */ public DocType(String elementName) { this(elementName, "", ""); } /** *

* This will create the DocType with * the specified element name and reference to an * external DTD. *

* * @param elementName String name of * element being constrained. * @param systemID String system ID of * referenced DTD */ public DocType(String elementName, String systemID) { this(elementName, "", systemID); } /* * XXX: * We need to take care of entities and notations here. */ /** *

* This will create the DocType with * the specified element name and a reference to an * external DTD. *

* * @param elementName String name of * element being constrained. * @param publicID String public ID of * referenced DTD * @param systemID String system ID of * referenced DTD */ public DocType(String elementName, String publicID, String systemID) { this.elementName = elementName; this.publicID = publicID; this.systemID = systemID; } /** *

* This will return a clone of this DocType. *

* * @return Object - clone of this DocType. */ public Object clone() { DocType docType = null; try { docType = (DocType) super.clone(); } catch (CloneNotSupportedException ce) { // Can't happen } docType.document = null; // elementName, publicID, and systemID are all immutable // (Strings) and references are copied by Object.clone() return docType; } /** *

* This tests for equality of this DocType to the supplied * Object. *

* * @param ob Object to compare to. * @return boolean - whether the DocType is * equal to the supplied Object. */ public final boolean equals(Object ob) { if (ob instanceof DocType) { DocType dt = (DocType) ob; return (stringEquals(dt.elementName, elementName) && stringEquals(dt.publicID, publicID) && stringEquals(dt.systemID, systemID)); } return false; } /** *

* This retrieves the owning {@link Document} for * this DocType, or null if not a currently a member of a * {@link Document}. *

* * @return Document owning this DocType, or null. */ public Document getDocument() { return this.document; } /** *

* This will retrieve the element name being * constrained. *

* * @return String - element name for DOCTYPE */ public String getElementName() { return elementName; } /** * get the data for the internal subset * * @return java.lang.String */ public java.lang.String getInternalSubset() { return internalSubset; } /** *

* This will retrieve the public ID of an externally * referenced DTD, or an empty String if * none is referenced. *

* * @return String - public ID of referenced DTD. */ public String getPublicID() { return publicID; } /** *

* This will return the DocType in XML format, * usable in an XML document. *

* * @return String - the serialized form of the * DocType. * * @deprecated Deprecated in Beta7, use XMLOutputter.outputString(DocType) * instead */ public final String getSerializedForm() { boolean hasPublic = false; StringBuffer serForm = new StringBuffer() .append(""); return serForm.toString(); } /** *

* This will retrieve the system ID of an externally * referenced DTD, or an empty String if * none is referenced. *

* * @return String - system ID of referenced DTD. */ public String getSystemID() { return systemID; } /** *

* This returns the hash code for this DocType. *

* * @return int - hash code. */ public final int hashCode() { return super.hashCode(); } /** *

* This sets the {@link Document} holding this doctype. *

* * @param document Document holding this doctype * @return Document this DocType modified */ protected DocType setDocument(Document document) { this.document = document; return this; } /** * set the data for the internal subset * * @param newData java.lang.String */ public void setInternalSubset(java.lang.String newData) { internalSubset = newData; } /** *

* This will set the public ID of an externally * referenced DTD. *

* * @return publicID String public ID of * referenced DTD. */ public DocType setPublicID(String publicID) { this.publicID = publicID; return this; } /** *

* This will set the system ID of an externally * referenced DTD. *

* * @return systemID String system ID of * referenced DTD. */ public DocType setSystemID(String systemID) { this.systemID = systemID; return this; } // Utility function to help with equals() private boolean stringEquals(String s1, String s2) { if (s1 == null && s2 == null) { return true; } else if (s1 == null && s2 != null) { return false; } else { // If we get here we know s1 can't be null return s1.equals(s2); } } /** *

* This returns a String representation of the * DocType, suitable for debugging. *

* * @return String - information about the * DocType */ public String toString() { return new StringBuffer() .append("[DocType: ") .append(new org.jdom.output.XMLOutputter().outputString(this)) .append("]") .toString(); } }