Search in sources :

Example 26 with CSSOMParser

use of com.gargoylesoftware.css.parser.CSSOMParser in project htmlunit by HtmlUnit.

the class CSSStyleSheet method parseCSS.

/**
 * 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
 * @param client the client
 * @return the stylesheet parsed from the specified input source
 */
private static CSSStyleSheetImpl parseCSS(final InputSource source, final WebClient client) {
    CSSStyleSheetImpl ss;
    try {
        final CSSErrorHandler errorHandler = client.getCssErrorHandler();
        final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
        parser.setErrorHandler(errorHandler);
        ss = parser.parseStyleSheet(source, null);
    } catch (final Throwable t) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Error parsing CSS from '" + toString(source) + "': " + t.getMessage(), t);
        }
        ss = new CSSStyleSheetImpl();
    }
    return ss;
}
Also used : CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) CSSErrorHandler(com.gargoylesoftware.css.parser.CSSErrorHandler) CSSOMParser(com.gargoylesoftware.css.parser.CSSOMParser) CSS3Parser(com.gargoylesoftware.css.parser.javacc.CSS3Parser)

Aggregations

CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)26 IOException (java.io.IOException)16 CSSException (com.gargoylesoftware.css.parser.CSSException)14 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)10 CSSErrorHandler (com.gargoylesoftware.css.parser.CSSErrorHandler)4 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)4 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)4 CSSStyleDeclarationImpl (com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)2 DOMException (com.gargoylesoftware.css.dom.DOMException)2 InputSource (com.gargoylesoftware.css.parser.InputSource)2 MediaQueryList (com.gargoylesoftware.css.parser.media.MediaQueryList)2 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 DOMException (org.w3c.dom.DOMException)2 CSSStyleSheetImpl (com.gargoylesoftware.css.dom.CSSStyleSheetImpl)1 MediaListImpl (com.gargoylesoftware.css.dom.MediaListImpl)1 MediaQuery (com.gargoylesoftware.css.parser.media.MediaQuery)1 SelectorListImpl (com.gargoylesoftware.css.parser.selector.SelectorListImpl)1 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)1 DisabledElement (com.gargoylesoftware.htmlunit.html.DisabledElement)1