use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method appendUseBeanToBuffer.
/**
* temp fix for 282295 until better mapping is in place
*
* @param newText
* @param jspReferenceRegion
*/
private void appendUseBeanToBuffer(String newText, ITextRegionCollection jspReferenceRegion, boolean isIndirect) throws Exception {
// java string looks like this (tokenized)
// Type id = new Classname();\n
// 0 1 2 3 4
// or
// Type id = null;\n // if there is no classname
// 0 1 2 3
// ----------------------
// calculate java ranges
// ----------------------
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(newText, " ", false);
int i = 0;
String[] parsedJava = new String[st.countTokens()];
while (st.hasMoreTokens()) parsedJava[i++] = st.nextToken();
// $NON-NLS-1$
String type = parsedJava[0] != null ? parsedJava[0] : "";
// $NON-NLS-1$
String id = parsedJava[1] != null ? parsedJava[1] : "";
// $NON-NLS-1$
String className = parsedJava.length > 4 ? parsedJava[4] : "";
Position javaTypeRange = new Position(fOffsetInUserCode, type.length());
Position javaIdRange = new Position(fOffsetInUserCode + type.length() + 1, id.length());
Position javaClassRange = new Position(fOffsetInUserCode + type.length() + 1 + id.length() + 7, 0);
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=212242 - Check for
* the existence of '(' first.
*/
int parenPos = -1;
if (className.length() >= 4 && (parenPos = className.indexOf('(')) >= 0) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86132
int classNameLength = className.substring(0, parenPos).length();
javaClassRange = new Position(fOffsetInUserCode + type.length() + 1 + id.length() + 7, classNameLength);
}
// ---------------------
// calculate jsp ranges
// ---------------------
ITextRegionList regions = jspReferenceRegion.getRegions();
ITextRegion r = null;
// $NON-NLS-1$ //$NON-NLS-2$
String attrName = "", attrValue = "";
int quoteOffset = 0;
Position jspTypeRange = null;
Position jspIdRange = null;
Position jspClassRange = null;
for (int j = 0; j < regions.size(); j++) {
r = regions.get(j);
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
attrName = jspReferenceRegion.getText(r);
if (regions.size() > j + 2 && regions.get(j + 2).getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
// get attr value
r = regions.get(j + 2);
attrValue = jspReferenceRegion.getText(r);
// may have quotes
// $NON-NLS-1$ //$NON-NLS-2$
quoteOffset = (attrValue.startsWith("\"") || attrValue.startsWith("'")) ? 1 : 0;
if (// $NON-NLS-1$
attrName.equals("type"))
jspTypeRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
else if (// $NON-NLS-1$
attrName.equals("id"))
jspIdRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
else if (// $NON-NLS-1$
attrName.equals("class"))
jspClassRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
}
}
}
// put ranges in java -> jsp range map
if (!type.equals("") && jspTypeRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaTypeRange, jspTypeRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaTypeRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaTypeRange, jspTypeRange);
}
if (!id.equals("") && jspIdRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaIdRange, jspIdRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaIdRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaIdRange, jspTypeRange);
}
if (!className.equals("") && jspClassRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaClassRange, jspClassRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaClassRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaClassRange, jspTypeRange);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method isUsebeanTag.
/**
* @param jspReferenceRegion
* @return
*/
private boolean isUsebeanTag(ITextRegionCollection jspReferenceRegion) {
ITextRegionList regions = jspReferenceRegion.getRegions();
ITextRegion r = null;
boolean isUseBean = false;
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
// and saves the expensive getText.equals call
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
if (r.getTextLength() == 11 && jspReferenceRegion.getText(r).equals("jsp:useBean")) {
// $NON-NLS-1$
isUseBean = true;
}
// break no matter what if you hit tagname
break;
}
}
return isUseBean;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method translateAttributeDirectiveAttributes.
private void translateAttributeDirectiveAttributes(Iterator regions) {
ITextRegion r = null;
String attrName, attrValue;
// $NON-NLS-1$ // the default class...
String varType = "java.lang.String";
String varName = null;
// $NON-NLS-1$
String description = "";
boolean isFragment = false;
// iterate all attributes
while (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() != DOMJSPRegionContexts.JSP_CLOSE) {
attrName = attrValue = null;
if (r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
attrName = getCurrentNode().getText(r).trim();
if (attrName.length() > 0) {
if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrValue = StringUtils.strip(getCurrentNode().getText(r));
}
// has equals, but no value?
}
if (attrName.equals(JSP11Namespace.ATTR_NAME_TYPE)) {
varType = attrValue;
} else if (attrName.equals(JSP20Namespace.ATTR_NAME_FRAGMENT)) {
isFragment = Boolean.valueOf(attrValue).booleanValue();
} else if (attrName.equals(JSP11Namespace.ATTR_NAME_NAME)) {
varName = attrValue;
} else if (attrName.equals(JSP20Namespace.ATTR_NAME_DESCRIPTION)) {
description = attrValue;
}
}
}
}
if (varName != null) {
if (isFragment) {
// 2.0:JSP.8.5.2
// $NON-NLS-1$
varType = "javax.servlet.jsp.tagext.JspFragment";
}
// $NON-NLS-1$
String declaration = new TaglibVariable(varType, varName, "", description).getDeclarationString(true, fContext, TaglibVariable.M_PRIVATE);
appendToBuffer(declaration, fUserDeclarations, false, fCurrentNode);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method checkAllAttributeValueContainers.
/**
* translates embedded containers for ALL attribute values
*
* @param regions
*/
private void checkAllAttributeValueContainers(ITextRegionCollection container, Iterator regions) {
// tag name is not jsp
// handle embedded jsp attributes...
ITextRegion embedded = null;
// Iterator attrRegions = null;
// ITextRegion attrChunk = null;
ITextRegion prevRegion = null;
while (regions.hasNext()) {
embedded = (ITextRegion) regions.next();
if (embedded.getType() == DOMRegionContext.XML_TAG_NAME || embedded.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
String fullTagName = container.getText(embedded);
if (fullTagName.indexOf(':') > -1 && !fullTagName.startsWith(JSP_PREFIX)) {
if (prevRegion != null)
// it may be a custom tag
addCustomTaglibVariables(fullTagName, container, prevRegion, -1);
}
} else if (embedded instanceof ITextRegionContainer) {
// parse out container
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=130606
// fix exponential iteration problem w/ embedded expressions
translateEmbeddedJSPInAttribute((ITextRegionContainer) embedded);
// attrRegions = ((ITextRegionContainer)
// embedded).getRegions().iterator();
// while (attrRegions.hasNext()) {
// attrChunk = (ITextRegion) attrRegions.next();
// String type = attrChunk.getType();
// // embedded JSP in attribute support only want to
// // translate one time per
// // embedded region so we only translate on the JSP open
// // tags (not content)
// if (type == DOMJSPRegionContexts.JSP_EXPRESSION_OPEN ||
// type ==
// DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN || type ==
// DOMJSPRegionContexts.JSP_DECLARATION_OPEN || type ==
// DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN || type ==
// DOMJSPRegionContexts.JSP_EL_OPEN) {
// // now call jsptranslate
// translateEmbeddedJSPInAttribute((ITextRegionContainer)
// embedded);
// break;
// }
// }
}
prevRegion = embedded;
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method translateXMLNode.
/**
* translates the various XMLJSP type nodes
*
* @param regions
* the regions of the XMLNode
*/
protected void translateXMLNode(ITextRegionCollection container, Iterator regions) {
// contents must be valid XHTML, translate escaped CDATA into what it
// really is...
ITextRegion r = null;
if (regions.hasNext()) {
r = (ITextRegion) regions.next();
// <jsp:directive.xxx > comes in as this
if (r.getType() == DOMRegionContext.XML_TAG_NAME || r.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
String fullTagName = container.getText(r);
if (fullTagName.indexOf(':') > -1 && !fullTagName.startsWith(JSP_PREFIX)) {
// it
addTaglibVariables(fullTagName, container, -1);
// may
// be a
// custom
// tag
}
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(fullTagName, ":.", false);
if (// $NON-NLS-1$
st.hasMoreTokens() && st.nextToken().equals("jsp")) {
if (st.hasMoreTokens()) {
String jspTagName = st.nextToken();
if (// $NON-NLS-1$
jspTagName.equals("scriptlet")) {
translateXMLJSPContent(SCRIPTLET);
} else if (// $NON-NLS-1$
jspTagName.equals("expression")) {
translateXMLJSPContent(EXPRESSION);
} else if (// $NON-NLS-1$
jspTagName.equals("declaration")) {
translateXMLJSPContent(DECLARATION);
} else if (// $NON-NLS-1$
jspTagName.equals("directive")) {
if (st.hasMoreTokens()) {
String directiveName = st.nextToken();
if (directiveName.equals("taglib")) {
// $NON-NLS-1$
while (r != null && regions.hasNext() && !r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
r = (ITextRegion) regions.next();
if (container.getText(r).equals(JSP11Namespace.ATTR_NAME_PREFIX)) {
String prefix = getAttributeValue(r, regions);
if (prefix != null) {
handleTaglib(prefix);
}
}
}
return;
} else if (directiveName.equals("include")) {
// $NON-NLS-1$
// $NON-NLS-1$
String fileLocation = "";
// include directive
while (r != null && regions.hasNext() && !r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
r = (ITextRegion) regions.next();
}
fileLocation = getAttributeValue(r, regions);
if (fileLocation != null)
handleIncludeFile(fileLocation);
} else if (directiveName.equals("page")) {
// setCurrentNode(getCurrentNode().getNext());
if (getCurrentNode() != null) {
// 'regions' contain the attrs
translatePageDirectiveAttributes(regions, getCurrentNode());
}
} else if (directiveName.equals("tag")) {
// $NON-NLS-1$
translatePageDirectiveAttributes(regions, getCurrentNode());
} else if (directiveName.equals("variable")) {
// $NON-NLS-1$
translateVariableDirectiveAttributes(regions);
}
}
} else if (jspTagName.equals("include")) {
// $NON-NLS-1$
// <jsp:include page="filename") />
// $NON-NLS-1$
checkAttributeValueContainer(regions, "page");
} else if (jspTagName.equals("forward")) {
// $NON-NLS-1$
// $NON-NLS-1$
checkAttributeValueContainer(regions, "page");
} else if (jspTagName.equals("param")) {
// $NON-NLS-1$
// $NON-NLS-1$
checkAttributeValueContainer(regions, "value");
} else if (jspTagName.equals("setProperty")) {
// $NON-NLS-1$
// $NON-NLS-1$
checkAttributeValueContainer(regions, "value");
} else if (// $NON-NLS-1$
jspTagName.equals("useBean")) {
// $NON-NLS-1$
checkAttributeValueContainer(regions, "name");
// advanceNextNode(); // get the content
if (getCurrentNode() != null) {
// 'regions'
translateUseBean(container);
}
}
}
} else {
checkAllAttributeValueContainers(container, regions);
}
}
}
}
Aggregations