Search in sources :

Example 11 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager in project webtools.sourceediting by eclipse.

the class JSPELContentAssistProcessor method getFunctionProposals.

protected List getFunctionProposals(String prefix, StructuredTextViewer viewer, int offset) {
    TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(viewer.getDocument());
    ArrayList completionList = new ArrayList();
    if (docMgr == null)
        return null;
    Iterator taglibs = docMgr.getCMDocumentTrackers(offset).iterator();
    while (taglibs.hasNext()) {
        TaglibTracker tracker = (TaglibTracker) taglibs.next();
        if (tracker.getPrefix().equals(prefix)) {
            CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
            List functions = doc.getFunctions();
            for (Iterator it = functions.iterator(); it.hasNext(); ) {
                TLDFunction function = (TLDFunction) it.next();
                CustomCompletionProposal proposal = new // $NON-NLS-1$
                CustomCompletionProposal(// $NON-NLS-1$
                function.getName() + "()", offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, // $NON-NLS-1$
                1);
                completionList.add(proposal);
            }
        }
    }
    return completionList;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ArrayList(java.util.ArrayList) List(java.util.List) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction) CMDocumentImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)

Example 12 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager in project webtools.sourceediting by eclipse.

the class LibraryTagsCompletionProposalComputer method forciblyGetTagLibAndJSPElements.

/**
 * <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
 * <p>This is bad because it does not use the ModelQuery framework, it
 * access the TLDCMDocumentManager directly</p>
 * <p>This is essentially a combination of the {@link TaglibModelQueryExtension} and
 * the {@link JSPModelQueryExtension} but it means any other extensions get left
 * out when creating content assist suggestion at the document root level</p>
 *
 * @param elementDecls
 * @param node
 * @param childIndex
 * @return
 */
private List forciblyGetTagLibAndJSPElements(List elementDecls, Node node, int childIndex) {
    if (node instanceof IDOMNode) {
        /*
			 * find the location of the intended insertion as it will give us
			 * the correct offset for checking position dependent CMDocuments
			 */
        int textInsertionOffset = 0;
        NodeList children = node.getChildNodes();
        if (children.getLength() >= childIndex && childIndex >= 0) {
            Node nodeAlreadyAtIndex = children.item(childIndex);
            if (nodeAlreadyAtIndex instanceof IDOMNode)
                textInsertionOffset = ((IDOMNode) nodeAlreadyAtIndex).getEndOffset();
        } else {
            textInsertionOffset = ((IDOMNode) node).getStartOffset();
        }
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((IDOMNode) node).getStructuredDocument());
        if (mgr != null) {
            List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset);
            if (moreCMDocuments != null) {
                for (int i = 0; i < moreCMDocuments.size(); i++) {
                    CMDocument doc = (CMDocument) moreCMDocuments.get(i);
                    CMNamedNodeMap elements = doc.getElements();
                    if (elements != null) {
                        for (int j = 0; j < elements.getLength(); j++) {
                            CMElementDeclaration ed = (CMElementDeclaration) elements.item(j);
                            elementDecls.add(ed);
                        }
                    }
                }
            }
        }
        // get position dependent CMDocuments and insert their tags as
        // proposals
        ModelQueryAdapter mqAdapter = null;
        if (node.getNodeType() == Node.DOCUMENT_NODE)
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) 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((IDOMNode) 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 (// $NON-NLS-1$
                    docElement != null && ((docElement.getNodeName().equals("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()))
                            continue;
                        elementDecls.add(ed);
                    }
                }
            } else // No cm document (such as for the Document (a non-Element) node itself)
            {
                CMNamedNodeMap jspElements = getDefaultJSPCMDocument((IDOMNode) node).getElements();
                int length = jspElements.getLength();
                for (int i = 0; i < length; i++) {
                    elementDecls.add(jspElements.item(i));
                }
            }
        }
    }
    return elementDecls;
}
Also used : JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) NodeList(org.w3c.dom.NodeList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) 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) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 13 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager in project webtools.sourceediting by eclipse.

the class ELGeneratorVisitor method genFunction.

/**
 * Generate a function invocation.
 *
 * @param fullFunctionName
 * @return
 */
