Search in sources :

Example 56 with ITextRegion

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

the class JSPTranslator method translatePageDirectiveAttributes.

/**
 * takes an iterator of the attributes of a page directive and the
 * directive itself. The iterator is used in case it can be optimized, but
 * the documentRegion is still required to ensure that the values are
 * extracted from the correct text.
 */
protected void translatePageDirectiveAttributes(Iterator regions, IStructuredDocumentRegion documentRegion) {
    ITextRegion r = null;
    String attrName, attrValue;
    // iterate all attributes
    while (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() != DOMJSPRegionContexts.JSP_CLOSE) {
        attrName = attrValue = null;
        if (r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
            attrName = documentRegion.getText(r).trim();
            if (attrName.length() > 0) {
                if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
                    if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                        attrValue = StringUtils.strip(documentRegion.getText(r));
                    }
                // has equals, but no value?
                }
                setDirectiveAttribute(attrName, attrValue);
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 57 with ITextRegion

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

the class JSPTranslator method isEmptyTag.

private boolean isEmptyTag(ITextRegionCollection customTag, int index) {
    String type = null;
    // custom tag is embedded
    ITextRegionList regions = customTag.getRegions();
    ITextRegion nextRegion = regions.get(index);
    int size = customTag.getNumberOfRegions();
    type = nextRegion.getType();
    while (index <= size && !(DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(type) || DOMRegionContext.XML_TAG_NAME.equals(type) || DOMRegionContext.XML_TAG_CLOSE.equals(type))) {
        nextRegion = regions.get(++index);
        type = nextRegion.getType();
    }
    return DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(type);
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 58 with ITextRegion

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

the class JSPTranslator method translateXMLContent.

/**
 * This currently only detects EL content and translates it,
 * but if other cases arise later then they could be added in here
 *
 * @param embeddedContainer the container that may contain EL
 */
protected void translateXMLContent(ITextRegionContainer embeddedContainer) {
    ITextRegionList embeddedRegions = embeddedContainer.getRegions();
    int length = embeddedRegions.size();
    for (int i = 0; i < length; i++) {
        ITextRegion delim = embeddedRegions.get(i);
        String type = delim.getType();
        // check next region to see if it's EL content
        if (i + 1 < length) {
            if ((type == DOMJSPRegionContexts.JSP_EL_OPEN || type == DOMJSPRegionContexts.JSP_VBL_OPEN)) {
                ITextRegion region = null;
                int start = delim.getEnd();
                while (++i < length) {
                    region = embeddedRegions.get(i);
                    if (region == null || !isELType(region.getType()))
                        break;
                }
                fLastJSPType = EXPRESSION;
                String elText = embeddedContainer.getFullText().substring(start, (region != null ? region.getStart() : embeddedContainer.getLength() - 1));
                translateEL(elText, embeddedContainer.getText(delim), fCurrentNode, embeddedContainer.getEndOffset(delim), elText.length());
            }
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 59 with ITextRegion

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

the class XMLJSPRegionHelper method getAttributeValue.

/*
	 * convenience method to get an attribute value from attribute name
	 */
protected String getAttributeValue(String attrName, IStructuredDocumentRegion sdRegion) {
    String sdRegionText = fTextToParse.substring(sdRegion.getStartOffset(), sdRegion.getEndOffset());
    // $NON-NLS-1$
    String textRegionText, attrValue = "";
    Iterator it = sdRegion.getRegions().iterator();
    ITextRegion nameRegion, valueRegion = null;
    while (it.hasNext()) {
        nameRegion = (ITextRegion) it.next();
        if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
            textRegionText = sdRegionText.substring(nameRegion.getStart(), nameRegion.getTextEnd());
            if (textRegionText.equalsIgnoreCase(attrName)) {
                while (it.hasNext()) {
                    valueRegion = (ITextRegion) it.next();
                    if (valueRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                        attrValue = sdRegionText.substring(valueRegion.getStart(), valueRegion.getEnd());
                        // inner
                        break;
                    }
                }
                // outer
                break;
            }
        }
    }
    return StringUtils.stripQuotes(attrValue);
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Example 60 with ITextRegion

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

the class XMLJSPRegionHelper method hasIllegalContent.

private int hasIllegalContent(IStructuredDocumentRegion sdRegion) {
    ITextRegionList list = sdRegion.getRegions();
    for (int i = 0; i < list.size(); i++) {
        ITextRegion region = list.get(i);
        String type = region.getType();
        if (type == DOMRegionContext.UNDEFINED)
            return i;
        if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_EMPTY_TAG_CLOSE || type == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE)
            return -1;
    }
    return -1;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) 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