Search in sources :

Example 6 with ICSSImportRule

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

the class ImportRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    if (end > 0) {
        // format source
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            String str = regions[i].getText();
            if (regions[i].getType() == CSSRegionContexts.CSS_IMPORT)
                str = decoratedIdentRegion(regions[i], stgy);
            else
                str = decoratedPropValueRegion(regions[i], stgy);
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(str);
        }
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String str = IMPORT;
        if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = IMPORT.toUpperCase();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        source.append(str);
        // $NON-NLS-1$
        str = "url(";
        if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
            str = str.toUpperCase();
        String href = ((ICSSImportRule) node).getHref();
        quote = CSSUtil.detectQuote(href, quote);
        // $NON-NLS-1$
        str = str + quote + href + quote + ")";
        appendSpaceBefore(node, str, source);
        source.append(str);
    }
    ICSSNode child = node.getFirstChild();
    if (child != null && (child instanceof org.w3c.dom.stylesheets.MediaList) && ((org.w3c.dom.stylesheets.MediaList) child).getLength() > 0) {
        // $NON-NLS-1$
        appendSpaceBefore(node, "", source);
    }
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)

Aggregations

ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)6 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)5 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)3 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)2 CSSRule (org.w3c.dom.css.CSSRule)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)1 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)1 ICSSCharsetRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule)1 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)1 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)1 SelectionCollector (org.eclipse.wst.css.core.internal.util.SelectionCollector)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 CSSImportRule (org.w3c.dom.css.CSSImportRule)1 CSSRuleList (org.w3c.dom.css.CSSRuleList)1