Search in sources :

Example 16 with CMNode

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

the class AbstractBreakpointProvider method isCustomTagRegion.

private static boolean isCustomTagRegion(IndexedRegion node) {
    if (node instanceof Element) {
        Element xmlElement = (Element) node;
        ModelQuery mq = ModelQueryUtil.getModelQuery(xmlElement.getOwnerDocument());
        CMElementDeclaration decl = mq.getCMElementDeclaration(xmlElement);
        if (decl instanceof CMNodeWrapper) {
            CMNode cmNode = ((CMNodeWrapper) decl).getOriginNode();
            return cmNode instanceof TLDElementDeclaration;
        }
    }
    return false;
}
Also used : CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Example 17 with CMNode

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

the class CMGroupWrapperImpl method getChildNodes.

/**
 * getChildNodes method
 * @return CMNodeList
 *
 * Returns child CMNodeList, which includes ElementDefinition or CMElement.
 */
public CMNodeList getChildNodes() {
    if (fChildNodes == null) {
        CMNodeListImpl childNodes = new CMNodeListImpl();
        CMNodeList children = fGroup.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            CMNode child = children.item(i);
            if (child instanceof CMGroup)
                childNodes.appendItem(new CMGroupWrapperImpl(fPrefix, (CMGroup) child));
            else if (child instanceof CMElementDeclaration)
                childNodes.appendItem(new CMElementDeclarationWrapperImpl(fPrefix, (CMElementDeclaration) child));
            else
                // error?
                childNodes.appendItem(new CMNodeWrapperImpl(fPrefix, child));
        }
        fChildNodes = childNodes;
    }
    return fChildNodes;
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) 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)

Example 18 with CMNode

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

the class JSPActionValidator method processDirective.

private void processDirective(IReporter reporter, IFile file, IStructuredModel model, IStructuredDocumentRegion documentRegion) {
    IndexedRegion ir = model.getIndexedRegion(documentRegion.getStartOffset());
    if (ir instanceof IDOMElement) {
        IDOMElement element = (IDOMElement) ir;
        ModelQuery query = ModelQueryUtil.getModelQuery(model);
        if (query != null) {
            CMElementDeclaration cmElement = query.getCMElementDeclaration(element);
            if (cmElement != null) {
                CMNamedNodeMap cmAttributes = null;
                CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl();
                List nodes = query.getAvailableContent(element, cmElement, 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;
                boolean foundjspattribute = checkUnknownAttributes(element, cmElement, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
                // missing required attributes
                if (!foundjspattribute && fSeverityMissingRequiredAttribute != ValidationMessage.IGNORE)
                    checkRequiredAttributes(element, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
                if (fSeverityNonEmptyInlineTag != ValidationMessage.IGNORE)
                    checkNonEmptyInlineTag(element, cmElement, reporter, file, model.getStructuredDocument());
            }
        }
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 19 with CMNode

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

the class JSPModelQueryExtension method getAvailableElementContent.

/**
 * Originally taken from JSPContentAssistProcessor
 *
 * @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
 */
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
    CMNode[] nodes = EMPTY_CMNODE_ARRAY;
    ArrayList nodeList = new ArrayList();
    // only returns anything if looking for child nodes
    if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMNode) {
        IDOMNode node = (IDOMNode) parentElement;
        // get position dependent CMDocuments and insert their tags as
        // proposals
        ModelQueryAdapter mqAdapter = null;
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            mqAdapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
        } else {
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
        }
        if (mqAdapter != null) {
            CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
            if (doc != null) {
                CMDocument jcmdoc = getDefaultJSPCMDocument(node);
                CMNamedNodeMap jspelements = jcmdoc.getElements();
                /* For a built-in JSP action the content model is properly
					 * set up, so don't just blindly add the rest--unless this
					 * will be a direct child of the document
					 */
                if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
                    List rejectElements = new ArrayList();
                    // determine if the document is in XML form
                    Document domDoc = null;
                    if (node.getNodeType() == Node.DOCUMENT_NODE) {
                        domDoc = (Document) node;
                    } else {
                        domDoc = node.getOwnerDocument();
                    }
                    // Show XML tag forms of JSP markers if jsp:root is
                    // the document element OR it's HTML but
                    // isn't really in the text.
                    // If the document isn't strictly XML, pull out the
                    // XML tag forms it is xml format
                    rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
                    rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
                    rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
                    rejectElements.add(JSP12Namespace.ElementName.TEXT);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
                    if (isXMLFormat(domDoc)) {
                        // jsp actions
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
                        rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
                        rejectElements.add(JSP12Namespace.ElementName.FORWARD);
                        rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.PARAM);
                        rejectElements.add(JSP12Namespace.ElementName.PARAMS);
                    }
                    // don't show jsp:root if a document element already
                    // exists
                    Element docElement = domDoc.getDocumentElement();
                    if (docElement != null && ((docElement.getNodeName().equals(TAG_JSP_ROOT)) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null)))) {
                        rejectElements.add(JSP12Namespace.ElementName.ROOT);
                    }
                    for (int j = 0; j < jspelements.getLength(); j++) {
                        CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
                        if (!rejectElements.contains(ed.getNodeName())) {
                            nodeList.add(ed);
                        }
                    }
                }
            } else // No cm document (such as for the Document (a non-Element) node itself)
            {
                CMNamedNodeMap jspElements = getDefaultJSPCMDocument(node).getElements();
                int length = jspElements.getLength();
                for (int i = 0; i < length; i++) {
                    nodeList.add(jspElements.item(i));
                }
            }
        }
        nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
    }
    return nodes;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) Document(org.w3c.dom.Document) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) ArrayList(java.util.ArrayList) List(java.util.List) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 20 with CMNode

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

