Search in sources :

Example 46 with CMNode

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

the class ModelQueryTester method testDTDLoadFromSystemID_1.

/**
 * A short test to ensure that a DTD can be loaded from a system
 * reference.
 *
 * Note: May require a functioning network connection for the references
 * to be resolved properly.
 *
 * @throws IOException
 */
public void testDTDLoadFromSystemID_1() throws IOException {
    if (testShippedDTDLookup) {
        setUpXML();
        URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
        String diskLocation = null;
        diskLocation = FileLocator.resolve(installationPath).toExternalForm();
        assertTrue("failed to resolve plugin install path", diskLocation != null);
        String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "TestFiles/DTDs/wapDTDs/WAP-2-0/wml20.dtd\"" + "><html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:wml=\"http://www.wapforum.org/2001/wml\"></html>";
        fModel.getStructuredDocument().set(content);
        CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
        Node domNode = (Node) fModel.getIndexedRegion(content.length() - 2);
        CMNode node = fModelQuery.getCMNode(domNode);
        assertTrue("wml20.dtd failed to load", node != null && node.getNodeName().equalsIgnoreCase("html"));
    }
}
Also used : CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) URL(java.net.URL)

Example 47 with CMNode

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode 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)

Example 48 with CMNode

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

the class TestFixedCMDocuments method verifyElementDeclarationHasName.

private void verifyElementDeclarationHasName(CMNode item) {
    assertTrue(item.getNodeType() == CMNode.ELEMENT_DECLARATION);
    assertNotNull("no name on an element declaration", item.getNodeName());
    CMNamedNodeMap attrs = ((CMElementDeclaration) item).getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        CMNode attr = attrs.item(i);
        verifyAttributeDeclaration(((CMElementDeclaration) item), attr);
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 49 with CMNode

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

the class TestFixedCMDocuments method checkDocument.

private void checkDocument(Object documentKey) {
    CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey.toString());
    assertNotNull("missing doc:" + documentKey.toString(), document);
    CMNamedNodeMap elements = document.getElements();
    for (int i = 0; i < elements.getLength(); i++) {
        CMNode item = elements.item(i);
        verifyElementDeclarationHasName(item);
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 50 with CMNode

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

the class TestFixedCMDocuments method checkAttrNames.

/**
 * @param cm_doc_type
 * @param elementName
 * @param attrNameImport
 */
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
    CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    for (int i = 0; i < attrNames.length; i++) {
        assertNotNull("missing attribute declaration:" + attrNames[i], attributes.getNamedItem(attrNames[i]));
    }
    assertEquals("Attributes defined in content model that are not expected by the test", attributes.getLength(), attrNames.length);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)133 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)37 List (java.util.List)36 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)35 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)23 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)20 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)17 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)17 Element (org.w3c.dom.Element)16 NodeList (org.w3c.dom.NodeList)15 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)14 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)13 Node (org.w3c.dom.Node)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)9 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)9 Image (org.eclipse.swt.graphics.Image)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8