Search in sources :

Example 6 with ModelQuery

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

Example 7 with ModelQuery

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

the class TaglibHelper method getModelQuery.

/**
 * @return Returns the fModelQuery.
 */
public ModelQuery getModelQuery(IDocument doc) {
    IStructuredModel model = null;
    ModelQuery mq = null;
    try {
        model = StructuredModelManager.getModelManager().getExistingModelForRead(doc);
        mq = ModelQueryUtil.getModelQuery(model);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
    return mq;
}
Also used : ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 8 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery 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 9 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery 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 10 with ModelQuery

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

the class XMLHyperlinkDetector method getCMElementDeclaration.

/**
 * Get the CMElementDeclaration for an element
 *
 * @param element
 * @return CMElementDeclaration
 */
private CMElementDeclaration getCMElementDeclaration(Element element) {
    CMElementDeclaration ed = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if (mq != null) {
        ed = mq.getCMElementDeclaration(element);
    }
    return ed;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Aggregations

ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)76 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)38 List (java.util.List)22 ArrayList (java.util.ArrayList)19 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)18 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)16 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)15 Element (org.w3c.dom.Element)15 Document (org.w3c.dom.Document)14 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)13 Node (org.w3c.dom.Node)12 Iterator (java.util.Iterator)10 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 NodeList (org.w3c.dom.NodeList)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6