Search in sources :

Example 1 with CMGroup

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

the class CMGroupWrapperImpl method getChildNodes.

/**
 * getChildNodes method
 * @return CMNodeList
 *
 * Returns child CMNodeList, which includes ElementDefinition or CMElement.
 */
public CMNodeList getChildNodes() {
    if (fChildNodes == null) {
        CMNodeListImpl childNodes = new CMNodeListImpl();
        CMNodeList children = fGroup.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            CMNode child = children.item(i);
            if (child instanceof CMGroup)
                childNodes.appendItem(new CMGroupWrapperImpl(fPrefix, (CMGroup) child));
            else if (child instanceof CMElementDeclaration)
                childNodes.appendItem(new CMElementDeclarationWrapperImpl(fPrefix, (CMElementDeclaration) child));
            else
                // error?
                childNodes.appendItem(new CMNodeWrapperImpl(fPrefix, child));
        }
        fChildNodes = childNodes;
    }
    return fChildNodes;
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 2 with CMGroup

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

the class ModelQueryTester method testHtmlChildren.

/**
 * Test the HTML HTML Element for its declared children
 */
public void testHtmlChildren() {
    setUpHTML();
    // set text
    fModel.getStructuredDocument().set("<html></html>");
    Element htmlElement = fModel.getDocument().getDocumentElement();
    CMElementDeclaration htmlDecl = fModelQuery.getCMElementDeclaration(htmlElement);
    // 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().equalsIgnoreCase(HTML40Namespace.ElementName.HEAD));
    assertTrue("content descriptor type, position 1", childList.item(1).getNodeType() == CMNode.GROUP);
    // The second child should be a group as well, containing BODY and
    // FRAMESET with an
    // operator of CMGroup.CHOICE
    assertTrue("content descriptor type, position 1 - relationship of group", ((CMGroup) childList.item(1)).getOperator() == CMGroup.CHOICE);
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Element(org.w3c.dom.Element) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 3 with CMGroup

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

the class ModelQueryActionHelper method isSimpleChoiceGroupContentModel.

protected boolean isSimpleChoiceGroupContentModel(CMElementDeclaration ed) {
    boolean result = false;
    CMNode cmNode = ed.getContent();
    if (cmNode != null && cmNode.getNodeType() == CMNode.GROUP) {
        CMGroup cmGroup = (CMGroup) cmNode;
        if (cmGroup.getOperator() == CMGroup.CHOICE && cmGroup.getMaxOccur() == -1) {
            result = true;
            CMNodeList list = cmGroup.getChildNodes();
            for (int i = list.getLength() - 1; i >= 0; i--) {
                if (list.item(i).getNodeType() != CMNode.ELEMENT_DECLARATION) {
                    result = false;
                    break;
                }
            }
        }
    }
    return result;
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 4 with CMGroup

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

the class DOMContentBuilderImpl method visitCMElementDeclaration.

public void visitCMElementDeclaration(CMElementDeclaration ed) {
    int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
    int min = Math.max(ed.getMinOccur(), forcedMin);
    // a group.
    if (!cmGroupStack.isEmpty()) {
        CMGroup group = (CMGroup) cmGroupStack.peek();
        int gmin = group.getMinOccur();
        if (gmin == 0)
            if (buildOptionalElements(buildPolicy)) {
            /* do nothing: min = min */
            } else {
                // min = 0
                min = min * gmin;
            }
        else {
            min = min * gmin;
        }
    }
    int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements());
    if (max < min)
        max = min;
    alwaysVisit = false;
    // involved.
    if (// leave
    buildFirstSubstitution(buildPolicy) || isAbstract(ed)) // this
    // for
    // backward
    // compatibility
    // for now
    {
        // Note - To change so that if ed is optional, we do not
        // generate anything here.
        ed = getSubstitution(ed);
    // Note - the returned ed may be an abstract element in
    // which case the xml will be invalid.
    }
    if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
        visitedCMElementDeclarationList.add(ed);
        for (int i = 1; i <= max; i++) {
            // create an Element for each
            Element element = null;
            if (rootElement != null) {
                element = rootElement;
                rootElement = null;
            } else {
                element = createElement(ed, computeName(ed, currentParent), currentParent);
            }
            // visit the children of the GrammarElement
            Node oldParent = currentParent;
            currentParent = element;
            handlePushParent(element, ed);
            namespaceTable.addElement(element);
            boolean oldAttachNodesToParent = attachNodesToParent;
            attachNodesToParent = true;
            // 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
            attachNodesToParent = oldAttachNodesToParent;
            handlePopParent(element, ed);
            currentParent = oldParent;
            linkNode(element);
        }
        int size = visitedCMElementDeclarationList.size();
        visitedCMElementDeclarationList.remove(size - 1);
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 5 with CMGroup

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

the class AttributeContextInformationProvider method getInfoForText.

/**
 * @param node
 */
IContextInformation[] getInfoForText(IDOMNode node) {
    Node parent = node.getParentNode();
    String contextString = node.getNodeName();
    // $NON-NLS-1$
    StringBuffer info = new StringBuffer(" ");
    if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
        CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent);
        CMContent content = decl.getContent();
        if (content instanceof CMGroup) {
            CMGroup cmGroup = (CMGroup) content;
            CMNodeList children = cmGroup.getChildNodes();
            CMNode cmNode = null;
            for (int i = 0; i < children.getLength(); i++) {
                cmNode = children.item(i);
                contextString = cmNode.getNodeName();
                if (contextString != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.append("<" + cmNode.getNodeName() + ">");
                    if (i < children.getLength() - 1) {
                        // $NON-NLS-1$
                        info.append(" ");
                    }
                }
            }
        }
    }
    if (!info.toString().trim().equals("")) {
        return new IContextInformation[] { new ContextInformation(contextString, info.toString()) };
    } else {
        return EMPTY_CONTEXT_INFO;
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) 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