InputSource source = new InputSource( new StringReader( "h1 { background: #ffcc44; } div { color: red; }")); CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); CSSStyleSheet sheet = parser.parseStyleSheet(source, null, null); CSSRuleList rules = sheet.getCssRules(); for (int i = 0; i < rules.getLength(); i++) { final CSSRule rule = rules.item(i); System.out.println(rule.getCssText()); }
CSSOMParser parser = new CSSOMParser(); InputSource source = new InputSource(new FileReader(cssFile)); CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null);
private static CSSStyleSheetImpl parseStyleSheet(final InputSource source) throws TranslatorException { try { CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); return (CSSStyleSheetImpl) parser.parseStyleSheet(source, null, null); } catch (final IOException e) { throw new TranslatorException("Exception while parsing some style defintion.", e); } }
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(); } } } }
CSSOMParser parser = new CSSOMParser(); try { CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null); CSSRuleList ruleList = stylesheet.getCssRules();
/** * Parses the CSS at the specified input source. If anything at all goes wrong, this method * returns an empty stylesheet. * * @param source the source from which to retrieve the CSS to be parsed * @return the stylesheet parsed from the specified input source */ private CSSStyleSheet parseCSS(final InputSource source) { CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } catch (final Exception e) { LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } return ss; }
/** * Parses the CSS at the specified input source. If anything at all goes wrong, this method * returns an empty stylesheet. * * @param source the source from which to retrieve the CSS to be parsed * @return the stylesheet parsed from the specified input source */ private CSSStyleSheet parseCSS(final InputSource source) { CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } catch (final Exception e) { LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } return ss; }
/** * Parses the CSS at the specified input source. If anything at all goes wrong, this method * returns an empty stylesheet. * * @param source the source from which to retrieve the CSS to be parsed * @return the stylesheet parsed from the specified input source */ private CSSStyleSheet parseCSS(final InputSource source) { CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } catch (final Exception e) { LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS from '" + toString(source) + "': " + e.getMessage(), e); ss = new CSSStyleSheetImpl(); } return ss; }
styleSheet = parser.parseStyleSheet(source, null, null); } catch (Exception e) { LOGGER.error(e.getMessage(), e);
final URI importURI = new URI(getBaseUri()).resolve(cssImportRule.getHref()); final CSSStyleSheetImpl importedCSS = (CSSStyleSheetImpl) new CSSOMParser().parseStyleSheet(new InputSource( importURI.toString()), null, importURI.toString()); if (recursive) {