use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class HTMLDocumentTypeAdapter method documentTypeChanged.
/**
*/
private void documentTypeChanged() {
IDOMDocument document = getDocument();
if (document == null)
// error
return;
IDOMModel model = document.getModel();
if (model == null)
// error
return;
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) {
// 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)
// error
return;
}
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);
}
}
}
boolean notify = false;
if (this.entry != null) {
// do not notify on initialization
notify = (newEntry != this.entry || newXMLType != this.isXMLType);
}
if (newDocumentType != null)
setDocumentType(newDocumentType);
this.entry = newEntry;
this.isXMLType = newXMLType;
if (notify)
notifyDocumentTypeChanged();
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class DOMImplementationTests method testCreateDocument.
public void testCreateDocument() {
final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
final DocumentType doctype = model.createDocumentType("bar", "publicTest", "systemTest");
final Document document = model.createDocument("http://eclipse.org", "foo:bar", doctype);
assertEquals("Document's doctype was not properly set", doctype, document.getDoctype());
assertEquals("Document owner node is not set properly", document, doctype.getOwnerDocument());
final Node node = document.getDocumentElement();
assertNotNull("Document should not be empty", node);
assertEquals("Element qualified name is not equal", "foo:bar", node.getNodeName());
assertEquals("Element namespace URI is not equal", "http://eclipse.org", node.getNamespaceURI());
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class DOMImplementationTests method testCreateDocumentUsedDoctype.
public void testCreateDocumentUsedDoctype() {
final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
final DocumentType doctype = model.createDocumentType("bar", "publicTest", "systemTest");
IDOMDocument document = model.getDocument();
document.appendChild(doctype);
try {
model.createDocument("http://eclipse.org", "foo:bar", doctype);
} catch (DOMException e) {
assertEquals("Wrong DOMExcetion thrown", DOMException.WRONG_DOCUMENT_ERR, e.code);
return;
}
fail("Reusing the doctype from another document should have caused an exception");
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class DeploymentDescriptorPropertyCache method _parseDocument.
private void _parseDocument(IPath path, Float[] version, List groupList, List urlPatterns, SubProgressMonitor subMonitor, Document document) {
Element webapp = document.getDocumentElement();
if (webapp != null) {
if (webapp.getTagName().equals(WEB_APP_ELEMENT_NAME) || webapp.getNodeName().endsWith(WEB_APP_ELEMENT_LOCAL_NAME)) {
// this convention only started with 2.4?
if (webapp.hasAttribute(WEB_APP_VERSION_NAME)) {
String versionValue = webapp.getAttribute(WEB_APP_VERSION_NAME);
versionValue = versionValue.trim();
if (versionValue.length() > 0) {
try {
version[0] = Float.valueOf(versionValue);
} catch (NumberFormatException e) {
// doesn't matter
}
}
}
if (version[0] == null) {
// try determining the version from the doctype reference
DocumentType doctype = document.getDoctype();
if (doctype != null) {
String systemId = doctype.getSystemId();
String publicId = doctype.getPublicId();
if ((systemId != null && systemId.endsWith("web-app_2_3.dtd")) || (publicId != null && publicId.indexOf("Web Application 2.3") > 0)) {
// $NON-NLS-1$ //$NON-NLS-2$
version[0] = new Float(2.3);
} else if ((systemId != null && systemId.endsWith("web-app_2_2.dtd")) || (publicId != null && publicId.indexOf("Web Application 2.2") > 0)) {
// $NON-NLS-1$ //$NON-NLS-2$
version[0] = new Float(2.2);
} else if ((systemId != null && systemId.endsWith("web-app_2_1.dtd")) || (publicId != null && publicId.indexOf("Web Application 2.1") > 0)) {
// $NON-NLS-1$ //$NON-NLS-2$
version[0] = new Float(2.1);
}
}
}
}
}
NodeList propertyGroupElements = document.getElementsByTagName(JSP_PROPERTY_GROUP);
int length = propertyGroupElements.getLength();
// $NON-NLS-1$
subMonitor.beginTask("Reading Property Groups", length);
for (int i = 0; i < length; i++) {
PropertyGroup group = PropertyGroup.createFrom(path, propertyGroupElements.item(i), i);
subMonitor.worked(1);
if (group != null) {
groupList.add(group);
}
}
// 325554 : only apply to URL patterns for Servlet mappings
NodeList urlPatternElements = document.getElementsByTagName(URL_PATTERN);
int urlPatternElementCount = urlPatternElements.getLength();
for (int i = 0; i < urlPatternElementCount; i++) {
Node urlPatternElement = urlPatternElements.item(i);
if (SERVLET_MAPPING.equals(urlPatternElement.getParentNode().getNodeName())) {
String urlPattern = getContainedText(urlPatternElement);
if (urlPattern != null && urlPattern.length() > 0) {
urlPatterns.add(new StringMatcher(urlPattern));
}
}
}
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class HTMLContentAssistProcessor method getXHTML.
/**
* Determine if this Document is an XHTML Document. Oprates solely off of
* the Document Type declaration
*/
protected boolean getXHTML(Node node) {
if (node == null)
return false;
Document doc = null;
if (node.getNodeType() != Node.DOCUMENT_NODE)
doc = node.getOwnerDocument();
else
doc = ((Document) node);
if (doc instanceof IDOMDocument)
return ((IDOMDocument) doc).isXMLType();
if (doc instanceof INodeNotifier) {
ModelQueryAdapter adapter = (ModelQueryAdapter) ((INodeNotifier) doc).getAdapterFor(ModelQueryAdapter.class);
CMDocument cmdoc = null;
if (adapter != null && adapter.getModelQuery() != null)
cmdoc = adapter.getModelQuery().getCorrespondingCMDocument(doc);
if (cmdoc != null) {
// model
if (cmdoc instanceof HTMLCMDocument)
return false;
if (cmdoc.supports(HTMLCMProperties.IS_XHTML))
return Boolean.TRUE.equals(cmdoc.getProperty(HTMLCMProperties.IS_XHTML));
}
}
// this should never be reached
DocumentType docType = doc.getDoctype();
// $NON-NLS-1$
return docType != null && docType.getPublicId() != null && docType.getPublicId().indexOf("-//W3C//DTD XHTML ") == 0;
}
Aggregations