public void setCssText(final String cssText) throws DOMException { try { final InputSource is = new InputSource(new StringReader(cssText)); final CSSOMParser parser = new CSSOMParser(); properties_.clear(); parser.parseStyleDeclaration(this, is); } catch (final Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
public void setMediaText(final String mediaText) { final InputSource source = new InputSource(new StringReader(mediaText)); try { final CSSOMParser parser = new CSSOMParser(); final SACMediaList sml = parser.parseMedia(source); media_ = new MediaListImpl(sml); } catch (final IOException e) { // TODO handle exception } }
public Map<String, CSSStyleRule> parseCSS() throws IOException { Map<String, CSSStyleRule> rules = new HashMap<String, CSSStyleRule>(); InputSource inputSource = new InputSource(new FileReader("bootstrap.css")); CSSStyleSheet styleSheet = new CSSOMParser().parseStyleSheet(inputSource, null, null); CSSRuleList ruleList = styleSheet.getCssRules(); for (int i = 0; i < ruleList.getLength(); i++) { CSSRule rule = ruleList.item(i); if (rule.getType() == CSSRule.STYLE_RULE) { CSSStyleRule styleRule = (CSSStyleRule) rule; rules.put(styleRule.getSelectorText(), styleRule); } } return rules; }
public void setCssText(final String cssText) throws DOMException { try { final InputSource is = new InputSource(new StringReader(cssText)); final CSSOMParser parser = new CSSOMParser(); final CSSValueImpl v2 = (CSSValueImpl) parser.parsePropertyValue(is); value_ = v2.value_; setUserDataMap(v2.getUserDataMap()); } catch (final Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
public void setMediaText(final String mediaText) throws DOMException { final InputSource source = new InputSource(new StringReader(mediaText)); try { final CSSOMParser parser = new CSSOMParser(); parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE); final SACMediaList sml = parser.parseMedia(source); setMediaList(sml); } catch (final CSSParseException e) { throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage()); } catch (final IOException e) { throw new DOMException(DOMException.NOT_FOUND_ERR, e.getLocalizedMessage()); } }
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); } }
public void setProperty( final String propertyName, final String value, final String priority) throws DOMException { try { CSSValue expr = null; if (!value.isEmpty()) { final CSSOMParser parser = new CSSOMParser(); final InputSource is = new InputSource(new StringReader(value)); expr = parser.parsePropertyValue(is); } Property p = getPropertyDeclaration(propertyName); final boolean important = PRIORITY_IMPORTANT.equalsIgnoreCase(priority); if (p == null) { p = new Property(propertyName, expr, important); addProperty(p); } else { p.setValue(expr); p.setImportant(important); } } catch (final Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
public void setSelectorText(final String selectorText) throws DOMException { final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { final InputSource is = new InputSource(new StringReader(selectorText)); final CSSOMParser parser = new CSSOMParser(); selectors_ = parser.parseSelectors(is); } catch (final CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (final IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } }
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(); } } } }
/** * Parses the selectors at the specified input source. If anything at all goes wrong, this * method returns an empty selector list. * * @param source the source from which to retrieve the selectors to be parsed * @return the selectors parsed from the specified input source */ SelectorList parseSelectors(final InputSource source) { SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); } catch (final Exception e) { LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } return selectors; }
/** * Parses the selectors at the specified input source. If anything at all goes wrong, this * method returns an empty selector list. * * @param source the source from which to retrieve the selectors to be parsed * @return the selectors parsed from the specified input source */ SelectorList parseSelectors(final InputSource source) { SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); } catch (final Exception e) { LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } return selectors; }
/** * 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 selectors at the specified input source. If anything at all goes wrong, this * method returns an empty selector list. * * @param source the source from which to retrieve the selectors to be parsed * @return the selectors parsed from the specified input source */ SelectorList parseSelectors(final InputSource source) { SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); } catch (final Exception e) { LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } catch (final Error e) { // SACParser sometimes throws Error: "Missing return statement in function" LOG.error("Error parsing CSS selectors from '" + toString(source) + "': " + e.getMessage(), e); selectors = new SelectorListImpl(); } return selectors; }
/** * 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; }
final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);
final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);
final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);
final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);
final CSSOMParser parser = new CSSOMParser(); final CSSRule r = parser.parseRule(is);