Search in sources :

Example 56 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class DTDFile method nodesReplaced.

public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
    IStructuredDocumentRegionList oldNodes = event.getOldStructuredDocumentRegions();
    NodesEvent removedDTDNodes = new NodesEvent();
    for (int i = 0; i < oldNodes.getLength(); i++) {
        IStructuredDocumentRegion flatNode = oldNodes.item(i);
        for (Iterator iter = getNodes().iterator(); iter.hasNext(); ) {
            DTDNode node = (DTDNode) iter.next();
            if (node.getStructuredDTDDocumentRegion() == flatNode) {
                removedDTDNodes.add(node);
            }
        }
    }
    buildNodes(event.getNewStructuredDocumentRegions());
    if (removedDTDNodes.getNodes().size() > 0) {
        notifyNodesRemoved(removedDTDNodes);
        removeNodes(removedDTDNodes.getNodes());
    }
}
Also used : NodesEvent(org.eclipse.wst.dtd.core.internal.event.NodesEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) Iterator(java.util.Iterator)

Example 57 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class CSSDocumentCharsetDetector method getEncodingName.

public String getEncodingName(IStructuredDocument structuredDocument) {
    String result = null;
    // if the document is empty, then there will be no nodes,
    // so no need to continue.
    IStructuredDocumentRegionList nodes = structuredDocument.getRegionList();
    if (nodes.getLength() > 0) {
        IStructuredDocumentRegion node = null;
        // as expected.
        for (int i = 0; i < nodes.getLength(); i++) {
            node = nodes.item(i);
            if (getType(node) != CSSRegionContexts.CSS_S) {
                break;
            }
        }
        Iterator regions = node.getRegions().iterator();
        ITextRegion region = getNextRegionOfType(CSSRegionContexts.CSS_CHARSET, regions);
        if (region != null) {
            ITextRegion valueRegion = getNextRegionOfType(CSSRegionContexts.CSS_STRING, regions);
            if (valueRegion == null) {
                // if didn't find the region, its probably due to ill
                // formed input, such as
                // @charset "ISO-8859-6;
                // so we'll try again for "unknown" region.
                // If that fails, we'll give up?
                regions = node.getRegions().iterator();
                region = getNextRegionOfType(CSSRegionContexts.CSS_CHARSET, regions);
                if (region != null) {
                    valueRegion = getNextRegionOfType(CSSRegionContexts.CSS_UNKNOWN, regions);
                    if (valueRegion != null) {
                        result = node.getText(valueRegion);
                    }
                }
            } else {
                result = node.getText(valueRegion);
            }
            result = StringUtils.stripNonLetterDigits(result);
        }
    }
    return result;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Example 58 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class UnitTests method handleEvent.

protected void handleEvent(StructuredDocumentEvent structuredDocumentEvent) {
    eventResult = false;
    switch(eventCase) {
        case 1:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 2:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 3:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 4:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 5:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 6:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                                if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                                    // ok
                                    eventResult = true;
                                }
                }
                break;
            }
        case 7:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 8:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                            // if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 9:
        case 10:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 11:
        case 12:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 13:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size())
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 14:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 15:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    RegionChangedEvent regionChangedEvent = (RegionChangedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegion documentRegion = ((RegionChangedEvent) structuredDocumentEvent).getStructuredDocumentRegion();
                    if ("b ".equals(documentRegion.getFullText(regionChangedEvent.getRegion()))) {
                        // ok
                        eventResult = true;
                    }
                }
                break;
            }
        case 16:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (0 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 17:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 18:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 19:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 20:
        case 21:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 22:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 23:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 24:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 25:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 26:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP5
        case 27:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 28:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 29:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 30:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP6
        case 31:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 32:
            {
                // changed 2002, 9/12 to fit -- this is definitely a change
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    RegionsReplacedEvent regionsReplacedEvent = (RegionsReplacedEvent) structuredDocumentEvent;
                    if (1 == regionsReplacedEvent.getOldRegions().size()) {
                        ITextRegion region = regionsReplacedEvent.getOldRegions().get(0);
                        IStructuredDocumentRegion documentRegion = regionsReplacedEvent.getStructuredDocumentRegion();
                        String text = documentRegion.getText(region);
                        if ("<% aaa %>".equals(text)) {
                            // ok
                            eventResult = true;
                        }
                    }
                } else if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    StructuredDocumentRegionsReplacedEvent nodesReplacedEvent = (StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegionList regions = nodesReplacedEvent.getNewStructuredDocumentRegions();
                    if (1 == regions.getLength()) {
                        IStructuredDocumentRegion region = regions.item(0);
                        String text = region.getText();
                        // System.out.println(text);
                        if ("<c<% aaa ".equals(text)) {
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 33:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 34:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 35:
            {
                // if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 36:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 37:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 38:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 39:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 40:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NODES_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGIONS_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGION_CHANGED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NEW_MODEL_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NO_CHANGE_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        default:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
            }
    }
}
Also used : NewDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)

Example 59 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class Debug method dump.

public static final void dump(IStructuredDocument structuredDocument, boolean verbose) {
    ITextRegionCollection flatNode = null;
    // $NON-NLS-1$
    System.out.println("Dump of structuredDocument:");
    IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
    Enumeration<?> structuredDocumentRegions = flatNodes.elements();
    while (structuredDocumentRegions.hasMoreElements()) {
        flatNode = (ITextRegionCollection) structuredDocumentRegions.nextElement();
        if (!verbose) {
            String outString = flatNode.toString();
            outString = org.eclipse.wst.sse.core.utils.StringUtils.escape(outString);
            System.out.println(outString);
        } else {
            dump(flatNode, verbose);
        }
    }
    System.out.println();
    // $NON-NLS-1$
    System.out.println("= = = = = =");
    System.out.println();
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 60 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class BasicStructuredDocument method updateDeletedFields.

/**
 * @param result
 */
private void updateDeletedFields(StructuredDocumentRegionsReplacedEvent event) {
    IStructuredDocumentRegionList oldRegions = event.getOldStructuredDocumentRegions();
    for (int i = 0; i < oldRegions.getLength(); i++) {
        IStructuredDocumentRegion structuredDocumentRegion = oldRegions.item(i);
        structuredDocumentRegion.setDeleted(true);
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)

Aggregations

IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)68 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)11 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)3 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)3 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 DOMException (org.w3c.dom.DOMException)2 Element (org.w3c.dom.Element)2 NodesEvent (org.eclipse.wst.dtd.core.internal.event.NodesEvent)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 NewDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent)1 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)1 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)1 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)1 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)1 CoreNodeList (org.eclipse.wst.sse.core.internal.text.CoreNodeList)1