protected String genFunction(String fullFunctionName) {
    TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(fDocument);
    int colonIndex = fullFunctionName.indexOf(':');
    String prefix = fullFunctionName.substring(0, colonIndex);
    String functionName = fullFunctionName.substring(colonIndex + 1);
    if (docMgr == null)
        return null;
    Iterator taglibs = docMgr.getCMDocumentTrackers(fCurrentNode.getStartOffset()).iterator();
    while (taglibs.hasNext()) {
        TaglibTracker tracker = (TaglibTracker) taglibs.next();
        if (tracker.getPrefix().equals(prefix)) {
            CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
            List functions = doc.getFunctions();
            for (Iterator it = functions.iterator(); it.hasNext(); ) {
                TLDFunction function = (TLDFunction) it.next();
                if (function.getName().equals(functionName)) {
                    String javaFuncName = getFunctionNameFromSignature(function.getSignature());
                    if (javaFuncName == null)
                        javaFuncName = functionName;
                    // $NON-NLS-1$
                    return function.getClassName() + "." + javaFuncName;
                }
            }
        }
    }
    return null;
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TLDFunction(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction) CMDocumentImpl(org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)

Example 14 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager in project webtools.sourceediting by eclipse.

the class JSPTranslator method handleTaglib.

/*
	 * This method should ideally only be called once per run through
	 * JSPTranslator This is intended for use by inner helper classes that
	 * need to add block markers to their own parsers. This method only adds
	 * markers that came from <@taglib> directives, (not <@include>), since
	 * include file taglibs are handled on the fly when they are encountered. *
	 * @param regions
	 */
private void handleTaglib(String prefix) {
    // get/create TLDCMDocument
    TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(fStructuredDocument);
    if (mgr != null) {
        // get trackers for the CMDocuments enabled at this offset
        List trackers = mgr.getCMDocumentTrackers(getCurrentNode().getEnd());
        Iterator it = trackers.iterator();
        CMDocumentTracker tracker = null;
        while (it.hasNext()) {
            tracker = (CMDocumentTracker) it.next();
            // $NON-NLS-1$
            addBlockMarkers(prefix + ":", tracker.getDocument());
        }
    }
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMDocumentTracker(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocumentTracker) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList)

Example 15 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager in project webtools.sourceediting by eclipse.

the class JSPTranslator method handleTaglib.

/*
	 * This method should ideally only be called once per run through
	 * JSPTranslator This is intended for use by inner helper classes that
	 * need to add block markers to their own parsers. This method only adds
	 * markers that came from <@taglib> directives, (not <@include>), since
	 * include file taglibs are handled on the fly when they are encountered. *
	 * @param regions
	 * 
	 * @deprecated - does not properly handle prefixes
	 */
protected void handleTaglib() {
    // get/create TLDCMDocument
    TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(fStructuredDocument);
    if (mgr != null) {
        List trackers = mgr.getCMDocumentTrackers(getCurrentNode().getEnd());
        Iterator it = trackers.iterator();
        CMDocumentTracker tracker = null;
        Iterator taglibRegions = null;
        IStructuredDocumentRegion sdRegion = null;
        ITextRegion r = null;
        while (it.hasNext()) {
            tracker = (CMDocumentTracker) it.next();
            sdRegion = tracker.getStructuredDocumentRegion();
            // this check is to be safer
            if (sdRegion != null && !sdRegion.isDeleted()) {
                taglibRegions = sdRegion.getRegions().iterator();
                while (!sdRegion.isDeleted() && taglibRegions.hasNext()) {
                    r = (ITextRegion) taglibRegions.next();
                    if (r.getType().equals(DOMJSPRegionContexts.JSP_DIRECTIVE_NAME)) {
                        String text = sdRegion.getText(r);
                        if (JSP12TLDNames.TAGLIB.equals(text) || JSP12Namespace.ElementName.DIRECTIVE_TAGLIB.equals(text)) {
                            addBlockMarkers(tracker.getDocument());
                        }
                    }
                }
            }
        }
    }
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CMDocumentTracker(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocumentTracker) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList)

Aggregations

TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)15 List (java.util.List)14 ArrayList (java.util.ArrayList)10 Iterator (java.util.Iterator)9 TaglibTracker (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker)8 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)8 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)6 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)6 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)5 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)4 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)4 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)4 NodeList (org.w3c.dom.NodeList)4 CMDocumentImpl (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl)3 TLDFunction (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction)3 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)3 CMNodeWrapper (org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 Path (org.eclipse.core.runtime.Path)2