Search in sources :

Example 16 with ModelQueryAdapter

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

the class TestModelsFromFiles method testClone.

private void testClone(IStructuredModel structuredModel) throws IOException {
    IDOMDocument document = ((IDOMModel) structuredModel).getDocument();
    INodeNotifier notifier = document;
    ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
    assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
    IStructuredModel newModel = structuredModel.newInstance();
    IDOMDocument newDocument = ((IDOMModel) newModel).getDocument();
    INodeNotifier newNotifier = newDocument;
    ModelQueryAdapter result = (ModelQueryAdapter) newNotifier.getAdapterFor(ModelQueryAdapter.class);
    assertNotNull("newInstance modelQueryAdapter should not be null", result);
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 17 with ModelQueryAdapter

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

the class TestTaglibCMTests method testTagFileHasHTMLContentModel.

public void testTagFileHasHTMLContentModel() 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("<b/>");
        ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
        CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
        assertNotNull("no CMElementDeclaration for 'b'", 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 18 with ModelQueryAdapter

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

the class TestTaglibCMTests method testTagFileReferencedInTLD.

public void testTagFileReferencedInTLD() throws IOException, CoreException {
    String DPROJECT_NAME = "DynamicWebProject";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
    if (!project.exists()) {
        // Create new project
        project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
        BundleResourceUtil.copyBundleZippedEntriesIntoWorkspace("/testfiles/jspErrorProject.zip", Path.ROOT);
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append("DynamicWebProject/WebContent/index.jsp"));
    assertTrue("test file " + jspFile.getFullPath() + " does not exist", jspFile.exists());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
        String DTAGNAME = "date:returndate";
        NodeList returnDates = model.getDocument().getElementsByTagName(DTAGNAME);
        assertNotNull("date:returndate was missing from document", returnDates.item(0));
        ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) returnDates.item(0)).getAdapterFor(ModelQueryAdapter.class);
        CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration((Element) returnDates.item(0));
        assertNotNull("no CMElementDeclaration for date:returndate", declaration);
        assertEquals("qualified name from element declaration was different", DTAGNAME, declaration.getNodeName());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IProject(org.eclipse.core.resources.IProject)

Example 19 with ModelQueryAdapter

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

the class TestTaglibCMTests method testLoadCustomTagsThroughXMLSyntax.

public void testLoadCustomTagsThroughXMLSyntax() throws IOException, CoreException {
    IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append(PROJECT_NAME).append("web stuff/testX.jsp"));
    assertTrue("test file " + jspFile.getFullPath() + " does not exist", jspFile.exists());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
        NodeList presents = model.getDocument().getElementsByTagName(TAG_NAME);
        assertNotNull(TAG_NAME + " was missing from document", presents.item(0));
        ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) presents.item(0)).getAdapterFor(ModelQueryAdapter.class);
        CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration((Element) presents.item(0));
        assertNotNull("no CMElementDeclaration for " + TAG_NAME, declaration);
        assertEquals("qualified name from element declaration was different", TAG_NAME, declaration.getNodeName());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList)

Example 20 with ModelQueryAdapter

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

the class LibraryTagsCompletionProposalComputer method forciblyGetTagLibAndJSPElements.

/**
 * <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
 * <p>This is bad because it does not use the ModelQuery framework, it
 * access the TLDCMDocumentManager directly</p>
 * <p>This is essentially a combination of the {@link TaglibModelQueryExtension} and
 * the {@link JSPModelQueryExtension} but it means any other extensions get left
 * out when creating content assist suggestion at the document root level</p>
 *
 * @param elementDecls
 * @param node
 * @param childIndex
 * @return
 */
private List forciblyGetTagLibAndJSPElements(List elementDecls, Node node, int childIndex) {
    if (node instanceof IDOMNode) {
        /*
			 * find the location of the intended insertion as it will give us
			 * the correct offset for checking position dependent CMDocuments
			 */
        int textInsertionOffset = 0;
        NodeList children = node.getChildNodes();
        if (children.getLength() >= childIndex && childIndex >= 0) {
            Node nodeAlreadyAtIndex = children.item(childIndex);
            if (nodeAlreadyAtIndex instanceof IDOMNode)
                textInsertionOffset = ((IDOMNode) nodeAlreadyAtIndex).getEndOffset();
        } else {
            textInsertionOffset = ((IDOMNode) node).getStartOffset();
        }
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((IDOMNode) node).getStructuredDocument());
        if (mgr != null) {
            List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset);
            if (moreCMDocuments != null) {
                for (int i = 0; i < moreCMDocuments.size(); i++) {
                    CMDocument doc = (CMDocument) moreCMDocuments.get(i);
                    CMNamedNodeMap elements = doc.getElements();
                    if (elements != null) {
                        for (int j = 0; j < elements.getLength(); j++) {
                            CMElementDeclaration ed = (CMElementDeclaration) elements.item(j);
                            elementDecls.add(ed);
                        }
                    }
                }
            }
        }
        // get position dependent CMDocuments and insert their tags as
        // proposals
        ModelQueryAdapter mqAdapter = null;
        if (node.getNodeType() == Node.DOCUMENT_NODE)
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) node).getAdapterFor(ModelQueryAdapter.class);
        else
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
        if (mqAdapter != null) {
            CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
            if (doc != null) {
                CMDocument jcmdoc = getDefaultJSPCMDocument((IDOMNode) node);
                CMNamedNodeMap jspelements = jcmdoc.getElements();
                /*
					 * For a built-in JSP action the content model is properly
					 * set up, so don't just blindly add the rest--unless this
					 * will be a direct child of the document
					 */
                if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
                    List rejectElements = new ArrayList();
                    // determine if the document is in XML form
                    Document domDoc = null;
                    if (node.getNodeType() == Node.DOCUMENT_NODE)
                        domDoc = (Document) node;
                    else
                        domDoc = node.getOwnerDocument();
                    // Show XML tag forms of JSP markers if jsp:root is
                    // the document element OR it's HTML but
                    // isn't really in the text.
                    // If the document isn't strictly XML, pull out the
                    // XML tag forms it is xml format
                    rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
                    rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
                    rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
                    rejectElements.add(JSP12Namespace.ElementName.TEXT);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
                    if (isXMLFormat(domDoc)) {
                        // jsp actions
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
                        rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
                        rejectElements.add(JSP12Namespace.ElementName.FORWARD);
                        rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.PARAM);
                        rejectElements.add(JSP12Namespace.ElementName.PARAMS);
                    }
                    // don't show jsp:root if a document element already
                    // exists
                    Element docElement = domDoc.getDocumentElement();
                    if (// $NON-NLS-1$
                    docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null))))
                        rejectElements.add(JSP12Namespace.ElementName.ROOT);
                    for (int j = 0; j < jspelements.getLength(); j++) {
                        CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
                        if (rejectElements.contains(ed.getNodeName()))
                            continue;
                        elementDecls.add(ed);
                    }
                }
            } else // No cm document (such as for the Document (a non-Element) node itself)
            {
                CMNamedNodeMap jspElements = getDefaultJSPCMDocument((IDOMNode) node).getElements();
                int length = jspElements.getLength();
                for (int i = 0; i < length; i++) {
                    elementDecls.add(jspElements.item(i));
                }
            }
        }
    }
    return elementDecls;
}
Also used : JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) NodeList(org.w3c.dom.NodeList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) 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) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

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