Search in sources :

Example 31 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class TestTaglibCMTests method testLoadCustomTagsThroughJSPSyntax.

public void testLoadCustomTagsThroughJSPSyntax() throws IOException, CoreException {
    IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append(PROJECT_NAME).append("web stuff/test1.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 CMElementDelcaration 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 32 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class TestTaglibCMTests method testTagRuntimeExpressionValues.

public void testTagRuntimeExpressionValues() throws Exception {
    final String testName = "testLoadTagFiles";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    if (!project.exists()) {
        project = BundleResourceUtil.createSimpleProject(testName, null, null);
        BundleResourceUtil.copyBundleEntriesIntoWorkspace(TESTFILES_PATHSTRING + testName, "/" + testName);
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    CMDocumentFactoryTLD factory = new CMDocumentFactoryTLD();
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/" + testName + "/"));
    assertEquals("There should only be one taglib record", 1, records.length);
    CMDocument document = factory.createCMDocument(records[0]);
    CMNamedNodeMap elements = document.getElements();
    assertNotNull("No elements for the CM Document", elements);
    CMNode node = elements.getNamedItem("test");
    assertTrue("Node must be a CMElementDeclarationImpl", node instanceof CMElementDeclarationImpl);
    CMNamedNodeMap attributes = ((CMElementDeclaration) node).getAttributes();
    assertNotNull("No attributes", attributes);
    node = attributes.getNamedItem("myAttr");
    assertTrue("Node must be a CMAttributeDeclarationImpl", node instanceof CMAttributeDeclarationImpl);
    assertEquals("Default rtexprvalue for tags should be true", JSP11Namespace.ATTR_VALUE_TRUE, ((CMAttributeDeclarationImpl) node).getRtexprvalue());
    node = attributes.getNamedItem("noRuntimeAttr");
    assertTrue("Node must be a CMAttributeDeclarationImpl", node instanceof CMAttributeDeclarationImpl);
    assertEquals("rtexprvalue for should be false since explicitly set", JSP11Namespace.ATTR_VALUE_FALSE, ((CMAttributeDeclarationImpl) node).getRtexprvalue());
}
Also used : Path(org.eclipse.core.runtime.Path) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMAttributeDeclarationImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMAttributeDeclarationImpl) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) CMElementDeclarationImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMElementDeclarationImpl) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMDocumentFactoryTLD(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentFactoryTLD) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) IProject(org.eclipse.core.resources.IProject)

Example 33 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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 34 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class ElementNodeCleanupHandler method getRequiredAttrs.

protected List getRequiredAttrs(Node node) {
    List result = new ArrayList();
    ModelQuery modelQuery = getModelQuery(node);
    if (modelQuery != null) {
        CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
        if (elementDecl != null) {
            CMNamedNodeMap attrMap = elementDecl.getAttributes();
            Iterator it = attrMap.iterator();
            CMAttributeDeclaration attr = null;
            while (it.hasNext()) {
                attr = (CMAttributeDeclaration) it.next();
                if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
                    result.add(attr);
                }
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 35 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class TestIndex method testUtilityProjectSupport.

public void testUtilityProjectSupport() throws Exception {
    // Create project 1
    IProject project = BundleResourceUtil.createSimpleProject("test-jar", null, null);
    assertTrue(project.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-jar", "/test-jar");
    // Create project 2
    IProject project2 = BundleResourceUtil.createSimpleProject("test-war", null, null);
    assertTrue(project2.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-war", "/test-war");
    IFile testFile = project2.getFile(new Path("src/main/webapp/test.jsp"));
    assertTrue("missing test JSP file!", testFile.isAccessible());
    IDOMModel jspModel = null;
    try {
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(testFile);
        NodeList tests = jspModel.getDocument().getElementsByTagName("test:test");
        assertTrue("test:test element not found", tests.getLength() > 0);
        CMElementDeclaration elementDecl = ModelQueryUtil.getModelQuery(jspModel).getCMElementDeclaration(((Element) tests.item(0)));
        assertNotNull("No element declaration was found for test:test at runtime", elementDecl);
        assertTrue("element declaration was not the expected kind", elementDecl instanceof CMNodeWrapper);
        CMNode originNode = ((CMNodeWrapper) elementDecl).getOriginNode();
        assertTrue("element declaration was not from a tag library", originNode instanceof TLDElementDeclaration);
        assertEquals("element declaration was not from expected tag library", "http://foo.com/testtags", ((TLDDocument) ((TLDElementDeclaration) originNode).getOwnerDocument()).getUri());
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IProject(org.eclipse.core.resources.IProject)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15