Search in sources :

Example 91 with ITextRegion

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IRegion(org.eclipse.jface.text.IRegion) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Example 92 with ITextRegion

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;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) LinkedList(java.util.LinkedList)

Example 93 with ITextRegion

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;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.dtd.core.internal.text.RegionIterator)

Example 94 with ITextRegion

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);
                    }
                }
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 95 with ITextRegion

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);
                }
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)447 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)179 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)174 Iterator (java.util.Iterator)75 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)58 ArrayList (java.util.ArrayList)40 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)39 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)35 List (java.util.List)33 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)31 BadLocationException (org.eclipse.jface.text.BadLocationException)30 RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)19 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)16 Node (org.w3c.dom.Node)16 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)15 IOException (java.io.IOException)13 IRegion (org.eclipse.jface.text.IRegion)13 StyleRange (org.eclipse.swt.custom.StyleRange)13