Search in sources :

Example 21 with CMElementDeclaration

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

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

the class CSSProposalGeneratorForHTMLTag method setupHTMLTags.

/**
 */
private static String[] setupHTMLTags() {
    CMDocument cmdoc = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML_DOC_TYPE);
    CMNamedNodeMap elements = cmdoc.getElements();
    Vector names = new Vector();
    int nElements = elements.getLength();
    for (int i = 0; i < nElements; i++) {
        CMElementDeclaration edec = (CMElementDeclaration) elements.item(i);
        if (isAttrDefined(edec, HTML40Namespace.ATTR_NAME_STYLE)) {
            names.add(edec.getElementName());
        }
    }
    Collections.sort(names);
    String[] tags = new String[names.size()];
    Iterator iNames = names.iterator();
    for (int i = 0; iNames.hasNext(); i++) {
        tags[i] = (String) iNames.next();
    }
    return tags;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Iterator(java.util.Iterator) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Vector(java.util.Vector)

Example 23 with CMElementDeclaration

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

the class JSPActionValidator method checkUnknownAttributes.

private boolean checkUnknownAttributes(IDOMElement element, CMElementDeclaration elementDecl, CMNamedNodeMap cmAttrs, IReporter reporter, IFile file, IStructuredDocument document, IStructuredDocumentRegion documentRegion) {
    boolean foundjspattribute = false;
    boolean dynamicAttributesAllowed = false;
    CMElementDeclaration decl = elementDecl;
    if (decl instanceof CMNodeWrapper)
        decl = (CMElementDeclaration) ((CMNodeWrapper) decl).getOriginNode();
    if (decl instanceof TLDElementDeclaration) {
        String dynamicAttributes = ((TLDElementDeclaration) decl).getDynamicAttributes();
        dynamicAttributesAllowed = dynamicAttributes != null ? Boolean.valueOf(dynamicAttributes).booleanValue() : false;
    }
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr a = (Attr) attrs.item(i);
        CMAttributeDeclaration adec = (CMAttributeDeclaration) cmAttrs.getNamedItem(a.getName());
        if (adec == null) {
            /*
				 * No attr declaration was found. That is, the attr name is
				 * undefined. Disregard it includes JSP structure or this
				 * element supports dynamic attributes
				 */
            if (!hasJSPRegion(((IDOMNode) a).getNameRegion()) && fSeverityUnknownAttribute != ValidationMessage.IGNORE) {
                if (!dynamicAttributesAllowed) {
                    String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_6, a.getName());
                    LocalizedMessage message = new LocalizedMessage(fSeverityUnknownAttribute, msgText, file);
                    int start = ((IDOMAttr) a).getNameRegionStartOffset();
                    int length = ((IDOMAttr) a).getNameRegionEndOffset() - start;
                    int lineNo = document.getLineOfOffset(start);
                    message.setLineNo(lineNo);
                    message.setOffset(start);
                    message.setLength(length);
                    reporter.addMessage(fMessageOriginator, message);
                }
            } else {
                foundjspattribute = true;
            }
        } else {
            if (fSeverityUnexpectedRuntimeExpression != ValidationMessage.IGNORE && adec instanceof TLDAttributeDeclaration) {
                // The attribute cannot have a runtime evaluation of an expression
                if (!isTrue(((TLDAttributeDeclaration) adec).getRtexprvalue())) {
                    IDOMAttr attr = (IDOMAttr) a;
                    if (checkRuntimeValue(attr) && !fIsELIgnored) {
                        String msg = NLS.bind(JSPCoreMessages.JSPActionValidator_1, a.getName());
                        LocalizedMessage message = new LocalizedMessage(fSeverityUnexpectedRuntimeExpression, msg, file);
                        ITextRegion region = attr.getValueRegion();
                        int start = attr.getValueRegionStartOffset();
                        int length = region != null ? region.getTextLength() : 0;
                        int lineNo = document.getLineOfOffset(start);
                        message.setLineNo(lineNo);
                        message.setOffset(start);
                        message.setLength(length);
                        reporter.addMessage(fMessageOriginator, message);
                    }
                }
            }
        }
    }
    return foundjspattribute;
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) TLDAttributeDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 24 with CMElementDeclaration

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

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

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