package org.jdom; import java.io.Serializable; /** *
DocType represents an XML
* DOCTYPE declaration.
*
* Default, no-args constructor for implementations * to use if needed. *
*/ protected DocType() {} /** *
* This will create the DocType with
* the specified element name
*
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.
*
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.
*
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.
*
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.
*
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}.
*
Document owning this DocType, or null.
*/
public Document getDocument() {
return this.document;
}
/**
* * This will retrieve the element name being * constrained. *
* * @returnString - 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.
*
String - public ID of referenced DTD.
*/
public String getPublicID() {
return publicID;
}
/**
*
* This will return the DocType in XML format,
* usable in an XML document.
*
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.
*
String - system ID of referenced DTD.
*/
public String getSystemID() {
return systemID;
}
/**
*
* This returns the hash code for this DocType.
*
int - hash code.
*/
public final int hashCode() {
return super.hashCode();
}
/**
*
* This sets the {@link Document} holding this doctype.
*
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 publicIDString 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 systemIDString 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.
*
String - information about the
* DocType
*/
public String toString() {
return new StringBuffer()
.append("[DocType: ")
.append(new org.jdom.output.XMLOutputter().outputString(this))
.append("]")
.toString();
}
}