the class TaglibModelQueryExtension method getAvailableElementContent.

/**
 * @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
 */
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
    CMNode[] nodes = EMPTY_CMNODE_ARRAY;
    ArrayList nodeList = new ArrayList();
    // only returns anything if looking for child nodes
    if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMElement) {
        // get the trackers
        IDOMElement elem = (IDOMElement) parentElement;
        IStructuredDocument structDoc = elem.getModel().getStructuredDocument();
        TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(structDoc);
        if (manager != null) {
            List trackers = new ArrayList(manager.getTaglibTrackers());
            Set prefixes = new HashSet();
            // for each tracker add each of its elements to the node list
            for (int trackerIndex = 0; trackerIndex < trackers.size(); ++trackerIndex) {
                TaglibTracker tracker = ((TaglibTracker) trackers.get(trackerIndex));
                CMNamedNodeMap elements = tracker.getElements();
                for (int elementIndex = 0; elementIndex < elements.getLength(); ++elementIndex) {
                    nodeList.add(elements.item(elementIndex));
                }
                prefixes.add(tracker.getPrefix());
            }
            String prefix = parentElement.getPrefix();
            if (prefixes.contains(prefix)) {
                Node parent = parentElement;
                while ((parent = parent.getParentNode()) != null && parent.getNodeType() == Node.ELEMENT_NODE) {
                    prefix = parent.getPrefix();
                    if (prefix == null || !prefixes.contains(prefix)) {
                        ModelQuery query = ModelQueryUtil.getModelQuery(parentElement.getOwnerDocument());
                        if (query != null) {
                            CMElementDeclaration decl = query.getCMElementDeclaration((Element) parent);
                            if (decl != null && !fExtensions.contains(this)) {
                                fExtensions.push(this);
                                nodeList.addAll(query.getAvailableContent((Element) parent, decl, includeOptions));
                                fExtensions.pop();
                            }
                        }
                        break;
                    }
                }
            }
            nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
        }
    }
    return nodes;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) Set(java.util.Set) HashSet(java.util.HashSet) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ArrayList(java.util.ArrayList) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) HashSet(java.util.HashSet)

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