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