Search in sources :

Example 1 with TLDCMDocumentManager

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

the class JSPELCompletionProposalComputer method getFunctionProposals.

/**
 * <p>Get the EL function proposals, ex: ${fn:| }</p>
 * @param prefix
 * @param viewer
 * @param offset
 * @return
 */
private List getFunctionProposals(String prefix, ITextViewer 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 2 with TLDCMDocumentManager

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

the class TaglibController method setup.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension#setup(org.eclipse.jface.text.IDocument,
	 *      org.eclipse.core.runtime.IPath,
	 *      org.eclipse.core.filebuffers.LocationKind)
	 */
public void setup(IDocument document, IPath location, LocationKind locationKind) {
    // if we've already shutdown, just ignore
    if (isShutdown())
        return;
    // reference the shared instance's documents directly
    synchronized (_instance.fJSPdocuments) {
        _instance.fJSPdocuments.add(document);
    }
    DocumentInfo info = new DocumentInfo();
    info.document = (IStructuredDocument) document;
    // will be supplied later
    info.textFileBuffer = null;
    info.location = location;
    info.locationKind = locationKind;
    info.tldDocumentManager = new TLDCMDocumentManager();
    synchronized (_instance.fDocumentMap) {
        _instance.fDocumentMap.put(document, info);
    }
    info.tldDocumentManager.setSourceParser((XMLSourceParser) info.document.getParser());
    if (document instanceof BasicStructuredDocument && document.getLength() > 0) {
        ((BasicStructuredDocument) document).reparse(this);
    }
    TaglibIndex.addTaglibIndexListener(info);
}
Also used : TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)

Example 3 with TLDCMDocumentManager

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

the class JSPActionValidator method getTaglibPrefixes.

private HashSet getTaglibPrefixes(IStructuredDocument document) {
    if (fTaglibPrefixes.isEmpty()) {
        // add all reserved prefixes
        // $NON-NLS-1$
        fTaglibPrefixes.add("jsp");
        // $NON-NLS-1$
        fTaglibPrefixes.add("jspx");
        // $NON-NLS-1$
        fTaglibPrefixes.add("java");
        // $NON-NLS-1$
        fTaglibPrefixes.add("javax");
        // $NON-NLS-1$
        fTaglibPrefixes.add("servlet");
        // $NON-NLS-1$
        fTaglibPrefixes.add("sun");
        // $NON-NLS-1$
        fTaglibPrefixes.add("sunw");
        // add all taglib prefixes
        TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(document);
        if (manager != null) {
            List trackers = manager.getTaglibTrackers();
            for (Iterator it = trackers.iterator(); it.hasNext(); ) {
                TaglibTracker tracker = (TaglibTracker) it.next();
                if (tracker.getElements().getLength() == 0)
                    continue;
                String prefix = tracker.getPrefix();
                fTaglibPrefixes.add(prefix);
            }
        }
    }
    return fTaglibPrefixes;
}
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) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList)

Example 4 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager 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 5 with TLDCMDocumentManager

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager 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)

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