use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class TaglibHyperlinkDetector method getNameRegion.
private IRegion getNameRegion(ITextRegionCollection containerRegion) {
ITextRegionList regions = containerRegion.getRegions();
ITextRegion nameRegion = null;
for (int i = 0; i < regions.size(); i++) {
ITextRegion r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
nameRegion = r;
break;
}
}
if (nameRegion != null)
return new Region(containerRegion.getStartOffset(nameRegion), nameRegion.getTextLength());
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class DTDRegionParser method addNewNodes.
private IStructuredDocumentRegion addNewNodes(IStructuredDocumentRegion lastNode, Vector regions) {
IStructuredDocumentRegion leadingSpaceNode = null;
IStructuredDocumentRegion contentNode = null;
IStructuredDocumentRegion trailingSpaceNode = null;
LinkedList nodeSeeds = new LinkedList();
int nRegions = regions.size();
int leadingSpaceEnd = -1;
int trailingSpaceBegin = nRegions;
// find leading space
nodeSeeds.clear();
for (int i = 0; i < nRegions; i++) {
ITextRegion region = (ITextRegion) regions.get(i);
String type = region.getType();
if (isBlankRegion(type)) {
leadingSpaceEnd = i;
nodeSeeds.addLast(region);
} else {
break;
}
}
if (!nodeSeeds.isEmpty()) {
leadingSpaceNode = createNode(nodeSeeds);
if (lastNode != null) {
lastNode.setNext(leadingSpaceNode);
leadingSpaceNode.setPrevious(lastNode);
}
lastNode = leadingSpaceNode;
}
// find trailing space
if (leadingSpaceEnd < nRegions - 1) {
nodeSeeds.clear();
for (int i = nRegions - 1; 0 <= i; i--) {
ITextRegion region = (ITextRegion) regions.get(i);
String type = ((ITextRegion) regions.get(i)).getType();
if (isBlankRegion(type)) {
trailingSpaceBegin = i;
nodeSeeds.addFirst(region);
} else {
break;
}
}
if (!nodeSeeds.isEmpty()) {
trailingSpaceNode = createNode(nodeSeeds);
}
nodeSeeds.clear();
for (int i = leadingSpaceEnd + 1; i < trailingSpaceBegin; i++) {
nodeSeeds.addLast(regions.get(i));
}
if (!nodeSeeds.isEmpty()) {
contentNode = createNode(nodeSeeds);
if (lastNode != null) {
lastNode.setNext(contentNode);
contentNode.setPrevious(lastNode);
}
lastNode = contentNode;
}
if (trailingSpaceNode != null) {
lastNode.setNext(trailingSpaceNode);
trailingSpaceNode.setPrevious(lastNode);
lastNode = trailingSpaceNode;
}
}
return lastNode;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class ExternalNode method getPublicValueRegion.
public ITextRegion getPublicValueRegion() {
RegionIterator iter = iterator();
ITextRegion publicKeyword = getPublicKeywordRegion(iter);
if (publicKeyword != null && iter.hasNext()) {
ITextRegion quotedLiteral = getNextQuotedLiteral(iter);
if (quotedLiteral != null) {
return quotedLiteral;
}
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class ExternalNode method setPublicID.
/**
* Set the value of publicID.
*
* @param v
* Value to assign to publicID.
*/
public void setPublicID(Object requestor, String v) {
if (!v.equals(publicID)) {
publicID = v;
ITextRegion publicValue = getPublicValueRegion();
ITextRegion publicKeyword = getPublicKeywordRegion(iterator());
ITextRegion systemKeyword = getSystemKeywordRegion(iterator());
ITextRegion systemValue = getSystemValueRegion();
if (v.equals("")) {
// $NON-NLS-1$
if (publicKeyword != null) {
// time to get rid of the public keyword and value
// and replace it with the system one
int startOffset = getStructuredDTDDocumentRegion().getStartOffset(publicKeyword);
// $NON-NLS-1$
String newString = "SYSTEM";
if (systemValue == null) {
// $NON-NLS-1$
newString += " \"\"";
}
replaceText(requestor, startOffset, getStructuredDTDDocumentRegion().getEndOffset(publicValue) - startOffset, newString);
}
} else {
// here were setting a non empty value
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String quoteChar = v.indexOf("\"") == -1 ? "\"" : "'";
if (publicValue != null) {
replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(publicValue), publicValue.getLength(), quoteChar + publicID + quoteChar);
} else {
// time to create stuff
if (publicKeyword != null) {
// then just put our new value after the keyword
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(publicKeyword), 0, " " + quoteChar + v + quoteChar);
} else {
// we need the public keyword as well
if (systemKeyword != null) {
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(systemKeyword), systemKeyword.getLength(), "PUBLIC " + quoteChar + v + quoteChar);
} else {
ITextRegion nameRegion = getNameRegion();
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(nameRegion), 0, " PUBLIC " + quoteChar + v + quoteChar);
}
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class ExternalNode method setSystemID.
/**
* Set the value of systemID.
*
* @param v
* Value to assign to systemID.
*/
public void setSystemID(Object requestor, String v) {
if (!v.equals(systemID) || (getPublicKeywordRegion(iterator()) == null && getSystemKeywordRegion(iterator()) == null)) {
systemID = v;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String quoteChar = v.indexOf("\"") == -1 ? "\"" : "'";
ITextRegion systemValue = getSystemValueRegion();
if (systemValue != null) {
replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(systemValue), systemValue.getLength(), quoteChar + systemID + quoteChar);
} else {
ITextRegion systemKeyword = getSystemKeywordRegion(iterator());
// time to create stuff
if (systemKeyword != null) {
// then just put our new value after the keyword
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(systemKeyword), 0, " " + quoteChar + v + quoteChar);
} else {
// see if we have a public keyword
ITextRegion publicKeyword = getPublicKeywordRegion(iterator());
if (publicKeyword == null) {
ITextRegion nameRegion = getNameRegion();
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(nameRegion), 0, " SYSTEM " + quoteChar + v + quoteChar);
} else {
// put it after the public value region
ITextRegion publicValueRegion = getPublicValueRegion();
// $NON-NLS-1$
replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(publicValueRegion), 0, " " + quoteChar + v + quoteChar);
}
}
}
}
}
Aggregations