Search in sources :

Example 51 with CMNode

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

the class CMValidator method validatAllGroupContent.

private void validatAllGroupContent(List elementContent, ElementContentComparator comparator, CMGroup allGroup, Result result) {
    boolean isValid = true;
    boolean isPartiallyValid = true;
    HashMap map = new HashMap();
    CMNodeList list = allGroup.getChildNodes();
    for (int j = list.getLength() - 1; j >= 0; j--) {
        CMNode node = list.item(j);
        if (map.get(node) == null) {
            map.put(node, new ItemCount());
        }
    }
    int validitionCount = 0;
    for (Iterator i = elementContent.iterator(); i.hasNext(); validitionCount++) {
        Object o = i.next();
        if (comparator.isElement(o)) {
            // test to see if the element is listed in the all group
            // 
            CMNode matchingCMNode = null;
            for (int j = list.getLength() - 1; j >= 0; j--) {
                CMNode node = list.item(j);
                if (comparator.matches(o, node)) {
                    matchingCMNode = node;
                    break;
                }
            }
            if (matchingCMNode == null) {
                isPartiallyValid = false;
                isValid = false;
                break;
            } else {
                // test to see that the element occurs only once
                // 
                ItemCount itemCount = (ItemCount) map.get(matchingCMNode);
                if (itemCount != null) {
                    if (itemCount.count > 0) {
                        // we don't want to allow too many elements!
                        // we consider 'not enough' to be partially valid... but not 'too many'
                        isPartiallyValid = false;
                        break;
                    } else {
                        itemCount.count++;
                    }
                }
            }
        }
    }
    if (isValid) {
        for (int j = list.getLength() - 1; j >= 0; j--) {
            CMNode node = list.item(j);
            if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                CMContent content = (CMContent) node;
                ItemCount itemCount = (ItemCount) map.get(node);
                // System.out.print("content " + content.getNodeName() + " " + content.getMinOccur());
                if (itemCount.count < content.getMinOccur()) {
                    isValid = false;
                    break;
                }
            }
        }
    }
    if (result instanceof ElementPathRecordingResult && isPartiallyValid) {
        ((ElementPathRecordingResult) result).setPartialValidationCount(validitionCount);
    }
    result.isValid = isValid;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) 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)

Example 52 with CMNode

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

the class CMValidator method getOriginArray.

public void getOriginArray(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, ElementPathRecordingResult result) {
    CMNode[] cmNodeArray = null;
    validate(ed, elementContent, comparator, result);
    if (result.isValid) {
        CMDataType dataType = ed.getDataType();
        int size = elementContent.size();
        cmNodeArray = new CMNode[size];
        Vector originList = result.getElementOriginList();
        int originListSize = originList.size();
        int originListIndex = 0;
        for (int i = 0; i < size; i++) {
            Object o = elementContent.get(i);
            if (comparator.isElement(o)) {
                if (originListIndex < originListSize) {
                    cmNodeArray[i] = (CMNode) originList.get(originListIndex);
                    originListIndex++;
                }
            } else if (comparator.isPCData(o)) {
                cmNodeArray[i] = dataType;
            }
        // else the CMNode at this index is null
        }
        result.setOriginArray(cmNodeArray);
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Example 53 with CMNode

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

the class CMNamedNodeMapImpl method item.

/**
 * item method
 * @return CMNode
 * @param index int
 */
public CMNode item(int index) {
    CMNode result = null;
    int size = table.size();
    if (index < size) {
        Enumeration values = table.elements();
        for (int i = 0; i <= index; i++) {
            result = (CMNode) values.nextElement();
        }
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Example 54 with CMNode

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

the class ModelQueryActionHelper method getReplaceActions.

public void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList) {
    int[] range = getRange(parent, selectedChildren);
    if (range != null) {
        if (isContiguous(parent, range, selectedChildren)) {
            List tempList = new Vector();
            getReplaceActions(parent, ed, includeOptions, validityChecking, tempList);
            if ((includeOptions & ModelQuery.INCLUDE_ENCLOSING_REPLACE_ACTIONS) != 0) {
                removeActionsNotContainingRange(tempList, range[0], range[1]);
            } else {
                removeActionsNotMatchingRange(tempList, range[0], range[1]);
            }
            actionList.addAll(tempList);
        }
    }
    if (selectedChildren.size() == 1) {
        Node node = (Node) selectedChildren.get(0);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) node;
            CMNode childEd = modelQuery.getCMElementDeclaration(childElement);
            if (childEd != null) {
                CMNode childOrigin = modelQuery.getOrigin(childElement);
                CMNodeList cmNodeList = childOrigin != null ? // $NON-NLS-1$
                (CMNodeList) childOrigin.getProperty("SubstitutionGroup") : // $NON-NLS-1$
                (CMNodeList) childEd.getProperty("SubstitutionGroup");
                if (cmNodeList != null && cmNodeList.getLength() > 1) {
                    int replaceIndex = getIndex(parent, childElement);
                    String childEdName = childEd.getNodeName();
                    for (int i = 0; i < cmNodeList.getLength(); i++) {
                        CMNode substitution = cmNodeList.item(i);
                        if (// $NON-NLS-1$
                        !substitution.getNodeName().equals(childEdName) && !Boolean.TRUE.equals(substitution.getProperty("Abstract"))) {
                            Action action = new Action(ModelQueryAction.REPLACE, parent, cmNodeList.item(i), replaceIndex, replaceIndex);
                            actionList.add(action);
                        }
                    }
                }
            }
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) List(java.util.List) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 55 with CMNode

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

Aggregations

CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)133 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)37 List (java.util.List)36 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)35 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)23 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)20 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)17 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)17 Element (org.w3c.dom.Element)16 NodeList (org.w3c.dom.NodeList)15 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)14 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)13 Node (org.w3c.dom.Node)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)9 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)9 Image (org.eclipse.swt.graphics.Image)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8