Search in sources :

Example 16 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class AbstractCSSSourceFormatter method decoratedPropNameRegion.

/**
 */
protected String decoratedPropNameRegion(CompoundRegion region, CSSCleanupStrategy stgy) {
    if (isFormat())
        return region.getText();
    String text = null;
    if (!stgy.isFormatSource())
        text = region.getFullText();
    else
        text = region.getText();
    if (region.getType() == CSSRegionContexts.CSS_STRING || region.getType() == CSSRegionContexts.CSS_URI)
        return decoratedRegion(region, 1, stgy);
    if (isCleanup()) {
        if (stgy.getPropNameCase() == CSSCleanupStrategy.ASIS || region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY)
            return text;
        else if (stgy.getPropNameCase() == CSSCleanupStrategy.UPPER)
            return text.toUpperCase();
        else
            return text.toLowerCase();
    }
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY)
        return text;
    else if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER)
        return text.toUpperCase();
    else
        return text.toLowerCase();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 17 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class AbstractCSSSourceFormatter method getIndentString.

private String getIndentString() {
    StringBuffer indent = new StringBuffer();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (preferences != null) {
        char indentChar = ' ';
        String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
        if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
            indentChar = '\t';
        }
        int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
        for (int i = 0; i < indentationWidth; i++) {
            indent.append(indentChar);
        }
    }
    return indent.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 18 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class AttrFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    ICSSAttr attr = (ICSSAttr) node;
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        int start = ((IndexedRegion) node).getStartOffset();
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBetween(node, regions[i - 1], regions[i], source);
                source.append(decoratedRegion(regions[i], 0, stgy));
            }
        } else if (attr.getName().equals(ICSSImportRule.HREF)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        } else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedIdentRegion(regions[i], stgy));
            }
        } else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        } else if (attr.getName() == null || attr.getName().length() == 0) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedIdentRegion(regions[i], stgy));
            }
        } else {
            // counter attributes
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        }
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String value = attr.getValue();
        if (value == null)
            // $NON-NLS-1$
            value = "";
        if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
        } else if (attr.getName().equals(ICSSImportRule.HREF)) {
            String uri = org.eclipse.wst.css.core.internal.util.CSSLinkConverter.stripFunc(value);
            // $NON-NLS-2$//$NON-NLS-1$
            String func = preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER ? "URL(" : "url(";
            if (preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI)) {
                String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
                quote = CSSUtil.detectQuote(uri, quote);
                // $NON-NLS-1$
                value = func + quote + uri + quote + ")";
            } else {
                // $NON-NLS-1$
                value = func + uri + ")";
            }
        } else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
            String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
            if (// $NON-NLS-2$//$NON-NLS-1$
            !value.startsWith("\"") && !value.startsWith("\'"))
                value = quote + value;
            if (// $NON-NLS-2$//$NON-NLS-1$
            !value.endsWith("\"") && !value.endsWith("\'"))
                value = value + quote;
        } else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
            if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        } else if (attr.getName() == null || attr.getName().length() == 0) {
            if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        } else {
            if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        }
        source.append(value);
    }
}
Also used : ICSSAttr(org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 19 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class CharsetRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        int start = ((IndexedRegion) node).getStartOffset();
        formatPre(node, new FormatRegion(start, end - start), source);
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        String str = CHARSET;
        if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = CHARSET.toUpperCase();
        source.append(str);
        String enc = ((ICSSCharsetRule) node).getEncoding();
        quote = CSSUtil.detectQuote(enc, quote);
        // $NON-NLS-1$ //$NON-NLS-2$
        str = quote + ((enc != null) ? enc : "") + quote + ";";
        appendSpaceBefore(node, str, source);
        source.append(str);
    }
}
Also used : ICSSCharsetRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 20 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class StyleDeclItemFormatter method getIndentString.

private String getIndentString() {
    StringBuffer indent = new StringBuffer();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (preferences != null) {
        char indentChar = ' ';
        String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
        if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
            indentChar = '\t';
        }
        int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
        for (int i = 0; i < indentationWidth; i++) {
            indent.append(indentChar);
        }
    }
    return indent.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Aggregations

Preferences (org.eclipse.core.runtime.Preferences)113 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 IFile (org.eclipse.core.resources.IFile)6 PartInitException (org.eclipse.ui.PartInitException)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 IStructuredFormatPreferences (org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)4 IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)4 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)4 List (java.util.List)3 Vector (java.util.Vector)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2