Search in sources :

Example 11 with RegionIterator

use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.

the class NamedTopLevelNode method setName.

public void setName(Object requestor, String name) {
    ITextRegion nameRegion = getNameRegion();
    if (nameRegion != null) {
        super.setName(requestor, name);
    } else {
        RegionIterator iter = iterator();
        ITextRegion elementTagRegion = getNextRegion(iter, tagStartType);
        int replaceLength = 0;
        if (iter.hasNext()) {
            ITextRegion region = iter.next();
            if (region.getType().equals(DTDRegionTypes.WHITESPACE)) {
                if (region.getLength() >= 2) {
                    // there are 2 spaces between 'ELEMENT' and the
                    // content
                    // Change replace length to 1 so that the new name and
                    // the content are separated by a single space
                    replaceLength = 1;
                }
            }
        }
        // beginRecording(requestor, "Name Change");
        // $NON-NLS-1$
        String newText = " " + name;
        replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(elementTagRegion), replaceLength, newText);
    // endRecording(requestor);
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 12 with RegionIterator

use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.

the class CMBasicNode method getOccurrenceRegion.

// returns the occurrencetoken, or the token where the occurrence token
// should appear after
public ITextRegion getOccurrenceRegion() {
    RegionIterator iter = iterator();
    skipPastName(iter);
    if (iter.hasNext()) {
        ITextRegion region = iter.next();
        if (region.getType() == DTDRegionTypes.OCCUR_TYPE) {
            return region;
        }
    }
    return getNameRegion();
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 13 with RegionIterator

use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.

the class DTDNode method getFullNodeText.

public String getFullNodeText() {
    String text = getNodeText();
    if (whitespace.size() > 0) {
        RegionIterator iter = new RegionIterator(whitespace);
        while (iter.hasNext()) {
            ITextRegion region = iter.next();
            text += getStructuredDTDDocumentRegion().getText(region);
        }
    }
    return text;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 14 with RegionIterator

use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.

the class DTDNode method getNodeText.

public String getNodeText() {
    StringBuffer sb = new StringBuffer();
    RegionIterator iter = iterator();
    while (iter.hasNext()) {
        ITextRegion region = iter.next();
        sb.append(getStructuredDTDDocumentRegion().getText(region));
    }
    return sb.toString();
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 15 with RegionIterator

use of org.eclipse.wst.dtd.core.internal.text.RegionIterator in project webtools.sourceediting by eclipse.

the class Element method resolveRegions.

public void resolveRegions() {
    // System.out.println("element node stream = " +
    // tokenStream.getString());
    fContentModel = null;
    removeChildNodes();
    RegionIterator iter = iterator();
    if (getNameRegion() != null) {
        // we skip past the name token is our name
        skipPastName(iter);
    }
    while (iter.hasNext()) {
        ITextRegion currentRegion = iter.next();
        if (fContentModel == null) {
            if (currentRegion.getType().equals(DTDRegionTypes.NAME)) {
                fContentModel = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
            } else if (currentRegion.getType().equals(DTDRegionTypes.CONTENT_PCDATA)) {
                fContentModel = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
            } else if (currentRegion.getType().equals(DTDRegionTypes.LEFT_PAREN)) {
                fContentModel = new CMGroupNode(getDTDFile(), getStructuredDTDDocumentRegion());
            }
        }
        if (fContentModel != null) {
            if (!currentRegion.getType().equals(DTDRegionTypes.END_TAG)) {
                // content model gets all regions except for the '>'
                fContentModel.addRegion(currentRegion);
            } else {
                // for the content model
                break;
            }
        }
    }
    if (fContentModel != null) {
        appendChild(fContentModel);
        // this is the root element content so set it true
        fContentModel.setRootElementContent(true);
        // now tell the content model to resolve it's regions
        fContentModel.resolveRegions();
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Aggregations

RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)22 ArrayList (java.util.ArrayList)1