Search in sources :

Example 21 with CMNode

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

the class TaglibHelper method getCustomTag.

public CustomTag getCustomTag(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
    List results = new ArrayList();
    boolean isIterationTag = false;
    String tagClass = null;
    String teiClass = null;
    if (problems == null)
        problems = new ArrayList();
    ModelQuery mq = getModelQuery(structuredDoc);
    if (mq != null) {
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
        if (mgr != null) {
            List trackers = mgr.getCMDocumentTrackers(-1);
            Iterator taglibs = trackers.iterator();
            CMDocument doc = null;
            CMNamedNodeMap elements = null;
            while (taglibs.hasNext()) {
                doc = (CMDocument) taglibs.next();
                CMNode node = null;
                if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                    if (node instanceof CMNodeWrapper) {
                        node = ((CMNodeWrapper) node).getOriginNode();
                    }
                    TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
                    tagClass = tldElementDecl.getTagclass();
                    teiClass = tldElementDecl.getTeiclass();
                    isIterationTag = isIterationTag(tldElementDecl, structuredDoc, customTag, problems);
                    /*
						 * Although clearly not the right place to add validation
						 * design-wise, this is the first time we have the
						 * necessary information to validate the tag class.
						 */
                    validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
                    // 1.2+ taglib style
                    addVariables(results, node, customTag);
                    // for 1.1 need more info from taglib tracker
                    if (doc instanceof TaglibTracker) {
                        String uri = ((TaglibTracker) doc).getURI();
                        String prefix = ((TaglibTracker) doc).getPrefix();
                        // only for 1.1 taglibs
                        addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
                    }
                    break;
                }
            }
        }
    }
    return new CustomTag(tagToAdd, tagClass, teiClass, (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]), isIterationTag);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 22 with CMNode

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

the class TaglibHelper method getTaglibVariables.

/**
 * @param tagToAdd
 *            is the name of the tag whose variables we want
 * @param structuredDoc
 *            is the IStructuredDocument where the tag is found
 * @param customTag
 *            is the IStructuredDocumentRegion opening tag for the custom
 *            tag
 * @param problems problems that are generated while creating variables are added to this collection
 */
public TaglibVariable[] getTaglibVariables(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
    List results = new ArrayList();
    if (problems == null)
        problems = new ArrayList();
    ModelQuery mq = getModelQuery(structuredDoc);
    if (mq != null) {
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
        // mq).getTaglibSupport();
        if (mgr == null)
            return new TaglibVariable[0];
        List trackers = mgr.getCMDocumentTrackers(-1);
        Iterator taglibs = trackers.iterator();
        // TaglibSupport support = ((TaglibModelQuery)
        // mq).getTaglibSupport();
        // if (support == null)
        // return new TaglibVariable[0];
        // 
        // Iterator taglibs =
        // support.getCMDocuments(customTag.getStartOffset()).iterator();
        CMDocument doc = null;
        CMNamedNodeMap elements = null;
        while (taglibs.hasNext()) {
            doc = (CMDocument) taglibs.next();
            CMNode node = null;
            if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                if (node instanceof CMNodeWrapper) {
                    node = ((CMNodeWrapper) node).getOriginNode();
                }
                TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
                /*
					 * Although clearly not the right place to add validation
					 * design-wise, this is the first time we have the
					 * necessary information to validate the tag class.
					 */
                boolean tagClassFound = validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
                // 1.2+ taglib style
                addVariables(results, node, customTag);
                // for 1.1 need more info from taglib tracker
                if (tagClassFound && doc instanceof TaglibTracker) {
                    String uri = ((TaglibTracker) doc).getURI();
                    String prefix = ((TaglibTracker) doc).getPrefix();
                    // only for 1.1 taglibs
                    addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
                }
            }
        }
    }
    return (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 23 with CMNode

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

the class HTML5ContentModelTest method verifyElementDeclarationHasName.

private void verifyElementDeclarationHasName(CMNode item) {
    assertTrue(item.getNodeType() == CMNode.ELEMENT_DECLARATION);
    assertNotNull("no name on an element declaration", item.getNodeName());
    CMNamedNodeMap attrs = ((CMElementDeclaration) item).getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        CMNode attr = attrs.item(i);
        verifyAttributeDeclaration(((CMElementDeclaration) item), attr);
    }
}
Also used : 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)

Example 24 with CMNode

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

the class HTML5ContentModelTest method checkDocument.

private void checkDocument(Object documentKey) {
    CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey.toString());
    assertNotNull("missing doc:" + documentKey.toString(), document);
    CMNamedNodeMap elements = document.getElements();
    for (int i = 0; i < elements.getLength(); i++) {
        CMNode item = elements.item(i);
        verifyElementDeclarationHasName(item);
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 25 with CMNode

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

the class CtdLiContainer method createContent.

/**
 * (LI)+.
 */
protected void createContent() {
    if (content != null)
        // already created.
        return;
    if (collection == null)
        return;
    // (LI)+
    content = new CMGroupImpl(CMGroup.SEQUENCE, 1, CMContentImpl.UNBOUNDED);
    CMNode li = collection.getNamedItem(CHTMLNamespace.ElementName.LI);
    if (li != null)
        content.appendChild(li);
}
Also used : CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

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