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);
}
}
Aggregations