Search in sources :

Example 21 with CMNodeList

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

the class BugFixesTest method testXSDTypeWhitespaceFacets.

// @SuppressWarnings("unchecked")
// public void testStackOverflow()
// {
// String namespaceURI = "http://www.w3.org/TR/voicexml20/vxml.xsd";
// String vxmlSchemaURI = locateFileUsingCatalog(namespaceURI);
// 
// // See bug 206138
// 
// // Two ways to test this.
// // First way. Call findTypesDerivedFrom from XSDImpl.
// 
// assertNotNull("unable to locate file for " + namespaceURI, vxmlSchemaURI);
// assertTrue("unable to locate file for " + namespaceURI, vxmlSchemaURI.length() > 0);
// XSDSchema xsdSchema = XSDImpl.buildXSDModel(vxmlSchemaURI);
// assertNotNull("failed to build model for " + vxmlSchemaURI,xsdSchema);
// boolean foundDesiredType = false;
// for (Iterator<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions().iterator(); types.hasNext(); )
// {
// XSDTypeDefinition type = types.next();
// if (type instanceof XSDComplexTypeDefinition)
// {
// XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) type;
// if ("basic.event.handler".equals(complexType.getName()))
// {
// foundDesiredType = true;
// List<XSDTypeDefinition> list = XSDImpl.findTypesDerivedFrom(complexType);
// int size = list.size();
// // assertTrue(size == 1);  // if we got something back, then great, there was no out of stack error
// assertTrue("no types found in XSD", size >= 0);
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular.   In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// break;
// }
// }
// }
// assertTrue("type \"basic.event.handler\" not found in XSD", foundDesiredType);  // if we didn't even find the complex type, then something terrible went wrong
// 
// // Second way to test via content model
// 
// CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
// assertNotNull("Assert factory is not null", factory);
// 
// CMDocument cmDocument = factory.createCMDocument(vxmlSchemaURI);
// assertNotNull("Assert CMDocument is not null", cmDocument);
// 
// CMNamedNodeMap elements = cmDocument.getElements();
// 
// boolean foundDesiredElement = false;
// for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); )
// {
// CMElementDeclaration element = i.next();
// if ("noinput".equals(element.getElementName()))
// {
// CMNamedNodeMap attributes = element.getAttributes();
// assertNotNull(attributes);
// // assertTrue(attributes.getLength() == 3);  // if we got something back, then great, there was no out of stack error
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular.   In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// assertTrue(attributes.getLength() >= 0);
// foundDesiredElement = true;
// break;
// }
// }
// assertTrue("element \"noinput\"r not found in XSD", foundDesiredElement);  // if we didn't even find the noinput element, then something terrible went wrong
// }
public void testXSDTypeWhitespaceFacets() {
    // Bug [194698] - Test that the correct whitespace facets are applied to the types
    String XSD_FILE_NAME = "XSDWhitespace.xsd";
    String fileURI = FILE_PROTOCOL + PLUGIN_ABSOLUTE_PATH + SAMPLES_DIR + XSD_FILE_NAME;
    CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
    assertNotNull("Assert factory is not null", factory);
    CMDocument cmDocument = factory.createCMDocument(fileURI);
    assertNotNull("Assert CMDocument is not null", cmDocument);
    CMElementDeclaration elemDecl = (CMElementDeclaration) cmDocument.getElements().item(0);
    assertEquals("test", elemDecl.getNodeName());
    assertTrue(elemDecl.getContent() instanceof XSDModelGroupAdapter);
    XSDModelGroupAdapter group = (XSDModelGroupAdapter) elemDecl.getContent();
    CMNodeList list = group.getChildNodes();
    XSDElementDeclarationAdapter adapter = null;
    String nodeName = null, expected = null;
    CMDataType type = null;
    // Iterate over the child nodes of the element, examining the whitespace facets */
    for (int i = 0; i < list.getLength(); i++) {
        adapter = (XSDElementDeclarationAdapter) list.item(i);
        nodeName = adapter.getNodeName();
        assertNotNull(nodeName);
        assertTrue(nodeName.contains("-"));
        type = adapter.getDataType();
        assertNotNull(type);
        expected = nodeName.substring(nodeName.indexOf('-') + 1);
        assertEquals(expected, type.getProperty(XSDImpl.PROPERTY_WHITESPACE_FACET));
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) XSDModelGroupAdapter(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDModelGroupAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.XSDElementDeclarationAdapter) CMDocumentFactoryXSD(org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 22 with CMNodeList

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

the class BugFixesTest method testGlobalAttr3Documentation.

private void testGlobalAttr3Documentation(CMNamedNodeMap attributes) {
    CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("globalAttr3");
    assertNotNull("Missing globalAttr1 attribute.");
    CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
    if (documentation.getLength() == 0) {
        fail("Unable to find documentation for globalAttr3");
    }
    assertEquals("Wrong number of documentation annotations.", 1, documentation.getLength());
    assertEquals("Incorrect annotation for globalAttr3:", "PASS! Documentation for resolved attribute ref when the attribute ref has an annotation but does not have documentation", ((DocumentationImpl) documentation.item(0)).getValue().trim());
}
Also used : CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) DocumentationImpl(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 23 with CMNodeList

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

the class ModelQueryTester method testDTDLoadFromSystemID_2.

/**
 * A short test to ensure that a DTD, the XHTML 1.0 Transitional one, 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_2() throws IOException {
    if (testShippedDTDLookup) {
        URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
        String diskLocation = null;
        diskLocation = FileLocator.resolve(installationPath).toExternalForm();
        assertTrue("failed to resolve plugin install path", diskLocation != null);
        setUpXML();
        String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "testfiles/XHTML/xhtml1-transitional.dtd\"" + "><html></html>";
        fModel.getStructuredDocument().set(content);
        CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
        documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
        // see defect 282429
        CMElementDeclaration htmlDecl = (CMElementDeclaration) fModelQuery.getCMNode((Node) fModel.getIndexedRegion(content.length() - 2));
        assertTrue("xhtml1-transitional.dtd not loaded", htmlDecl != null);
        // HTML's children are within a group
        CMContent contents = htmlDecl.getContent();
        assertTrue("content type is not a group", contents.getNodeType() == CMNode.GROUP);
        CMGroup group = (CMGroup) contents;
        int operator = group.getOperator();
        CMNodeList childList = group.getChildNodes();
        int max = contents.getMaxOccur();
        int min = contents.getMinOccur();
        // the group should be allowed once, with a sequence whose first
        // entry
        // is the declaration for HEAD
        assertTrue("occurrance of group", min == 1 && max == 1);
        assertTrue("relationship in group", operator == CMGroup.SEQUENCE);
        assertTrue("content descriptor type, position 0", contents.getNodeType() == CMNode.GROUP);
        assertTrue("child order (HEAD first)", childList.item(0).getNodeName().equals(HTML40Namespace.ElementName.HEAD.toLowerCase()));
        assertTrue("child order (BODY second)", childList.item(1).getNodeName().equals(HTML40Namespace.ElementName.BODY.toLowerCase()));
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) URL(java.net.URL) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Aggregations

CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)23 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)9 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)8 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)5 CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)5 DocumentationImpl (org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl)5 CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)4 Node (org.w3c.dom.Node)3 URL (java.net.URL)2 List (java.util.List)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)1 CMDocumentation (org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1