Search in sources :

Example 6 with CMContent

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

the class CMUtility method isRepeatable.

public static boolean isRepeatable(CMNode child) {
    boolean result = false;
    if (child instanceof CMContent) {
        CMContent content = (CMContent) child;
        result = content.getMaxOccur() > 1 || content.getMaxOccur() == -1;
    }
    return result;
}
Also used : CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 7 with CMContent

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

Example 8 with CMContent

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

the class CMDescriptionBuilder method visitCMElementDeclaration.

public void visitCMElementDeclaration(CMElementDeclaration ed) {
    if (ed == root && !isRootVisited) {
        isRootVisited = true;
        CMContent content = ed.getContent();
        if (content != null) {
            if (content.getNodeType() != CMNode.GROUP) {
                // $NON-NLS-1$
                sb.append("(");
                visitCMNode(content);
                // $NON-NLS-1$
                sb.append(")");
            } else {
                visitCMNode(content);
            }
        }
    } else {
        sb.append(ed.getElementName());
        addOccurenceSymbol(ed);
    }
}
Also used : CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 9 with CMContent

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

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

Aggregations

CMContent (org.eclipse.wst.xml.core.internal.contentmodel.CMContent)12 CMGroup (org.eclipse.wst.xml.core.internal.contentmodel.CMGroup)5 Iterator (java.util.Iterator)4 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)4 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)4 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)4 Node (org.w3c.dom.Node)3 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)2 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)2 Element (org.w3c.dom.Element)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)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 CMDocumentManager (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager)1