Search in sources :

Example 76 with DocumentType

use of org.w3c.dom.DocumentType in project webservices-axiom by apache.

the class TestWithParser1 method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().parse(TestWithParser1.class.getResource("test1.xml").toString());
    DocumentType doctype = document.getDoctype();
    assertEquals("root", doctype.getName());
    assertNull(doctype.getPublicId());
    assertNull(doctype.getSystemId());
    assertEquals("<!ELEMENT root (#PCDATA)>", doctype.getInternalSubset().trim());
}
Also used : DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 77 with DocumentType

use of org.w3c.dom.DocumentType in project webservices-axiom by apache.

the class TestWithParser2 method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().parse(TestWithParser2.class.getResource("test2.xml").toString());
    DocumentType doctype = document.getDoctype();
    assertEquals("root", doctype.getName());
    assertEquals("dummy", doctype.getPublicId());
    assertEquals("test.dtd", doctype.getSystemId());
    assertNull(doctype.getInternalSubset());
}
Also used : DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 78 with DocumentType

use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method getAvailableRootChildren.

// returns a list of CMElementDeclarations
protected List getAvailableRootChildren(Document document, int childIndex) {
    List list = null;
    // extract the valid 'root' node name from the DocumentType Node
    DocumentType docType = document.getDoctype();
    String rootName = null;
    if (docType != null) {
        rootName = docType.getNodeName();
    }
    if (rootName == null) {
        return new ArrayList(0);
    }
    for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) {
        // is it required to be an Element?
        if ((child.getNodeType() == Node.ELEMENT_NODE) && stringsEqual(child.getNodeName(), rootName)) {
            // count it as present
            if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) {
                continue;
            }
            if (Debug.displayInfo) {
                // $NON-NLS-1$
                System.out.println(rootName + " already present!");
            }
            setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[] { rootName })));
            return new ArrayList(0);
        }
    }
    list = new ArrayList(1);
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery != null) {
        CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
        if (cmdoc != null) {
            if (rootName != null) {
                CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
                if (rootDecl != null) {
                    list.add(rootDecl);
                } else {
                    // supply the given document name anyway, even if it
                    // is an error
                    list.add(new SimpleCMElementDeclaration(rootName));
                    if (Debug.displayInfo || Debug.displayWarnings) {
                        // $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
                        System.out.println("No definition found for " + rootName + " in " + docType.getPublicId() + "/" + docType.getSystemId());
                    }
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
                    // $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
                    if (location.length() > 0) {
                        setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for_in, (new Object[] { rootName, location })));
                    } else {
                        setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for, (new Object[] { rootName })));
                    }
                }
            }
        } else {
            if (Debug.displayInfo || Debug.displayWarnings) {
                // $NON-NLS-1$
                System.out.println("No content model found.");
            }
            // $NON-NLS-1$
            // $NON-NLS-1$
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
            // $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
            if (location.length() > 0) {
                setErrorMessage(NLS.bind(XMLUIMessages.No_content_model_for, (new Object[] { location })));
            } else {
                setErrorMessage(XMLUIMessages.No_content_model_found_UI_);
            }
        }
    }
    return list;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DocumentType(org.w3c.dom.DocumentType) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 79 with DocumentType

use of org.w3c.dom.DocumentType 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 80 with DocumentType

use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.

the class EditDoctypeAction method run.

public void run() {
    Shell shell = getDisplay().getActiveShell();
    if (validateEdit(model, shell)) {
        model.beginRecording(this, getUndoDescription());
        // Shell shell =
        // XMLCommonUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
        EditDoctypeDialog dialog = showEditDoctypeDialog(shell);
        if (dialog.getReturnCode() == Window.OK) {
            if (doctype != null) {
                updateDoctype(dialog, doctype);
            } else if (document != null) {
                DocumentType doctype = createDoctype(dialog, document);
                if (doctype != null) {
                    insertDoctype(doctype, document);
                }
            }
        }
        model.endRecording(this);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) DocumentType(org.w3c.dom.DocumentType) EditDoctypeDialog(org.eclipse.wst.xml.ui.internal.dialogs.EditDoctypeDialog)

Aggregations

DocumentType (org.w3c.dom.DocumentType)107 Document (org.w3c.dom.Document)68 DOMImplementation (org.w3c.dom.DOMImplementation)34 Node (org.w3c.dom.Node)21 DOMException (org.w3c.dom.DOMException)19 Element (org.w3c.dom.Element)16 NamedNodeMap (org.w3c.dom.NamedNodeMap)14 NodeList (org.w3c.dom.NodeList)12 ArrayList (java.util.ArrayList)10 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)8 Entity (org.w3c.dom.Entity)8 IOException (java.io.IOException)7 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Transformer (javax.xml.transform.Transformer)4 TransformerFactory (javax.xml.transform.TransformerFactory)4 DOMSource (javax.xml.transform.dom.DOMSource)4 StreamResult (javax.xml.transform.stream.StreamResult)4 Attr (org.w3c.dom.Attr)4