Search in sources :

Example 11 with CMNamedNodeMap

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

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

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

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

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

the class HTMLTagInfoTest method getCMAttributeDeclaration.

/**
 * Retreives CMAttributeDeclaration indicated by attribute name within
 * elementDecl
 */
private CMAttributeDeclaration getCMAttributeDeclaration(CMElementDeclaration elementDecl, String attName) {
    CMAttributeDeclaration attrDecl = null;
    if (elementDecl != null) {
        CMNamedNodeMap attributes = elementDecl.getAttributes();
        String noprefixName = DOMNamespaceHelper.getUnprefixedName(attName);
        if (attributes != null) {
            attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName);
            if (attrDecl == null) {
                attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attName);
            }
        }
    }
    return attrDecl;
}
Also used : CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) 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