Search in sources :

Example 6 with CMGroup

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

the class CMValidator method validate.

/**
 */
public void validate(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, Result result) {
    int contentType = ed.getContentType();
    if (contentType == CMElementDeclaration.MIXED || contentType == CMElementDeclaration.ELEMENT) {
        ElementList elementList = createElementList(contentType, elementContent, comparator, result);
        if (result.isValid == true) {
            boolean isGraphValidationNeeded = !(elementList == null && contentType == CMElementDeclaration.MIXED);
            // explicitly handle 'All' groups
            // 
            CMContent content = ed.getContent();
            if (content != null && content.getNodeType() == CMNode.GROUP) {
                CMGroup group = (CMGroup) content;
                if (group.getOperator() == CMGroup.ALL) {
                    isGraphValidationNeeded = false;
                    validatAllGroupContent(elementContent, comparator, group, result);
                }
            }
            if (isGraphValidationNeeded) {
                // validate the elementList using a graph
                // 
                result.isValid = false;
                GraphNode node = lookupOrCreateGraph(ed);
                validateElementList(elementList, node, comparator, result, false);
            }
        }
    } else if (contentType == CMElementDeclaration.PCDATA) {
        int size = elementContent.size();
        for (int i = 0; i < size; i++) {
            Object o = elementContent.get(i);
            if (comparator.isElement(o)) {
                result.isValid = false;
                result.errorIndex = i;
                // $NON-NLS-1$
                result.errorMessage = "Element may only include PCDATA content";
                break;
            }
        }
    } else if (contentType == CMElementDeclaration.EMPTY) {
        int size = elementContent.size();
        for (int i = 0; i < size; i++) {
            Object o = elementContent.get(i);
            if (!comparator.isIgnorable(o)) {
                result.isValid = false;
                result.errorIndex = i;
                // $NON-NLS-1$
                result.errorMessage = "Element may not contain PCDATA or Element content";
                break;
            }
        }
    }
// else if (contentType == CMElementDeclaration.ANY)
// {
// assume elementContent will always be valid for this content type
// }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 7 with CMGroup

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

CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)7 CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)5 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)5 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)5 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)4 Node (org.w3c.dom.Node)3 Element (org.w3c.dom.Element)2 URL (java.net.URL)1 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 CMAnyElement (org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement)1 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1 CMDocumentManager (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1