Search in sources :

Example 6 with CMNodeList

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

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

the class MarkupTagInfoProvider method printDocumentation.

/**
 * Adds the tag documentation property of the CMNode to the string buffer,
 * sb
 */
protected void printDocumentation(StringBuffer sb, CMNode node) {
    // $NON-NLS-1$
    CMNodeList nodeList = (CMNodeList) node.getProperty("documentation");
    if ((nodeList != null) && (nodeList.getLength() > 0)) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            CMDocumentation documentation = (CMDocumentation) nodeList.item(i);
            String doc = documentation.getValue();
            if (doc != null) {
                sb.append(PARAGRAPH_START + doc.trim() + PARAGRAPH_END);
            }
        }
        sb.append(NEW_LINE);
    }
}
Also used : CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) CMDocumentation(org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation)

Example 8 with CMNodeList

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

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

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

the class CMDescriptionBuilder method visitCMGroup.

public void visitCMGroup(CMGroup group) {
    int op = group.getOperator();
    if (op == CMGroup.ALL) {
        // $NON-NLS-1$
        sb.append("all");
    }
    // $NON-NLS-1$
    sb.append("(");
    // $NON-NLS-1$
    String separator = ", ";
    if (op == CMGroup.CHOICE) {
        // $NON-NLS-1$
        separator = " | ";
    }
    CMNodeList nodeList = group.getChildNodes();
    int size = nodeList.getLength();
    for (int i = 0; i < size; i++) {
        visitCMNode(nodeList.item(i));
        if (i < size - 1) {
            sb.append(separator);
        }
    }
    // $NON-NLS-1$
    sb.append(")");
    addOccurenceSymbol(group);
}
Also used : CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Aggregations

CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)23 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)9 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)8 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)5 CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)5 DocumentationImpl (org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl)5 CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)4 Node (org.w3c.dom.Node)3 URL (java.net.URL)2 List (java.util.List)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)1 CMDocumentation (org.eclipse.wst.xml.core.internal.contentmodel.CMDocumentation)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1