}
/**
*/
private void documentTypeChanged() {
IDOMDocument document = getDocument();
if (document == null)
return; // error
IDOMModel model = document.getModel();
if (model == null)
return; // error
IFile file = getFile(model);
// find DOCTYPE delcaration and Public ID
String publicId = null;
String systemId = null;
DocumentType newDocumentType = findDocumentType(document);
if (newDocumentType != null) {
publicId = newDocumentType.getPublicId();
systemId = newDocumentType.getSystemId();
}
else {
// lookup default set by contentsettings
publicId = HTMLContentProperties.getProperty(HTMLContentProperties.DOCUMENT_TYPE, file, true);
}
// lookup DOCTYPE registry
HTMLDocumentTypeEntry newEntry = null;
if (publicId != null) {
newEntry = HTMLDocumentTypeRegistry.getInstance().getEntry(publicId);
}
else if (systemId == null){
newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_HTML5);
}
boolean newXMLType = (newEntry != null ? newEntry.isXMLType() : false);
boolean newWMLType = (newEntry != null ? newEntry.isWMLType() : false);
if (!newXMLType) {
// find XML declaration
if (findXMLNode(document) != null) {
newXMLType = true;
}
// check file extension
if (file != null) {
String ext = file.getFileExtension();
if (ext != null && ext.equalsIgnoreCase(XHTML)) {
newXMLType = true;
}
if (ext != null && ext.equalsIgnoreCase(WML)) {
newXMLType = true;
newWMLType = true;
}
}
}
if (newEntry == null) {
// lookup system default
if (newXMLType && newDocumentType == null) {
// use default XHTML, if it's XML and no document type
// declared
if (newWMLType)
newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_WML);
else
newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_XHTML);
}
else {
newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_HTML);
}
if (newEntry == null)
return; // error
}
if (newDocumentType == null) {
DocumentType oldDocumentType = getDocumentType();
if (oldDocumentType == null || oldDocumentType.getName() != newEntry.getName()) {
// create implicit DocumentType
DOMImplementation impl = document.getImplementation();
if (impl != null) {
String name = newEntry.getName();
publicId = newEntry.getPublicId();
systemId = newEntry.getSystemId();
newDocumentType = impl.createDocumentType(name, publicId, systemId);