com.steadystate.css.parser.SACParserCSS3 Java Examples
The following examples show how to use
com.steadystate.css.parser.SACParserCSS3.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StyleParser.java From svgtoandroid with MIT License | 6 votes |
private void init() { if (style != null) { String styleContent = style.getValue().getText(); if (styleContent != null && !styleContent.isEmpty()) { InputSource source = new InputSource(new StringReader(styleContent)); CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(new ParserErrorHandler()); try { styleSheet = parser.parseStyleSheet(source, null, null); cssFormat = new CSSFormat().setRgbAsHex(true); CSSRuleList rules = styleSheet.getCssRules(); for (int i = 0; i < rules.getLength(); i++) { final CSSRule rule = rules.item(i); if (rule instanceof CSSStyleRuleImpl) { styleRuleMap.put(((CSSStyleRuleImpl) rule).getSelectorText(), (CSSStyleRuleImpl) rule); } } } catch (IOException e) { e.printStackTrace(); } } } }
Example #2
Source File: CssFormatter.java From formatter-maven-plugin with Apache License 2.0 | 5 votes |
@Override protected String doFormat(String code, LineEnding ending) throws IOException { InputSource source = new InputSource(new StringReader(code)); CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) parser.parseStyleSheet(source, null, null); String formattedCode = sheet.getCssText(formatter); if (code.equals(formattedCode)) { return null; } return formattedCode; }