Search in sources :

Example 86 with CMNode

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

the class XMLAssociationProvider method getCorrespondingCMDocument.

protected CMDocument getCorrespondingCMDocument(Node node, boolean getDocumentFromCMNode) {
    CMDocument result = null;
    try {
        Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
        String[] doctypeInfo = getDoctypeInfo(document);
        if (doctypeInfo != null) {
            // $NON-NLS-1$
            result = getCMDocument(doctypeInfo[0], doctypeInfo[1], "DTD");
        } else // TODO... see if there is a way to re-organize to avoid the need for this flag
        if (getDocumentFromCMNode) {
            CMNode cmNode = getCMNode(node);
            if (cmNode != null) {
                // todo... add a getCMDocument() methods to CMNode
                // for now use the getProperty interface
                // $NON-NLS-1$
                result = (CMDocument) cmNode.getProperty("CMDocument");
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("exception locating CMDocument for " + node, e);
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 87 with CMNode

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

the class ModelQueryActionHelper method getInsertChildNodeActions.

protected void getInsertChildNodeActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList) {
    int size = parent.getChildNodes().getLength();
    List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed);
    List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions);
    boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed);
    for (Iterator iterator = availableChildNodeList.iterator(); iterator.hasNext(); ) {
        CMNode cmNode = (CMNode) iterator.next();
        for (int i = size; i >= 0; i--) {
            if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, i, validityChecking, contentSpecificationList)) {
                Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, i, i);
                actionList.add(action);
                break;
            }
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) 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)

Example 88 with CMNode

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

the class ModelQueryActionHelper method getInsertChildNodeActionsAtIndex.

protected void getInsertChildNodeActionsAtIndex(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList) {
    // get actions for each insertable attribute
    // 
    int size = parent.getChildNodes().getLength();
    if (index <= size) {
        List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed);
        List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions);
        boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed);
        for (Iterator i = availableChildNodeList.iterator(); i.hasNext(); ) {
            CMNode cmNode = (CMNode) i.next();
            if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, index, validityChecking, contentSpecificationList)) {
                Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index);
                actionList.add(action);
            }
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) 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)

Example 89 with CMNode

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

the class ModelQueryActionHelper method getInsertActions.

public void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList) {
    // get the root element and doctype index (if any)
    // 
    int doctypeIndex = -1;
    DocumentType doctype = null;
    Element rootElement = null;
    NodeList nodeList = parent.getChildNodes();
    int nodeListLength = nodeList.getLength();
    for (int i = 0; i < nodeListLength; i++) {
        Node childNode = nodeList.item(i);
        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
            rootElement = (Element) childNode;
            break;
        } else if (childNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
            doctype = (DocumentType) childNode;
            doctypeIndex = i;
        }
    }
    // make sure that root elements are only added after the doctype (if any)
    if (rootElement == null && index > doctypeIndex) {
        CMNamedNodeMap map = cmDocument.getElements();
        int mapLength = map.getLength();
        for (int i = 0; i < mapLength; i++) {
            CMNode cmNode = map.item(i);
            boolean canAdd = true;
            if (validityChecking == ModelQuery.VALIDITY_STRICT) {
                canAdd = doctype == null || doctype.getName().equals(cmNode.getNodeName());
            }
            if (canAdd) {
                Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index);
                actionList.add(action);
            }
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) DocumentType(org.w3c.dom.DocumentType) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 90 with CMNode

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

the class DOMContentBuilderImpl method visitCMGroup.

public void visitCMGroup(CMGroup e) {
    cmGroupStack.push(e);
    int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
    int min = Math.max(e.getMinOccur(), forcedMin);
    int max = 0;
    if (// unbounded
    e.getMaxOccur() == -1)
        max = getNumOfRepeatableElements();
    else
        max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements());
    if (max < min)
        max = min;
    alwaysVisit = false;
    for (int i = 1; i <= max; i++) {
        if (e.getOperator() == CMGroup.CHOICE && buildFirstChoice(buildPolicy)) {
            CMNode hintNode = null;
            // todo... the CMGroup should specify the hint... but it seems
            // as though
            // the Yamato guys are making the CMElement specify the hint.
            // I do it that way for now until... we should fix this post
            // GA
            // 
            int listSize = visitedCMElementDeclarationList.size();
            if (listSize > 0) {
                CMElementDeclaration ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
                // $NON-NLS-1$
                Object contentHint = ed.getProperty("contentHint");
                if (contentHint instanceof CMNode) {
                    hintNode = (CMNode) contentHint;
                }
            }
            // see if this hint corresponds to a valid choice
            // 
            CMNode cmNode = null;
            if (hintNode != null) {
                CMNodeList nodeList = e.getChildNodes();
                int nodeListLength = nodeList.getLength();
                for (int j = 0; j < nodeListLength; j++) {
                    if (hintNode == nodeList.item(j)) {
                        cmNode = hintNode;
                    }
                }
            }
            // 
            if (cmNode == null) {
                CMNodeList nodeList = e.getChildNodes();
                if (nodeList.getLength() > 0) {
                    cmNode = nodeList.item(0);
                }
            }
            if (cmNode != null) {
                // Visit the node only if it is not a GROUP (model group). If it is an element, then visit it.
                if (!(cmNode.getNodeType() == CMNode.GROUP && min > 0)) {
                    visitCMNode(cmNode);
                }
            }
        } else if (// ALL
        e.getOperator() == CMGroup.ALL || // SEQUENCE
        e.getOperator() == CMGroup.SEQUENCE) {
            // visit all of the content
            super.visitCMGroup(e);
        }
    }
    cmGroupStack.pop();
}
Also used : 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)

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