Search in sources :

Example 21 with CMDataType

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

the class ContentBuilder method visitCMElementDeclaration.

public void visitCMElementDeclaration(CMElementDeclaration ed) {
    int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
    int min = Math.max(ed.getMinOccur(), forcedMin);
    alwaysVisit = false;
    if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
        visitedCMElementDeclarationList.add(ed);
        for (int i = 1; i <= min; i++) {
            createElementNodeStart(ed);
            // instead of calling super.visitCMElementDeclaration()
            // we duplicate the code with some minor modifications
            CMNamedNodeMap nodeMap = ed.getAttributes();
            int size = nodeMap.getLength();
            for (int j = 0; j < size; j++) {
                visitCMNode(nodeMap.item(j));
            }
            CMContent content = ed.getContent();
            if (content != null) {
                visitCMNode(content);
            }
            if (ed.getContentType() == CMElementDeclaration.PCDATA) {
                CMDataType dataType = ed.getDataType();
                if (dataType != null) {
                    visitCMDataType(dataType);
                }
            }
            // end duplication
            createElementNodeEnd(ed);
        }
        int size = visitedCMElementDeclarationList.size();
        visitedCMElementDeclarationList.remove(size - 1);
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 22 with CMDataType

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

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

the class BugFixesTest method testBase64BinaryDefaultValue.

/**
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322841
 */
public void testBase64BinaryDefaultValue() {
    Bundle bundle = Platform.getBundle(XSDCoreTestsPlugin.PLUGIN_ID);
    // $NON-NLS-1$
    URL url = bundle.getEntry("/testresources/samples/base64Binary/Test.xsd");
    CMDocument cmDocument = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull(cmDocument);
    CMNamedNodeMap elements = cmDocument.getElements();
    // $NON-NLS-1$
    CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) elements.getNamedItem("Test");
    assertNotNull(cmElementDeclaration);
    CMDataType dataType = cmElementDeclaration.getDataType();
    assertNotNull(dataType);
    String impliedValue = dataType.generateInstanceValue();
    // $NON-NLS-1$
    assertEquals("MA==", impliedValue);
}
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) Bundle(org.osgi.framework.Bundle) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) URL(java.net.URL)

Example 24 with CMDataType

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

the class ModelQueryTester method testBodyElement.

/**
 * Test the HTML BODY Element for the "bgcolor" attribute declaration
 */
public void testBodyElement() {
    setUpHTML();
    // set
    fModel.getStructuredDocument().set("<html><body bgcolor=\"#ffffff\"><form method=\"post\"></form></body></html>");
    // text
    // TEST getting a CMElementDeclaration
    // node at
    Element bodyElement = (Element) fModel.getIndexedRegion(7);
    // offset7--should
    // be
    // <body>
    CMElementDeclaration bodyDecl = fModelQuery.getCMElementDeclaration(bodyElement);
    int contentType = bodyDecl.getContentType();
    assertTrue("CMElementDeclaration CONTENT TYPE INCORRECT FOR BODY", (contentType == CMElementDeclaration.MIXED));
    // get permissible attrs
    CMNamedNodeMap map = bodyDecl.getAttributes();
    assertTrue("ATTRIBUTES FROM ELEMENT DECLARATION == NULL", (map != null));
    Vector allowed = new Vector();
    for (int i = 0; i < map.getLength(); i++) {
        CMAttributeDeclaration node = (CMAttributeDeclaration) map.item(i);
        String name = node.getNodeName();
        allowed.add(name);
        if (name.equalsIgnoreCase("bgcolor")) {
            assertTrue("GOT INCORRECT ATTRIBUTE NODE TYPE", (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION));
            CMDataType attrType = node.getAttrType();
            // System.out.println("attribute type > " + attrType);
            assertTrue("COULD NOT GET ATTRIBUTE TYPE", (attrType != null));
            assertTrue("COULDN'T GET IMPLIED VALUE KIND", (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_NONE));
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) Element(org.w3c.dom.Element) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Vector(java.util.Vector)

Example 25 with CMDataType

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

the class ModelQueryTester method getValidStrings.

/**
 * Return the valid values for an attribute with the given declaration on
 * the given element. Derived from XMLPropertySource
 */
private List getValidStrings(Element element, CMAttributeDeclaration attrDecl) {
    CMDataType valuesHelper = attrDecl.getAttrType();
    Vector values = new Vector();
    if (valuesHelper.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED && valuesHelper.getImpliedValue() != null) {
        // FIXED value
        values.add(valuesHelper.getImpliedValue());
    } else {
        // ENUMERATED values
        String[] valueStrings = null;
        // new way
        valueStrings = fModelQuery.getPossibleDataTypeValues(element, attrDecl);
        if (valueStrings == null)
            // older way
            valueStrings = attrDecl.getAttrType().getEnumeratedValues();
        if (valueStrings != null) {
            for (int i = 0; i < valueStrings.length; i++) {
                values.add(valueStrings[i]);
            }
        }
    }
    if (valuesHelper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE && valuesHelper.getImpliedValue() != null) {
        if (!values.contains(valuesHelper.getImpliedValue()))
            values.add(valuesHelper.getImpliedValue());
    }
    return values;
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) Vector(java.util.Vector)

Aggregations

CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)26 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)12 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)9 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)7 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)7 List (java.util.List)6 Element (org.w3c.dom.Element)6 ArrayList (java.util.ArrayList)5 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)5 Node (org.w3c.dom.Node)5 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)4 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)4 Iterator (java.util.Iterator)3 Vector (java.util.Vector)3 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)3 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)3 NodeList (org.w3c.dom.NodeList)3 Image (org.eclipse.swt.graphics.Image)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2