Search in sources :

Example 1 with CSSNodeImpl

use of org.eclipse.wst.css.core.internal.document.CSSNodeImpl in project webtools.sourceediting by eclipse.

the class JSPedCSSModelParser method insertStructuredDocumentRegion.

/**
 */
protected CSSNodeImpl insertStructuredDocumentRegion(IStructuredDocumentRegion region) {
    CSSModelCreationContext creationContext = getCreationContext();
    if (creationContext == null || region == null) {
        return null;
    }
    String type = ((BasicStructuredDocumentRegion) region).getType();
    CSSNodeImpl modified = null;
    if (type == JSPedCSSRegionContexts.CSS_JSP_DIRECTIVE) {
        boolean isInclude = region.getText().indexOf("include") != -1;
        if (isInclude) {
            modified = insertUnknownImport(region);
        } else {
            modified = insertUnknownRule(region);
        }
    }
    // post process
    if (modified != null) {
        if (modified instanceof CSSStructuredDocumentRegionContainer) {
            ((CSSStructuredDocumentRegionContainer) modified).propagateRangeStructuredDocumentRegion();
        }
    }
    return modified != null ? modified : super.insertStructuredDocumentRegion(region);
}
Also used : BasicStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion) CSSStructuredDocumentRegionContainer(org.eclipse.wst.css.core.internal.document.CSSStructuredDocumentRegionContainer) CSSNodeImpl(org.eclipse.wst.css.core.internal.document.CSSNodeImpl) CSSModelCreationContext(org.eclipse.wst.css.core.internal.document.CSSModelCreationContext)

Example 2 with CSSNodeImpl

use of org.eclipse.wst.css.core.internal.document.CSSNodeImpl in project webtools.sourceediting by eclipse.

the class JSPedCSSModelParser method insertUnknownImport.

private CSSNodeImpl insertUnknownImport(IStructuredDocumentRegion region) {
    CSSModelCreationContext creationContext = getCreationContext();
    CSSNodeImpl parent = creationContext.getTargetNode();
    ICSSDocument sheet = parent.getOwnerDocument();
    String text = region.getText();
    Pattern pattern = Pattern.compile(" ");
    String[] strs = pattern.split(text);
    String hrefValue = null;
    for (int i = 0; i < strs.length; i++) {
        String hrefStr = "file=\"";
        if (strs[i].startsWith(hrefStr)) {
            int hrefStr_length = hrefStr.length();
            // minus 1 to avoid quote?
            int hrefValue_length = strs[i].length() - 1;
            if (hrefValue_length > hrefStr_length) {
                hrefValue = strs[i].substring(hrefStr_length, hrefValue_length);
            } else {
                /*
					 * ISSUE: this handles cases where, e.g. "file=" has no
					 * subsequent 'value' ... and from code in insertStructuredDocumentRegion
					 * I believe should return null, rather than empty string, but, this may 
					 * need some fine tuning eventually.
					 */
                hrefValue = null;
            }
            break;
        }
    }
    if (hrefValue == null) {
        return null;
    }
    JSPCSSImportRuleImpl rule = new JSPCSSImportRuleImpl();
    rule.setOwnerDocument(sheet);
    rule.appendChild((CSSNodeImpl) sheet.createMediaList());
    rule.setRangeStructuredDocumentRegion(region, region);
    if (!isUpdateContextActive()) {
        // Attribute(ICSSImportRule.HREF, hrefValue);
        rule.setHref(hrefValue);
    }
    // insert to tree
    if (!isUpdateContextActive() && parent != null) {
        // propagateRangePreInsert(sheet, rule);
        CSSNodeImpl next = creationContext.getNextNode();
        if (next != null) {
            ((CSSNodeImpl) sheet).insertBefore(rule, next);
        } else {
            ((CSSNodeImpl) sheet).appendChild(rule);
        }
    }
    // creationContext.setTargetNode(rule);
    return rule;
}
Also used : Pattern(java.util.regex.Pattern) CSSNodeImpl(org.eclipse.wst.css.core.internal.document.CSSNodeImpl) CSSModelCreationContext(org.eclipse.wst.css.core.internal.document.CSSModelCreationContext) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Example 3 with CSSNodeImpl

use of org.eclipse.wst.css.core.internal.document.CSSNodeImpl in project webtools.sourceediting by eclipse.

the class JSPedCSSModelParser method insertUnknownRule.

private CSSNodeImpl insertUnknownRule(IStructuredDocumentRegion flatNode) {
    CSSModelCreationContext creationContext = getCreationContext();
    CSSNodeImpl parent = creationContext.getTargetNode();
    if (!isParseFloating() && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    JSPCSSNodeImpl rule = new JSPCSSNodeImpl(flatNode.getText());
    rule.setOwnerDocument(parent.getOwnerDocument());
    // setup flat container
    rule.setRangeStructuredDocumentRegion(flatNode, flatNode);
    // insert to tree
    if (!isUpdateContextActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = creationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) CSSNodeImpl(org.eclipse.wst.css.core.internal.document.CSSNodeImpl) CSSModelCreationContext(org.eclipse.wst.css.core.internal.document.CSSModelCreationContext)

Aggregations

CSSModelCreationContext (org.eclipse.wst.css.core.internal.document.CSSModelCreationContext)3 CSSNodeImpl (org.eclipse.wst.css.core.internal.document.CSSNodeImpl)3 Pattern (java.util.regex.Pattern)1 CSSStructuredDocumentRegionContainer (org.eclipse.wst.css.core.internal.document.CSSStructuredDocumentRegionContainer)1 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 ICSSRuleContainer (org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer)1 BasicStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion)1