Search in sources :

Example 36 with CMNamedNodeMap

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

the class BugFixesTest method testGlobalElementDocumentation.

public void testGlobalElementDocumentation() {
    // See bug 157254
    Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
    URL url = bundle.getEntry("/testresources/samples/documentation/globalreftest.xsd");
    CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull("Content model loaded Null", document);
    CMNamedNodeMap elements = document.getElements();
    CMElementDeclaration node = (CMElementDeclaration) elements.getNamedItem("rootTest");
    assertNotNull("Missing rootElement", node);
    CMElementDeclaration testElement = (CMElementDeclaration) node.getLocalElements().getNamedItem("test");
    assertNotNull("Missing test element", testElement);
    CMNodeList documentation = (CMNodeList) testElement.getProperty("documentation");
    if (documentation.getLength() == 0) {
        fail("test global element missing documentation.");
    }
    for (int cnt = 0; cnt < documentation.getLength(); cnt++) {
        DocumentationImpl doc = (DocumentationImpl) documentation.item(cnt);
        assertEquals("Test global element missing documentation.", "This some global documentation", doc.getValue());
    }
    testElement = (CMElementDeclaration) node.getLocalElements().getNamedItem("testElement");
    documentation = (CMNodeList) testElement.getProperty("documentation");
    if (documentation.getLength() == 0) {
        fail("testElement local element missing documentation.");
    }
    for (int cnt = 0; cnt < documentation.getLength(); cnt++) {
        DocumentationImpl doc = (DocumentationImpl) documentation.item(cnt);
        assertEquals("testElement documentation wrong.", "This is an override", doc.getValue());
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Bundle(org.osgi.framework.Bundle) DocumentationImpl(org.eclipse.wst.xsd.contentmodel.internal.XSDImpl.DocumentationImpl) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) URL(java.net.URL) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 37 with CMNamedNodeMap

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

the class BugFixesTest method testXSIType.

// Add tests here
@SuppressWarnings("unchecked")
public void testXSIType() {
    String soapSchemaURI = locateFileUsingCatalog("http://schemas.xmlsoap.org/wsdl/soap/");
    CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
    assertNotNull("Assert factory is not null", factory);
    CMDocument cmDocument = factory.createCMDocument(soapSchemaURI);
    assertNotNull("Assert CMDocument is not null", cmDocument);
    CMNamedNodeMap elements = cmDocument.getElements();
    boolean foundDesiredElement = false;
    for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); ) {
        CMElementDeclaration element = i.next();
        if ("binding".equals(element.getElementName())) {
            foundDesiredElement = true;
            CMNamedNodeMap attributes = element.getAttributes();
            // Three attributes: required, transport and style
            assertNotNull(attributes);
            // If the xsi:type was present, it would be 4 attributes
            assertTrue(attributes.getLength() == 3);
            CMNode attrNode = null;
            attrNode = attributes.getNamedItem("required");
            assertNotNull(attrNode);
            attrNode = attributes.getNamedItem("transport");
            assertNotNull(attrNode);
            attrNode = attributes.getNamedItem("style");
            assertNotNull(attrNode);
            // Should be null!
            attrNode = attributes.getNamedItem("type");
            assertNull(attrNode);
            break;
        }
    }
    // if we didn't even find the binding element, then something terrible went wrong
    assertTrue(foundDesiredElement);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMDocumentFactoryXSD(org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD)

Example 38 with CMNamedNodeMap

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

the class DefaultXMLPartitionFormatter method updateFormattingConstraints.

/**
 * Given the provided information (parentConstraints & currentDOMRegion),
 * update the formatting constraints (for this & child)
 *
 * @param parentConstraints
 *            can be null
 * @param thisConstraints
 *            can be null
 * @param childConstraints
 *            can be null
 * @param currentDOMRegion
 *            cannot be null
 */
