use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method translatePageDirectiveAttributes.
/**
* takes an iterator of the attributes of a page directive and the
* directive itself. The iterator is used in case it can be optimized, but
* the documentRegion is still required to ensure that the values are
* extracted from the correct text.
*/
protected void translatePageDirectiveAttributes(Iterator regions, IStructuredDocumentRegion documentRegion) {
ITextRegion r = null;
String attrName, attrValue;
// 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 = documentRegion.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(documentRegion.getText(r));
}
// has equals, but no value?
}
setDirectiveAttribute(attrName, attrValue);
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method isEmptyTag.
private boolean isEmptyTag(ITextRegionCollection customTag, int index) {
String type = null;
// custom tag is embedded
ITextRegionList regions = customTag.getRegions();
ITextRegion nextRegion = regions.get(index);
int size = customTag.getNumberOfRegions();
type = nextRegion.getType();
while (index <= size && !(DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(type) || DOMRegionContext.XML_TAG_NAME.equals(type) || DOMRegionContext.XML_TAG_CLOSE.equals(type))) {
nextRegion = regions.get(++index);
type = nextRegion.getType();
}
return DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(type);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class JSPTranslator method translateXMLContent.
/**
* This currently only detects EL content and translates it,
* but if other cases arise later then they could be added in here
*
* @param embeddedContainer the container that may contain EL
*/
protected void translateXMLContent(ITextRegionContainer embeddedContainer) {
ITextRegionList embeddedRegions = embeddedContainer.getRegions();
int length = embeddedRegions.size();
for (int i = 0; i < length; i++) {
ITextRegion delim = embeddedRegions.get(i);
String type = delim.getType();
// check next region to see if it's EL content
if (i + 1 < length) {
if ((type == DOMJSPRegionContexts.JSP_EL_OPEN || type == DOMJSPRegionContexts.JSP_VBL_OPEN)) {
ITextRegion region = null;
int start = delim.getEnd();
while (++i < length) {
region = embeddedRegions.get(i);
if (region == null || !isELType(region.getType()))
break;
}
fLastJSPType = EXPRESSION;
String elText = embeddedContainer.getFullText().substring(start, (region != null ? region.getStart() : embeddedContainer.getLength() - 1));
translateEL(elText, embeddedContainer.getText(delim), fCurrentNode, embeddedContainer.getEndOffset(delim), elText.length());
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class XMLJSPRegionHelper method getAttributeValue.
/*
* convenience method to get an attribute value from attribute name
*/
protected String getAttributeValue(String attrName, IStructuredDocumentRegion sdRegion) {
String sdRegionText = fTextToParse.substring(sdRegion.getStartOffset(), sdRegion.getEndOffset());
// $NON-NLS-1$
String textRegionText, attrValue = "";
Iterator it = sdRegion.getRegions().iterator();
ITextRegion nameRegion, valueRegion = null;
while (it.hasNext()) {
nameRegion = (ITextRegion) it.next();
if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
textRegionText = sdRegionText.substring(nameRegion.getStart(), nameRegion.getTextEnd());
if (textRegionText.equalsIgnoreCase(attrName)) {
while (it.hasNext()) {
valueRegion = (ITextRegion) it.next();
if (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrValue = sdRegionText.substring(valueRegion.getStart(), valueRegion.getEnd());
// inner
break;
}
}
// outer
break;
}
}
}
return StringUtils.stripQuotes(attrValue);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class XMLJSPRegionHelper method hasIllegalContent.
private int hasIllegalContent(IStructuredDocumentRegion sdRegion) {
ITextRegionList list = sdRegion.getRegions();
for (int i = 0; i < list.size(); i++) {
ITextRegion region = list.get(i);
String type = region.getType();
if (type == DOMRegionContext.UNDEFINED)
return i;
if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_EMPTY_TAG_CLOSE || type == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE)
return -1;
}
return -1;
}
Aggregations