Search in sources :

Example 61 with CMDocument

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

the class SimpleAssociationProvider method getCMElementDeclaration.

public CMElementDeclaration getCMElementDeclaration(Element element) {
    CMElementDeclaration result = null;
    CMDocument cmDocument = getCorrespondingCMDocument(element);
    if (cmDocument != null) {
        result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName());
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Example 62 with CMDocument

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

the class DOMContentBuilderImpl method testPopulateDocumentFromGrammarFile.

public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) {
    try {
        CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
        CMNamedNodeMap elementMap = cmDocument.getElements();
        CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(rootElementName);
        DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document);
        contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack;
        contentBuilder.createDefaultRootContent(cmDocument, element);
        System.out.println();
        // $NON-NLS-1$
        System.out.println("-----------------------------");
        DOMWriter writer = new DOMWriter();
        if (hack) {
            writer.print(document, grammarFileName);
        } else {
            writer.print(document);
        }
        // $NON-NLS-1$
        System.out.println("-----------------------------");
    } catch (Exception e) {
        // $NON-NLS-1$
        System.out.println("Error: " + e);
        e.printStackTrace();
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 63 with CMDocument

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

the class BugFixesTest method testEnumerationsInSimpleTypeHierarchy.

public void testEnumerationsInSimpleTypeHierarchy() {
    // See bug 424276
    Bundle bundle = Platform.getBundle(XSDCoreTestsPlugin.PLUGIN_ID);
    // $NON-NLS-1$
    URL url = bundle.getEntry("/testresources/samples/bugzilla424276.xsd");
    CMDocument cmDocument = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull(cmDocument);
    XSDSchema xsdSchema = XSDImpl.buildXSDModel(url.toExternalForm());
    // $NON-NLS-1$
    assertNotNull("failed to build model for " + url.toExternalForm());
    // $NON-NLS-1$
    assertTrue("Number of types in the test schema is 8", xsdSchema.getTypeDefinitions().size() == 8);
    for (Iterator<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions().iterator(); types.hasNext(); ) {
        XSDTypeDefinition type = types.next();
        if (type instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
            // System.out.println(simpleType.getName());
            if ("A".equals(simpleType.getName())) {
                String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
                assertEquals(1, enumeratedValuesForType.length);
                assertEquals(enumeratedValuesForType[0], "01");
            }
            if ("B0".equals(simpleType.getName())) {
                String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
                assertEquals(1, enumeratedValuesForType.length);
                assertEquals(enumeratedValuesForType[0], "01");
            }
            if ("C0".equals(simpleType.getName())) {
                String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
                assertEquals(2, enumeratedValuesForType.length);
                assertEquals(enumeratedValuesForType[0], "01");
                assertEquals(enumeratedValuesForType[1], "02");
            }
            if ("D0".equals(simpleType.getName())) {
                String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
                assertEquals(4, enumeratedValuesForType.length);
                assertEquals(enumeratedValuesForType[0], "01");
                assertEquals(enumeratedValuesForType[1], "02");
                assertEquals(enumeratedValuesForType[2], "03");
                assertEquals(enumeratedValuesForType[3], "04");
            }
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Bundle(org.osgi.framework.Bundle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) URL(java.net.URL) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 64 with CMDocument

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

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

the class BugFixesTest method testGlobalAtrributeDocumentation.

public void testGlobalAtrributeDocumentation() {
    // See bug 157254
    Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
    URL url = bundle.getEntry("/testresources/samples/documentation/TestAttributeRefs.xsd");
    CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull("Content model loaded Null", document);
    CMNamedNodeMap elements = document.getElements();
    CMElementDeclaration node = (CMElementDeclaration) elements.getNamedItem("object");
    assertNotNull("Missing object element", node);
    CMNamedNodeMap attributes = node.getAttributes();
    testGlobalAttr1Documentation(attributes);
    testGlobalAttr2Documentation(attributes);
    testGlobalAttr3Documentation(attributes);
    testGlobalAttr4Documentation(attributes);
    testLocalAttrDocumentation(attributes);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Bundle(org.osgi.framework.Bundle) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) URL(java.net.URL)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5