use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.
the class CMGroupNode method resolveRegions.
public void resolveRegions() {
int nesting = 0;
// children.clear();
removeChildNodes();
DTDNode currentGroupNode = null;
CMBasicNode currentReferenceNode = null;
RegionIterator iter = iterator();
// we assume the first region is the '('
iter.next();
while (iter.hasNext() && nesting >= 0) {
ITextRegion currentRegion = iter.next();
if (nesting == 0) {
if (currentRegion.getType().equals(DTDRegionTypes.CONTENT_PCDATA)) {
currentGroupNode = currentReferenceNode = null;
DTDNode pcData = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
pcData.addRegion(currentRegion);
appendChild(pcData);
// children.add(pcData);
} else if (currentRegion.getType().equals(DTDRegionTypes.NAME)) {
// we have hit a new reference node. Make sure we reset
// the groupnode var so it doesn't collect more regions
currentGroupNode = null;
currentReferenceNode = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
currentReferenceNode.addRegion(currentRegion);
appendChild(currentReferenceNode);
// children.add(currentReferenceNode);
} else if (currentRegion.getType().equals(DTDRegionTypes.OCCUR_TYPE)) {
// are null
if (currentReferenceNode != null) {
// currentReferenceNode.setOccurrence(currentRegion.getText().toCharArray()[0]);
currentReferenceNode.addRegion(currentRegion);
currentReferenceNode = null;
}
} else if (currentRegion.getType().equals(DTDRegionTypes.CONNECTOR)) {
// note that if connector is already set and it is
// different from the current connector region, then we
// have an error!
// setConnector(currentRegion.getText().toCharArray()[0]);
} else if (currentRegion.getType().equals(DTDRegionTypes.LEFT_PAREN)) {
if (currentGroupNode == null) {
// we have hit a new group. Make sure we reset the
// referencenode var so it doesn't collect any more
// regions
currentReferenceNode = null;
currentGroupNode = new CMGroupNode(getDTDFile(), getStructuredDTDDocumentRegion());
appendChild(currentGroupNode);
// children.add(currentGroupNode);
}
}
}
if (currentRegion.getType().equals(DTDRegionTypes.LEFT_PAREN)) {
nesting++;
}
if (currentRegion.getType().equals(DTDRegionTypes.RIGHT_PAREN)) {
nesting--;
if (nesting == 0 && currentGroupNode != null) {
currentGroupNode.addRegion(currentRegion);
// so, add it to the groupnode
if (iter.hasNext()) {
ITextRegion nextRegion = iter.next();
if (nextRegion.getType().equals(DTDRegionTypes.OCCUR_TYPE)) {
currentGroupNode.addRegion(nextRegion);
} else {
// Otherwise, push it back as the next item to be
// retrieved by a future next() call
iter.previous();
}
}
currentGroupNode = null;
}
}
if (currentGroupNode != null) {
currentGroupNode.addRegion(currentRegion);
}
}
if (nesting < 0) {
// Look for an occurrence region
while (iter.hasNext()) {
ITextRegion currentRegion = iter.next();
if (currentRegion.getType().equals(DTDRegionTypes.OCCUR_TYPE)) {
// setOccurrence(currentRegion.getText().toCharArray()[0]);
}
}
// end of while ()
}
// for (org.w3c.dom.Node child = getFirstChild(); child != null; child
// = child.getNextSibling())
// {
// System.out.println("child found = " + child);
// }
Object[] children = getChildren();
for (int i = 0; i < children.length; i++) {
DTDNode currentNode = (DTDNode) children[i];
currentNode.resolveRegions();
}
// end of while ()
}
use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.
the class CMGroupNode method setConnector.
/**
* Set the value of connector.
*
* @param v
* Value to assign to connector.
*/
public void setConnector(char v) {
if (connector != v) {
connector = v;
// walk through our kids and see if there is a connector between
// each sibling. if not, create one and set the connector. if
// there is
// then just change the text of the connector
Object[] children = getChildren();
if (children.length <= 1) {
// there won't be any connector existing between the children
// just notify a change in the node and return;
getDTDFile().notifyNodeChanged(this);
return;
}
// $NON-NLS-1$
beginRecording(this, DTDCoreMessages._UI_LABEL_CM_GRP_NODE_CONNECTOR);
for (int i = 0; i < children.length - 1; i++) {
DTDNode childA = (DTDNode) children[i];
DTDNode childB = (DTDNode) children[i + 1];
// create a stream between the two siblings and walk it
// note that this stream includes the last region of the first
// sibling and the first region of the next sibling.
// both these should be ignored
RegionIterator iter = new RegionIterator(getStructuredDTDDocumentRegion(), childA.getEndOffset(), childB.getStartOffset());
// skip the first region which is the last region of childA
// do we still need this
// iter.next();
ITextRegion currentRegion = null;
boolean foundConnector = false;
while (iter.hasNext() && currentRegion != childB.getStartRegion()) {
currentRegion = iter.next();
if (currentRegion.getType() == DTDRegionTypes.CONNECTOR) {
foundConnector = true;
// Region oldRegion = currentRegion.createCopy();
// found a connector! on to the next sibling pair
// currentRegion.updateText(String.valueOf(v));
replaceText(this, getStructuredDTDDocumentRegion().getStartOffset(currentRegion), 1, String.valueOf(connector));
// changeStructuredDocument(oldRegion, currentRegion);
break;
}
}
if (!foundConnector) {
// if we're here, that means we need to insert a new
// connector region after childA
replaceText(this, childA.getEndOffset(), 0, String.valueOf(connector));
// DTDRegion connectorRegion = new
// DTDRegion(DTDRegionTypes.CONNECTOR,
// childA.getEndOffset(), 1);
// insertIntoStructuredDocument(connectorRegion);
}
}
endRecording(this);
}
}
use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.
the class Entity method setValue.
/**
* Set the value of value.
*
* @param v
* Value to assign to value.
*/
public void setValue(Object requestor, String v) {
if (!isExternalEntity()) {
if (!getValue().equals(v)) {
// then it makes sense to change the value
ITextRegion valueRegion = getNextQuotedLiteral(iterator());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String quoteChar = v.indexOf("\"") == -1 ? "\"" : "'";
if (valueRegion != null) {
replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(valueRegion), valueRegion.getLength(), quoteChar + v + quoteChar);
} else {
int startOffset = 0;
RegionIterator iter = iterator();
ITextRegion region = getNextRegion(iter, DTDRegionTypes.NAME);
if (region == null) {
// create it after the percent if there is one
region = getPercentRegion();
}
if (region == null) {
// if still null, then create it after the element tag
region = getStartTag(iterator());
}
if (region != null) {
startOffset = getStructuredDTDDocumentRegion().getEndOffset(region);
replaceText(requestor, startOffset, 0, quoteChar + v + quoteChar);
}
}
}
}
}
use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.
the class Entity method setParameterEntity.
/**
* Set the value of isParameterEntity.
*
* @param v
* Value to assign to isParameterEntity.
*/
public void setParameterEntity(boolean v) {
if (isParameterEntity() != v) {
beginRecording(this, v ? setParameterEntity : setGeneralEntity);
if (v) {
RegionIterator iter = iterator();
ITextRegion startTag = getNextRegion(iter, DTDRegionTypes.ENTITY_TAG);
int startOffset = 0, length = 0;
if (iter.hasNext()) {
ITextRegion region = iter.next();
startOffset = getStructuredDTDDocumentRegion().getStartOffset(region);
if (region.getType() == DTDRegionTypes.WHITESPACE && region.getLength() > 1) {
length = 1;
}
} else {
startOffset = getStructuredDTDDocumentRegion().getEndOffset(startTag);
}
// $NON-NLS-1$
replaceText(this, startOffset, length, " %");
// now get rid of any NData since it is only allowed if the
// entity is a general entity and not a parameter entity
removeNData(this);
} else {
// get rid of percent region
ITextRegion percentRegion = getPercentRegion();
// $NON-NLS-1$
replaceText(this, getStructuredDTDDocumentRegion().getStartOffset(percentRegion), percentRegion.getLength(), "");
}
endRecording(this);
}
}
use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.
the class ParameterEntityReference method getStartAndEndOffsetForText.
private void getStartAndEndOffsetForText(StartEndPair pair) {
RegionIterator iter = iterator();
ITextRegion commentStartTag = getStartTag(iter);
ITextRegion endCommentTag = getNextRegion(iter, DTDRegionTypes.COMMENT_END);
pair.endOffset = getStructuredDTDDocumentRegion().getEndOffset();
if (commentStartTag != null) {
pair.startOffset = getStructuredDTDDocumentRegion().getEndOffset(commentStartTag);
}
if (endCommentTag != null) {
pair.endOffset = getStructuredDTDDocumentRegion().getEndOffset(endCommentTag);
}
}
Aggregations