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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations