Search in sources :

Example 11 with CMElementDeclaration

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

the class ModelQueryImpl method canWrap.

/**
 * This method is experimental... use at your own risk
 */
public boolean canWrap(Element childElement, CMElementDeclaration wrapElement, int validityChecking) {
    boolean result = true;
    Node parentNode = childElement.getParentNode();
    if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
        Element parentElement = (Element) parentNode;
        CMElementDeclaration parentEd = getCMElementDeclaration(parentElement);
        if (parentEd != null) {
            if (validityChecking == VALIDITY_STRICT) {
                int index = getIndexOfNode(parentElement.getChildNodes(), childElement);
                List contentSpecificationList = getValidator().createContentSpecificationList(parentElement, parentEd);
                List subList = contentSpecificationList.subList(index, index + 1);
                result = getValidator().canReplace(parentEd, contentSpecificationList, index, index, wrapElement);
                if (result) {
                    result = getValidator().isValid(wrapElement, subList);
                }
            }
        }
    } else {
        result = false;
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 12 with CMElementDeclaration

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

the class ModelQueryImpl method canRemove.

public boolean canRemove(List nodeList, int validityChecking) {
    boolean result = true;
    if (validityChecking == VALIDITY_STRICT) {
        Element parentElement = null;
        List childList = null;
        for (Iterator i = nodeList.iterator(); i.hasNext(); ) {
            Node node = (Node) i.next();
            if (parentElement == null) {
                parentElement = getParentOrOwnerElement(node);
            } else if (parentElement != getParentOrOwnerElement(node)) {
                // make sure the parent are the same
                result = false;
                break;
            }
            if (parentElement == null) {
                result = true;
                break;
            }
            int nodeType = node.getNodeType();
            if (nodeType == Node.ATTRIBUTE_NODE) {
                if (!canRemove(node, validityChecking)) {
                    result = false;
                    break;
                }
            } else {
                if (childList == null) {
                    childList = nodeListToList(parentElement.getChildNodes());
                }
                childList.remove(node);
            }
        }
        if (result && childList != null) {
            CMElementDeclaration ed = getCMElementDeclaration(parentElement);
            if (ed != null) {
                List contentSpecificationList = getValidator().createContentSpecificationList(childList, ed);
                result = getValidator().isValid(ed, contentSpecificationList);
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) 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) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 13 with CMElementDeclaration

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

the class ModelQueryImpl method getPossibleDataTypeValues.

/**
 * This methods return an array of possible values corresponding to the datatype of the CMNode (either an CMAttributeDeclaration or a CMElementDeclaration)
 */
public String[] getPossibleDataTypeValues(Element element, CMNode cmNode) {
    List list = new ArrayList();
    if (cmNode != null) {
        CMDataType dataType = null;
        if (cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
            dataType = ((CMAttributeDeclaration) cmNode).getAttrType();
        } else if (cmNode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
            dataType = ((CMElementDeclaration) cmNode).getDataType();
        }
        String[] enumeratedValues = dataType != null ? dataType.getEnumeratedValues() : null;
        if (enumeratedValues != null) {
            for (int i = 0; i < enumeratedValues.length; i++) {
                list.add(enumeratedValues[i]);
            }
        }
    }
    addValuesForXSIType(element, cmNode, list);
    if (extensionManager != null) {
        list.addAll(extensionManager.getDataTypeValues(element, cmNode));
    }
    // Remove duplicates
    List duplicateFreeList = new ArrayList();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (duplicateFreeList.indexOf(next) == -1) {
            duplicateFreeList.add(next);
        }
    }
    return (String[]) duplicateFreeList.toArray(new String[duplicateFreeList.size()]);
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 14 with CMElementDeclaration

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

the class XMLAssociationProvider method getCMAttributeDeclaration.

public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) {
    CMAttributeDeclaration result = null;
    Element element = attr.getOwnerElement();
    if (element != null) {
        CMElementDeclaration ed = getCMElementDeclaration(element);
        if (ed != null) {
            result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(attr.getName());
            if (result == null) {
                // try to get the unprefixed name
                String name = DOMNamespaceHelper.getUnprefixedName(attr.getName());
                result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(name);
            }
            if (result == null) {
            // todo... perhaps this is a globally defined attribute...
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Element(org.w3c.dom.Element) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 15 with CMElementDeclaration

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

the class XMLAssociationProvider method getCMElementDeclaration.

protected CMElementDeclaration getCMElementDeclaration(Element targetElement, List list, NamespaceTable namespaceTable) {
    CMElementDeclaration currentED = null;
    try {
        int listSize = list.size();
        for (int i = 0; i < listSize; i++) {
            Element element = (Element) list.get(i);
            if (i != 0) {
                namespaceTable.addElement(element);
            }
            String nodeName = element.getNodeName();
            String unprefixedName = DOMNamespaceHelper.getUnprefixedName(nodeName);
            String prefix = DOMNamespaceHelper.getPrefix(nodeName);
            CMElementDeclaration ed = null;
            // 
            if (currentED != null) {
                ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(unprefixedName);
            }
            if (ed == null) {
                NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix);
                if (namespaceInfo != null) {
                    // $NON-NLS-1$
                    CMDocument cmDocument = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD");
                    if (cmDocument != null) {
                        ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(unprefixedName);
                    }
                }
            }
            currentED = ed;
            // handle XSIType
            if (currentED != null) {
                CMElementDeclaration derivedED = getDerivedCMElementDeclaration(element, currentED, namespaceTable);
                if (derivedED != null) {
                    currentED = derivedED;
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("exception locating element declaration for " + targetElement, e);
    }
    return currentED;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Element(org.w3c.dom.Element) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15