use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType in project webtools.sourceediting by eclipse.
the class EditDoctypeAction method createDoctype.
protected DocumentType createDoctype(EditDoctypeDialog dialog, Document document) {
DocumentType result = null;
if (document instanceof DocumentImpl) {
IDOMDocument documentImpl = (IDOMDocument) document;
IDOMDocumentType doctypeImpl = (IDOMDocumentType) documentImpl.createDoctype(dialog.getName());
doctypeImpl.setPublicId(dialog.getPublicId());
doctypeImpl.setSystemId(dialog.getSystemId());
result = doctypeImpl;
}
return result;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType in project webtools.sourceediting by eclipse.
the class EditDoctypeAction method updateDoctype.
protected void updateDoctype(EditDoctypeDialog dialog, DocumentType doctype) {
if (doctype instanceof IDOMDocumentType) {
IDOMDocumentType doctypeImpl = (IDOMDocumentType) doctype;
if (doctypeImpl.getName().equals(dialog.getName())) {
doctypeImpl.setPublicId(dialog.getPublicId());
doctypeImpl.setSystemId(dialog.getSystemId());
} else {
// we need to create a new one and remove the old
//
Document document = doctype.getOwnerDocument();
DocumentType newDoctype = createDoctype(dialog, document);
document.insertBefore(newDoctype, doctype);
document.removeChild(doctype);
// manager.reformat(newDoctype, false);
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType in project webtools.sourceediting by eclipse.
the class DocTypeTest method testModel.
public void testModel() {
IDOMModel model = createHTMLModel();
try {
IDOMDocument document = model.getDocument();
IDOMDocumentType docType = (IDOMDocumentType) document.createDoctype("HTML");
document.appendChild(docType);
Element html = document.createElement("HTML");
document.appendChild(html);
printSource(model);
printTree(model);
docType.setSystemId("sytem");
printSource(model);
printTree(model);
docType.setPublicId("public");
printSource(model);
printTree(model);
document.insertBefore(document.createTextNode(" "), docType);
printSource(model);
printTree(model);
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType in project webtools.sourceediting by eclipse.
the class HTMLConverter method setDeclaration.
/**
*/
public void setDeclaration(IDOMModel model, String declaration, String publicId) {
if (model == null)
return;
IDOMDocument document = model.getDocument();
if (document == null)
return;
try {
model.aboutToChangeModel();
ProcessingInstruction pi = null;
Node child = document.getFirstChild();
if (child != null && child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
String target = child.getNodeName();
if (target != null && target.equals("xml")) {
// $NON-NLS-1$
pi = (ProcessingInstruction) child;
child = child.getNextSibling();
}
}
IDOMDocumentType docType = (IDOMDocumentType) document.getDoctype();
if (declaration != null) {
if (pi != null) {
pi.setData(declaration);
} else {
// $NON-NLS-1$
pi = document.createProcessingInstruction("xml", declaration);
document.insertBefore(pi, child);
insertBreak(model, child);
}
}
if (publicId != null) {
HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(publicId);
String name = (entry != null ? entry.getName() : null);
if (name == null || name.length() == 0)
// default //$NON-NLS-1$
name = "HTML";
if (docType != null) {
if (!name.equals(docType.getName())) {
// replace
Node parent = docType.getParentNode();
child = docType;
docType = (IDOMDocumentType) document.createDoctype(name);
parent.insertBefore(docType, child);
parent.removeChild(child);
}
} else {
docType = (IDOMDocumentType) document.createDoctype(name);
document.insertBefore(docType, child);
insertBreak(model, child);
}
docType.setPublicId(publicId);
if (entry != null) {
String systemId = entry.getSystemId();
if (systemId != null)
docType.setSystemId(systemId);
String namespaceURI = entry.getNamespaceURI();
if (namespaceURI != null) {
Element element = document.getDocumentElement();
if (element != null) {
// $NON-NLS-1$
element.setAttribute("xmlns", namespaceURI);
}
}
}
}
} finally {
model.changedModel();
}
}
Aggregations