Search in sources :

Example 6 with RegionIterator

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

the class CMGroupNode method getConnector.

/**
 * Get the value of connector.
 *
 * @return value of connector.
 */
public char getConnector() {
    Object[] children = getChildren();
    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());
        // stream.setFirstRegion(childA.getLastRegion());
        // stream.setLastRegion(childB.getFirstRegion());
        // Iterator iter = stream.iterator();
        // skip the first region which is the last region of childA
        // do we need this now ?
        // iter.next();
        ITextRegion currentRegion = null;
        while (iter.hasNext() && currentRegion != childB.getStartRegion()) {
            currentRegion = iter.next();
            if (currentRegion.getType() == DTDRegionTypes.CONNECTOR) {
                connector = getStructuredDTDDocumentRegion().getText(currentRegion).charAt(0);
                return connector;
            }
        }
    }
    return connector;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 7 with RegionIterator

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

the class Entity method setNotationName.

public void setNotationName(Object requestor, String newNotation) {
    if (!getNotationName().equals(newNotation)) {
        if (!newNotation.equals("")) {
            // $NON-NLS-1$
            // 
            ITextRegion ndataRegion = getNextRegion(iterator(), DTDRegionTypes.NDATA_VALUE);
            if (ndataRegion != null) {
                replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(ndataRegion), ndataRegion.getLength(), newNotation);
            } else {
                // time to create one
                int startOffset = 0;
                // $NON-NLS-1$
                String string = "";
                RegionIterator iter = iterator();
                ITextRegion ndataKeyword = getNextRegion(iter, DTDRegionTypes.NDATA_KEYWORD);
                if (ndataKeyword == null) {
                    // we'll need to create one after the last quoted
                    // literal
                    // Reset iterator
                    // $NON-NLS-1$
                    string += " NDATA ";
                    iter = iterator();
                    ITextRegion lastQuotedLiteral = null;
                    while (iter.hasNext()) {
                        ITextRegion literal = getNextQuotedLiteral(iter);
                        if (literal != null) {
                            lastQuotedLiteral = literal;
                        }
                    }
                    if (lastQuotedLiteral != null) {
                        startOffset = getStructuredDTDDocumentRegion().getEndOffset(lastQuotedLiteral);
                    } else {
                        // created after the system or public keyword
                        ITextRegion keyword = getPublicKeywordRegion(iterator());
                        if (keyword == null) {
                            keyword = getSystemKeywordRegion(iterator());
                        }
                        // we shouldn't be null here since we check if we
                        // were external already
                        startOffset = getStructuredDTDDocumentRegion().getEndOffset(keyword);
                    }
                } else {
                    startOffset = getStructuredDTDDocumentRegion().getEndOffset(ndataKeyword);
                }
                replaceText(requestor, startOffset, 0, string + newNotation);
            }
        } else {
            // need to remove the ndata stuff
            removeNData(requestor);
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 8 with RegionIterator

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

the class Entity method setExternalEntity.

/**
 * Set the value of externalEntity.
 *
 * @param v
 *            Value to assign to externalEntity.
 */
public void setExternalEntity(boolean isExternalEntity) {
    if (isExternalEntity() != isExternalEntity) {
        // externalEntity = v;
        beginRecording(this, isExternalEntity ? setExternalEntity : setInternalEntity);
        if (isExternalEntity) {
            // we need to get rid of the value literal
            ITextRegion quote = getNextRegion(iterator(), DTDRegionTypes.SINGLEQUOTED_LITERAL);
            if (quote == null) {
                quote = getNextRegion(iterator(), DTDRegionTypes.DOUBLEQUOTED_LITERAL);
            }
            if (quote != null) {
                // $NON-NLS-1$
                replaceText(this, getStructuredDTDDocumentRegion().getStartOffset(quote), quote.getLength(), "");
            }
            // $NON-NLS-1$
            setSystemID("");
        } else {
            // we need to get rid of text between end of name region and
            // the last double quoted literal
            RegionIterator iter = iterator();
            ITextRegion keyword = getSystemKeywordRegion(iter);
            int startOffset = 0;
            int length = 0;
            if (keyword == null) {
                // reset the iterator
                iter = iterator();
                keyword = getPublicKeywordRegion(iter);
            }
            if (keyword != null) {
                startOffset = getStructuredDTDDocumentRegion().getStartOffset(keyword);
                // start with a length just equal to the keyword for now
                length = keyword.getLength();
            } else {
                // reset the iterator since we didn't find the keyword
                iter = iterator();
                // just go from after the name
                startOffset = getStructuredDTDDocumentRegion().getEndOffset(getNameRegion());
            }
            // now that we have the start, look for the end
            ITextRegion lastRegion = null;
            if (lastRegion == null) {
                // then look for last quoted literal
                while (iter.hasNext()) {
                    ITextRegion literal = getNextQuotedLiteral(iter);
                    if (literal != null) {
                        lastRegion = literal;
                    }
                }
            }
            if (lastRegion != null) {
                length = getStructuredDTDDocumentRegion().getEndOffset(lastRegion) - startOffset;
            }
            // $NON-NLS-1$
            replaceText(this, startOffset, length, "\"\"");
            removeNData(this);
        }
        endRecording(this);
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 9 with RegionIterator

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

the class ExternalNode method getSystemValueRegion.

public ITextRegion getSystemValueRegion() {
    RegionIterator iter = iterator();
    ITextRegion systemKeyword = getSystemKeywordRegion(iter);
    if (systemKeyword != null && iter.hasNext()) {
        ITextRegion quotedLiteral = getNextQuotedLiteral(iter);
        if (quotedLiteral != null) {
            return quotedLiteral;
        }
    } else {
        // try and see if there is a second quoted literal after a public
        // keyword
        iter = iterator();
        ITextRegion publicKeyword = getPublicKeywordRegion(iter);
        if (publicKeyword != null && iter.hasNext()) {
            ITextRegion quotedLiteral = getNextQuotedLiteral(iter);
            if (quotedLiteral != null && iter.hasNext()) {
                // now get the second quoted literal
                quotedLiteral = getNextQuotedLiteral(iter);
                if (quotedLiteral != null) {
                    // got it!
                    return quotedLiteral;
                }
            }
        }
    }
    return null;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 10 with RegionIterator

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

the class NamedTopLevelNode method getNameRegion.

public ITextRegion getNameRegion() {
    // name region is located after the whitespace (which is after
    // the elementtag
    RegionIterator iter = iterator();
    getNextRegion(iter, tagStartType);
    if (!iter.hasNext()) {
        return null;
    }
    ITextRegion region = iter.next();
    if (!region.getType().equals(DTDRegionTypes.WHITESPACE)) {
        return null;
    }
    if (!iter.hasNext()) {
        return null;
    }
    region = iter.next();
    if (region.getType().equals(DTDRegionTypes.NAME)) {
        return region;
    }
    // whitespace again
    if (tagStartType == DTDRegionTypes.ENTITY_TAG && region.getType().equals(DTDRegionTypes.PERCENT) && iter.hasNext()) {
        region = iter.next();
        if (!region.getType().equals(DTDRegionTypes.WHITESPACE)) {
            return null;
        }
        if (!iter.hasNext()) {
            return null;
        }
        region = iter.next();
        if (region.getType().equals(DTDRegionTypes.NAME)) {
            return region;
        }
    }
    return null;
}
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