protected void updateFormattingConstraints(XMLFormattingConstraints parentConstraints, XMLFormattingConstraints thisConstraints, XMLFormattingConstraints childConstraints, DOMRegion currentDOMRegion) {
    IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
    IDOMNode currentNode = currentDOMRegion.domNode;
    // default to whatever parent's constraint said to do
    if (parentConstraints != null) {
        if (thisConstraints != null) {
            thisConstraints.copyConstraints(parentConstraints);
        }
        if (childConstraints != null) {
            childConstraints.copyConstraints(parentConstraints);
            // defaults are taken instead
            if (parentConstraints.isWhitespaceStrategyAHint())
                childConstraints.setWhitespaceStrategy(null);
        }
    }
    // set up constraints for direct children of document root
    Node parentNode = currentNode.getParentNode();
    if (parentNode != null && parentNode.getNodeType() == Node.DOCUMENT_NODE) {
        if (thisConstraints != null) {
            thisConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
            thisConstraints.setIndentStrategy(XMLFormattingConstraints.NEW_LINE);
            thisConstraints.setIndentLevel(0);
        }
        if (childConstraints != null) {
            childConstraints.setWhitespaceStrategy(null);
            childConstraints.setIndentStrategy(null);
            childConstraints.setIndentLevel(0);
        }
    }
    // other conditions to check when setting up child constraints
    if (childConstraints != null) {
        XMLFormattingPreferences preferences = getFormattingPreferences();
        // on a new line and have an indent level of 0
        if (currentNode.getNodeType() == Node.DOCUMENT_NODE) {
            childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
            childConstraints.setIndentStrategy(XMLFormattingConstraints.NEW_LINE);
            childConstraints.setIndentLevel(0);
        } else {
            // BUG108074 & BUG84688 - preserve whitespace in xsl:text &
            // xsl:attribute
            String nodeNamespaceURI = currentNode.getNamespaceURI();
            if (XSL_NAMESPACE.equals(nodeNamespaceURI)) {
                String nodeName = ((Element) currentNode).getLocalName();
                if (XSL_ATTRIBUTE.equals(nodeName) || XSL_TEXT.equals(nodeName)) {
                    childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
                }
            } else {
                // search within current tag for xml:space attribute
                ITextRegionList textRegions = currentRegion.getRegions();
                int i = 0;
                boolean xmlSpaceFound = false;
                boolean preserveFound = false;
                while (i < textRegions.size() && !xmlSpaceFound) {
                    ITextRegion textRegion = textRegions.get(i);
                    if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegion.getType())) {
                        String regionText = currentRegion.getText(textRegion);
                        if (XML_SPACE.equals(regionText)) {
                            if ((i + 1) < textRegions.size()) {
                                ++i;
                                textRegion = textRegions.get(i);
                                if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(textRegion.getType()) && ((i + 1) < textRegions.size())) {
                                    ++i;
                                    textRegion = textRegions.get(i);
                                    regionText = currentRegion.getText(textRegion);
                                    if (PRESERVE.equals(regionText) || PRESERVE_QUOTED.equals(regionText)) {
                                        preserveFound = true;
                                    }
                                }
                            }
                            xmlSpaceFound = true;
                        }
                    }
                    ++i;
                }
                if (xmlSpaceFound) {
                    if (preserveFound) {
                        // preserve was found so set the strategy
                        childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
                    } else {
                        // xml:space was found but it was not collapse, so
                        // use default whitespace strategy
                        childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.DEFAULT);
                    }
                } else {
                    // how to hande nodes that have nonwhitespace text
                    // content
                    NodeList nodeList = currentNode.getChildNodes();
                    int length = nodeList.getLength();
                    int index = 0;
                    boolean textNodeFound = false;
                    // still reflect the parent constraints
                    while (index < length && !textNodeFound && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
                        Node childNode = nodeList.item(index);
                        if (childNode.getNodeType() == Node.TEXT_NODE) {
                            textNodeFound = !((IDOMText) childNode).isElementContentWhitespace();
                        }
                        ++index;
                    }
                    if (textNodeFound) {
                        if (length > 1) {
                            // more in here than just text, so consider
                            // this mixed content
                            childConstraints.setWhitespaceStrategy(preferences.getMixedWhitespaceStrategy());
                            childConstraints.setIndentStrategy(preferences.getMixedIndentStrategy());
                        } else {
                            // there's only text
                            childConstraints.setWhitespaceStrategy(preferences.getTextWhitespaceStrategy());
                            childConstraints.setIndentStrategy(preferences.getTextIndentStrategy());
                        }
                        childConstraints.setIsWhitespaceStrategyAHint(true);
                        childConstraints.setIsIndentStrategyAHint(true);
                    }
                    // try referring to content model for information on
                    // whitespace & indent strategy
                    ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) currentNode.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
                    CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(currentNode);
                    if (elementDeclaration != null) {
                        // follow whitespace strategy preference for
                        // pcdata content
                        int contentType = elementDeclaration.getContentType();
                        String facetValue = null;
                        if (elementDeclaration.getDataType() != null)
                            facetValue = (String) elementDeclaration.getDataType().getProperty(PROPERTY_WHITESPACE_FACET);
                        if (facetValue != null) {
                            if (PRESERVE.equals(facetValue))
                                childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
                            else // For XSD types, "collapse" corresponds to the IGNOREANDTRIM strategy
                            if (COLLAPSE.equals(facetValue))
                                childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNOREANDTRIM);
                            else if (REPLACE.equals(facetValue))
                                childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.REPLACE);
                        } else if (contentType == CMElementDeclaration.PCDATA && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
                            childConstraints.setWhitespaceStrategy(preferences.getPCDataWhitespaceStrategy());
                        } else if (contentType == CMElementDeclaration.ELEMENT && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
                            childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
                            childConstraints.setIndentStrategy(XMLFormattingConstraints.INDENT);
                            childConstraints.setIsWhitespaceStrategyAHint(true);
                            childConstraints.setIsIndentStrategyAHint(true);
                        } else {
                            // look for xml:space in content model
                            CMNamedNodeMap cmAttributes = elementDeclaration.getAttributes();
                            // Not needed - we're looking for xml:space
                            // CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(cmAttributes);
                            // List nodes = ModelQueryUtil.getModelQuery(currentNode.getOwnerDocument()).getAvailableContent((Element) currentNode, elementDeclaration, ModelQuery.INCLUDE_ATTRIBUTES);
                            // for (int k = 0; k < nodes.size(); k++) {
                            // CMNode cmnode = (CMNode) nodes.get(k);
                            // if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                            // allAttributes.put(cmnode);
                            // }
                            // }
                            // cmAttributes = allAttributes;
                            // Check implied values from the DTD way.
                            CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
                            if (attributeDeclaration != null) {
                                // CMAttributeDeclaration found, check
                                // it
                                // out.
                                // BUG214516/196544 - Fixed NPE that was caused by an attr having
                                // a null attr type
                                String defaultValue = null;
                                CMDataType attrType = attributeDeclaration.getAttrType();
                                if (attrType != null) {
                                    if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && attrType.getImpliedValue() != null)
                                        defaultValue = attrType.getImpliedValue();
                                    else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
                                        defaultValue = attrType.getEnumeratedValues()[0];
                                    }
                                }
                                // default.
                                if (PRESERVE.equals(defaultValue))
                                    childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
                                else
                                    childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.DEFAULT);
                            } else // If the node has no attributes, inherit the parents whitespace strategy
                            {
                                if (parentConstraints != null)
                                    childConstraints.setWhitespaceStrategy(parentConstraints.getWhitespaceStrategy());
                                else
                                    childConstraints.setWhitespaceStrategy(null);
                            }
                        }
                    }
                }
            }
        }
        // set default values according to preferences
        if (childConstraints.getWhitespaceStrategy() == null) {
            childConstraints.setWhitespaceStrategy(preferences.getElementWhitespaceStrategy());
        }
        if (childConstraints.getIndentStrategy() == null) {
            childConstraints.setIndentStrategy(preferences.getElementIndentStrategy());
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMText(org.eclipse.wst.xml.core.internal.provisional.document.IDOMText) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 39 with CMNamedNodeMap

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

the class AbstractContentAssistProcessor method addAttributeNameProposals.

protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
    IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion();
    // retrieve the list of attributes
    CMElementDeclaration elementDecl = getCMElementDeclaration(node);
    if (elementDecl != null) {
        CMNamedNodeMap attributes = elementDecl.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
            for (int k = 0; k < nodes.size(); k++) {
                CMNode cmnode = (CMNode) nodes.get(k);
                if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                    allAttributes.put(cmnode);
                }
            }
        }
        attributes = allAttributes;
        String matchString = contentAssistRequest.getMatchString();
        // check whether an attribute really exists for the replacement
        // offsets AND if it possesses a value
        boolean attrAtLocationHasValue = false;
        NamedNodeMap attrs = node.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
            AttrImpl existingAttr = (AttrImpl) attrs.item(i);
            ITextRegion name = existingAttr.getNameRegion();
            if ((sdRegion.getStartOffset(name) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(name) + name.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()) && (existingAttr.getValueRegion() != null)) {
                attrAtLocationHasValue = true;
                break;
            }
        }
        // the matchstring
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);
                int isRequired = 0;
                if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
                    isRequired = XMLRelevanceConstants.R_REQUIRED;
                }
                boolean showAttribute = true;
                showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
                AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
                ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
                // nameRegion.getEndOffset() + 1 is required to allow for
                // matches against the full name of an existing Attr
                showAttribute = showAttribute && (attr == null || nameRegion == null || (nameRegion != null && (sdRegion.getStartOffset(nameRegion) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength())));
                if (showAttribute) {
                    Image attrImage = CMImageUtil.getImage(attrDecl);
                    if (attrImage == null) {
                        if (isRequired > 0) {
                            attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
                        } else {
                            attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                        }
                    }
                    String proposedText = null;
                    String proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
                    CustomCompletionProposal proposal = null;
                    // attribute is at this location and already exists
                    if (attrAtLocationHasValue) {
                        // only propose the name
                        proposedText = getRequiredName(node, attrDecl);
                        proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), attrImage, proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true);
                    } else // no attribute exists or is elsewhere, generate
                    // minimally
                    {
                        Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
                        String value = null;
                        if (existingAttrNode != null && existingAttrNode.getSpecified()) {
                            value = existingAttrNode.getNodeValue();
                        }
                        if ((value != null) && (value.length() > 0)) {
                            proposedText = getRequiredName(node, attrDecl);
                        } else {
                            proposedText = getRequiredText(node, attrDecl);
                        }
                        proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), attrDecl.getNodeName().length() + 2, attrImage, // and there is no single quote that may be encasing a double quote
                        (showValues && (proposedText.lastIndexOf('\"') - proposedText.indexOf('\"') == 1 && proposedText.indexOf('\'') == -1)) ? getRequiredName(node, attrDecl) : proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired);
                    }
                    contentAssistRequest.addProposal(proposal);
                }
            }
        }
    } else {
        setErrorMessage(NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[] { node.getNodeName() })));
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) AttrImpl(org.eclipse.wst.xml.core.internal.document.AttrImpl) Image(org.eclipse.swt.graphics.Image) Attr(org.w3c.dom.Attr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 40 with CMNamedNodeMap

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

the class AbstractContentAssistProcessor method attributeInList.

/**
 * This method determines if any of the attributes in the proposed XMLNode
 * node, are possible values of attributes from possible Elements at this
 * point in the document according to the Content Model.
 *
 * @param node
 *            the element with attributes that you would like to test if
 *            are possible for possible Elements at this point
 * @param cmnode
 *            possible element at this point in the document (depending on
 *            what 'node' is) true if any attributes of 'node' match any
 *            possible attributes from 'cmnodes' list.
 */
protected boolean attributeInList(IDOMNode node, Node parent, CMNode cmnode) {
    if ((node == null) || (parent == null) || (cmnode == null)) {
        return false;
    }
    String elementMatchString = node.getNodeName();
    // cmnode.getNodeName();
    String cmnodeName = getRequiredName(parent, cmnode);
    if (node instanceof Element) {
        NamedNodeMap map = ((Element) node).getAttributes();
        // $NON-NLS-1$
        String attrMatchString = "";
        CMNamedNodeMap cmattrMap = null;
        // iterate attribute possibilities for partially started node
        for (int i = 0; (map != null) && (i < map.getLength()); i++) {
            attrMatchString = map.item(i).getNodeName();
            // filter on whatever user typed for element name already
            if (beginsWith(cmnodeName, elementMatchString)) {
                if (cmnode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                    cmattrMap = ((CMElementDeclaration) cmnode).getAttributes();
                    CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(cmattrMap);
                    List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, (CMElementDeclaration) cmnode, ModelQuery.INCLUDE_ATTRIBUTES);
                    for (int k = 0; k < nodes.size(); k++) {
                        CMNode adnode = (CMNode) nodes.get(k);
                        if (adnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                            allAttributes.put(adnode);
                        }
                    }
                    cmattrMap = allAttributes;
                    // proposal list
                    for (int k = 0; (cmattrMap != null) && (k < cmattrMap.getLength()); k++) {
                        // check if name matches
                        if (cmattrMap.item(k).getNodeName().equals(attrMatchString)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)68 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)39 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)36 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)26 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)23 List (java.util.List)21 ArrayList (java.util.ArrayList)18 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)16 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 Element (org.w3c.dom.Element)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)9 NodeList (org.w3c.dom.NodeList)9 Iterator (java.util.Iterator)8 Attr (org.w3c.dom.Attr)8 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)6 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)6 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)6