Search in sources :

Example 86 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class TestAttributesOrder method ensureDocumentHasGrammar.

/**
 * Reusable test to make sure the XML model for the given file has a grammar.
 *
 * @param file
 *          the file containing the XML document.
 */
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
        assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 87 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class TestCyclicGroupReferences method testCyclicGroupReferences.

/**
 * Test CMVisitor for cyclic group references.
 */
public void testCyclicGroupReferences() {
    // $NON-NLS-1$
    IFile file = getFile("Test.xml");
    CMVisitor cmVisitor = new CMVisitor();
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForRead(file);
        // $NON-NLS-1$
        assertNotNull("failure loading model", model);
        IDOMModel domModel = (IDOMModel) model;
        IDOMDocument document = domModel.getDocument();
        // $NON-NLS-1$
        assertNotNull("failure getting document", document);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
        // $NON-NLS-1$
        assertNotNull("ModelQuery is missing", modelQuery);
        IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
        // $NON-NLS-1$
        assertNotNull("missing document element", documentElement);
        CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
        assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        cmElementDeclaration);
        cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
    } catch (Throwable th) {
        fail("Test failed :" + th.getClass().getName());
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) CMVisitor(org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 88 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method isXMLNode.

/**
 * Similar to the call in HTMLContentAssistProcessor. Pass in a node, it
 * tells you if the document is XML type.
 *
 * @param node
 */
private boolean isXMLNode(Node node) {
    if (node == null) {
        return false;
    }
    Document doc = null;
    doc = (node.getNodeType() != Node.DOCUMENT_NODE) ? node.getOwnerDocument() : ((Document) node);
    return (doc instanceof IDOMDocument) && ((IDOMDocument) doc).isXMLType();
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 89 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class XSDModelAdapter method clear.

public void clear() {
    if (schema != null) {
        Document doc = schema.getDocument();
        if (doc instanceof IDOMDocument) {
            IDOMDocument domDocument = (IDOMDocument) doc;
            domDocument.getModel().removeModelStateListener(getModelReconcileAdapter());
            domDocument.removeAdapter(getModelReconcileAdapter());
            domDocument.removeAdapter(this);
        }
        schema = null;
    }
    resourceSet = null;
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 90 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class NamespaceSelectionAdapter method widgetSelected.

@Override
public void widgetSelected(SelectionEvent e) {
    IEditorPart activeEditor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = createNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9