Search in sources :

Example 1 with IDOMDocumentType

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;
}
Also used : IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) DocumentType(org.w3c.dom.DocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Example 2 with IDOMDocumentType

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);
        }
    }
}
Also used : IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 3 with IDOMDocumentType

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();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 4 with IDOMDocumentType

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();
    }
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)4 IDOMDocumentType (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType)4 DocumentType (org.w3c.dom.DocumentType)2 Element (org.w3c.dom.Element)2 DocumentImpl (org.eclipse.wst.xml.core.internal.document.DocumentImpl)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 ProcessingInstruction (org.w3c.dom.ProcessingInstruction)1