Search in sources :

Example 6 with ModelQueryAdapter

use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.

the class TestTaglibCMTests method testTagFileHasTagContentModel.

public void testTagFileHasTagContentModel() throws IOException, CoreException {
    String DPROJECT_NAME = getName();
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
    if (!project.exists()) {
        // Create new project
        project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IFile tagFile = project.getFile("test1.tag");
    tagFile.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, null);
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tagFile);
        model.getStructuredDocument().set("<" + JSP20Namespace.ElementName.DOBODY + "/>");
        ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
        CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
        assertNotNull("no CMElementDeclaration for '" + JSP20Namespace.ElementName.DOBODY + "'", declaration);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
    project.delete(true, null);
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IProject(org.eclipse.core.resources.IProject)

Example 7 with ModelQueryAdapter

use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.

the class TestModelClone method checkModelQuery.

private void checkModelQuery(IStructuredModel model, Class class1) {
    Document doc = ((IDOMModel) model).getDocument();
    ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) doc).getExistingAdapter(ModelQueryAdapter.class);
    assertNotNull("model did not have modelQueryAdapter", modelQueryAdapter);
    assertTrue("modelQueryAdapter is wrong class", class1.equals(JSPModelQueryImpl.class));
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) JSPModelQueryImpl(org.eclipse.jst.jsp.core.internal.modelquery.JSPModelQueryImpl) Document(org.w3c.dom.Document)

Example 8 with ModelQueryAdapter

use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.

the class TestModelClone method checkEmbeddedModelQuery.

private void checkEmbeddedModelQuery(IStructuredModel model, Class outerQueryAdapter, Class outerQueryClass, Class embeddedQueryClass) {
    Document doc = ((IDOMModel) model).getDocument();
    ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) doc).getExistingAdapter(ModelQueryAdapter.class);
    assertNotNull("model did not have modelQueryAdapter", modelQueryAdapter);
    Class expected = outerQueryAdapter;
    Class actual = modelQueryAdapter.getClass();
    assertEquals("document's model query is not as expected", expected, actual);
    ModelQuery modelQuery = modelQueryAdapter.getModelQuery();
    expected = outerQueryClass;
    actual = modelQuery.getClass();
    assertEquals("model query adapter's model query is not as expected", expected, actual);
    ModelQuery nodeQuery = getEmbeddedModelQuery(doc);
    assertNotNull("node does not have a modelQueryAdapter", nodeQuery);
    expected = embeddedQueryClass;
    actual = nodeQuery.getClass();
    assertEquals("documents model query is not as expected", expected, actual);
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) Document(org.w3c.dom.Document)

Example 9 with ModelQueryAdapter

use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.

the class TestModelAdapters method testJSPModel.

public void testJSPModel() throws IOException {
    IModelManager modelManager = getModelManager();
    IDOMModel structuredModel = (IDOMModel) modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    try {
        boolean test = structuredModel.getId().equals(IModelManager.UNMANAGED_MODEL);
        assertTrue(test);
        ModelQueryAdapter modelQueryAdapter = structuredModel.getAdapter(ModelQueryAdapter.class);
        assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
        IStructuredModel newModel = structuredModel.newInstance();
        // IDOMDocument newDocument = ((IDOMModel)
        // newModel).getDocument();
        // INodeNotifier notifier = newDocument;
        ModelQueryAdapter result = newModel.getAdapter(ModelQueryAdapter.class);
        assertNotNull("newInstance modelQueryAdapter should not be null", result);
    } finally {
        // even though model is unmanaged, release still required, since
        // adapter factories, etc., may be depending on it.
        structuredModel.releaseFromEdit();
        // if above complete's normally (with no exceptions)
        // consider passed.
        assertTrue(true);
    }
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 10 with ModelQueryAdapter

use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.

the class ElementNodeFormatter method formatEndTag.

protected void formatEndTag(IDOMNode node, IStructuredFormatContraints formatContraints) {
    if (!isEndTagMissing(node)) {
        // end tag exists
        IStructuredDocument structuredDocument = node.getModel().getStructuredDocument();
        String lineDelimiter = structuredDocument.getLineDelimiter();
        String nodeIndentation = getNodeIndent(node);
        IDOMNode lastChild = (IDOMNode) node.getLastChild();
        if (lastChild != null && lastChild.getNodeType() != Node.TEXT_NODE) {
            if (isEndTagMissing(lastChild)) {
                // find deepest child
                IDOMNode deepestChild = (IDOMNode) lastChild.getLastChild();
                while (deepestChild != null && deepestChild.getLastChild() != null && isEndTagMissing(deepestChild)) {
                    lastChild = deepestChild;
                    deepestChild = (IDOMNode) deepestChild.getLastChild();
                }
                if (deepestChild != null) {
                    if (deepestChild.getNodeType() == Node.TEXT_NODE) {
                        // Special indentation handling if lastChild's end
                        // tag is missing and deepestChild is a text node.
                        String nodeText = deepestChild.getNodeValue();
                        if (!nodeText.endsWith(lineDelimiter + nodeIndentation)) {
                            nodeText = StringUtils.appendIfNotEndWith(nodeText, lineDelimiter);
                            nodeText = StringUtils.appendIfNotEndWith(nodeText, nodeIndentation);
                        }
                        replaceNodeValue(deepestChild, nodeText);
                    } else
                        insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
                }
            } else
                // indent end tag
                insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
        } else if (lastChild == null && firstStructuredDocumentRegionContainsLineDelimiters(node)) {
            // BUG174243 do not indent end tag if node has empty content
            // (otherwise new text node would be introduced)
            ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
            CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
            if ((elementDeclaration == null) || (elementDeclaration.getContentType() != CMElementDeclaration.EMPTY)) {
                // indent end tag
                replace(structuredDocument, node.getFirstStructuredDocumentRegion().getEndOffset(), 0, lineDelimiter + nodeIndentation);
            }
        }
        // format end tag name
        IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getLastStructuredDocumentRegion();
        if (endTagStructuredDocumentRegion.getRegions().size() >= 3) {
            ITextRegion endTagNameRegion = endTagStructuredDocumentRegion.getRegions().get(1);
            removeRegionSpaces(node, endTagStructuredDocumentRegion, endTagNameRegion);
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

ModelQueryAdapter (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter)25 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)14 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)11 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)8 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 Document (org.w3c.dom.Document)6 IFile (org.eclipse.core.resources.IFile)5 Element (org.w3c.dom.Element)5 Node (org.w3c.dom.Node)5 NodeList (org.w3c.dom.NodeList)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)4 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)4 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)4 IProject (org.eclipse.core.resources.IProject)3 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3