use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker in project webtools.sourceediting by eclipse.
the class TaglibHyperlinkDetector method detectHyperlinks.
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
IHyperlink hyperlink = null;
if (textViewer != null && region != null) {
IDocument doc = textViewer.getDocument();
if (doc != null) {
try {
// check if jsp tag/directive first
ITypedRegion partition = TextUtilities.getPartition(doc, IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, region.getOffset(), false);
if (partition != null && partition.getType() == IJSPPartitions.JSP_DIRECTIVE) {
IStructuredModel sModel = null;
try {
sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc);
// check if jsp taglib directive
Node currentNode = getCurrentNode(sModel, region.getOffset());
if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) {
String baseLocationForTaglib = getBaseLocationForTaglib(doc);
if (baseLocationForTaglib != null && JSP11Namespace.ElementName.DIRECTIVE_TAGLIB.equalsIgnoreCase(currentNode.getNodeName())) {
/**
* The taglib directive itself
*/
// get the uri attribute
Attr taglibURINode = ((Element) currentNode).getAttributeNode(JSP11Namespace.ATTR_NAME_URI);
if (taglibURINode != null) {
ITaglibRecord reference = TaglibIndex.resolve(baseLocationForTaglib, taglibURINode.getValue(), false);
// there's nothing to link to
if (reference != null) {
// handle taglibs
switch(reference.getRecordType()) {
case (ITaglibRecord.TLD):
{
ITLDRecord record = (ITLDRecord) reference;
String uriString = record.getPath().toString();
IRegion hyperlinkRegion = getHyperlinkRegion(taglibURINode, region);
if (hyperlinkRegion != null) {
hyperlink = createHyperlink(uriString, hyperlinkRegion, doc, null);
}
}
break;
case (ITaglibRecord.JAR):
case (ITaglibRecord.URL):
{
IRegion hyperlinkRegion = getHyperlinkRegion(taglibURINode, region);
if (hyperlinkRegion != null) {
hyperlink = new TaglibJarUriHyperlink(hyperlinkRegion, reference);
}
}
}
}
}
} else if (baseLocationForTaglib != null && JSP12Namespace.ElementName.ROOT.equalsIgnoreCase(currentNode.getNodeName())) {
/**
* The jsp:root element
*/
NamedNodeMap attrs = currentNode.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
if (attr.getNodeName().startsWith(XMLNS)) {
String uri = StringUtils.strip(attr.getNodeValue());
if (uri.startsWith(URN_TLD)) {
uri = uri.substring(URN_TLD.length());
}
ITaglibRecord reference = TaglibIndex.resolve(baseLocationForTaglib, uri, false);
// there's nothing to link to
if (reference != null) {
// handle taglibs
switch(reference.getRecordType()) {
case (ITaglibRecord.TLD):
{
ITLDRecord record = (ITLDRecord) reference;
String uriString = record.getPath().toString();
IRegion hyperlinkRegion = getHyperlinkRegion(attr, region);
if (hyperlinkRegion != null) {
hyperlink = createHyperlink(uriString, hyperlinkRegion, doc, null);
}
}
break;
case (ITaglibRecord.JAR):
case (ITaglibRecord.URL):
{
IRegion hyperlinkRegion = getHyperlinkRegion(attr, region);
if (hyperlinkRegion != null) {
hyperlink = new TaglibJarUriHyperlink(hyperlinkRegion, reference);
}
}
}
}
}
}
} else {
/**
* Hyperlink custom tag to its TLD or tag file
*/
TLDCMDocumentManager documentManager = TaglibController.getTLDCMDocumentManager(doc);
if (documentManager != null) {
List documentTrackers = documentManager.getCMDocumentTrackers(currentNode.getPrefix(), region.getOffset());
for (int i = 0; i < documentTrackers.size(); i++) {
TaglibTracker tracker = (TaglibTracker) documentTrackers.get(i);
CMElementDeclaration decl = (CMElementDeclaration) tracker.getElements().getNamedItem(currentNode.getNodeName());
if (decl != null) {
decl = (CMElementDeclaration) ((CMNodeWrapper) decl).getOriginNode();
if (decl instanceof CMElementDeclarationImpl) {
String base = ((CMElementDeclarationImpl) decl).getLocationString();
IRegion hyperlinkRegion = getHyperlinkRegion(currentNode, region);
if (hyperlinkRegion != null) {
hyperlink = createHyperlink(base, hyperlinkRegion, doc, currentNode);
}
}
}
}
}
}
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
} catch (BadLocationException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
}
}
}
if (hyperlink != null)
return new IHyperlink[] { hyperlink };
return null;
}
use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker 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;
}
use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker 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;
}
Aggregations