Search in sources :

Example 16 with CSSException

use of com.gargoylesoftware.css.parser.CSSException in project LoboEvolution by LoboEvolution.

the class CSSStyleRuleImpl method setCssText.

/**
 * {@inheritDoc}
 */
@Override
public void setCssText(final String cssText) throws DOMException {
    try {
        final CSSOMParser parser = new CSSOMParser();
        final AbstractCSSRuleImpl r = parser.parseRule(cssText);
        // The rule must be a style rule
        if (r instanceof CSSStyleRuleImpl) {
            selectors_ = ((CSSStyleRuleImpl) r).selectors_;
            style_ = ((CSSStyleRuleImpl) r).style_;
        } else {
            throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, DOMException.EXPECTING_STYLE_RULE);
        }
    } catch (final CSSException e) {
        throw new DOMException(DOMException.SYNTAX_ERR, e.getMessage());
    } catch (final IOException e) {
        throw new DOMException(DOMException.SYNTAX_ERR, e.getMessage());
    }
}
Also used : CSSOMParser(com.gargoylesoftware.css.parser.CSSOMParser) CSSException(com.gargoylesoftware.css.parser.CSSException) IOException(java.io.IOException)

Example 17 with CSSException

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

the class NamedAttrNodeMapImpl method matches.

/**
 * Returns true if the element would be selected by the specified selector string; otherwise, returns false.
 * @param selectorString the selector to test
 * @return true if the element would be selected by the specified selector string; otherwise, returns false.
 */
public boolean matches(final String selectorString) {
    try {
        final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion();
        final SelectorList selectorList = getSelectorList(selectorString, browserVersion);
        if (selectorList != null) {
            for (final Selector selector : selectorList) {
                if (CSSStyleSheet.selects(browserVersion, selector, this, null, true)) {
                    return true;
                }
            }
        }
        return false;
    } catch (final IOException e) {
        throw new CSSException("Error parsing CSS selectors from '" + selectorString + "': " + e.getMessage());
    }
}
Also used : SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) CSSException(com.gargoylesoftware.css.parser.CSSException) IOException(java.io.IOException) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 18 with CSSException

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

the class DomNode method querySelectorAll.

/**
 * Retrieves all element nodes from descendants of the starting element node that match any selector
 * within the supplied selector strings.
 * @param selectors one or more CSS selectors separated by commas
 * @return list of all found nodes
 */
public DomNodeList<DomNode> querySelectorAll(final String selectors) {
    try {
        final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion();
        final SelectorList selectorList = getSelectorList(selectors, browserVersion);
        final List<DomNode> elements = new ArrayList<>();
        if (selectorList != null) {
            for (final DomElement child : getDomElementDescendants()) {
                for (final Selector selector : selectorList) {
                    if (CSSStyleSheet.selects(browserVersion, selector, child, null, true)) {
                        elements.add(child);
                        break;
                    }
                }
            }
        }
        return new StaticDomNodeList(elements);
    } catch (final IOException e) {
        throw new CSSException("Error parsing CSS selectors from '" + selectors + "': " + e.getMessage());
    }
}
Also used : SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) ArrayList(java.util.ArrayList) CSSException(com.gargoylesoftware.css.parser.CSSException) IOException(java.io.IOException) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Aggregations

CSSException (com.gargoylesoftware.css.parser.CSSException)18 IOException (java.io.IOException)16 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)13 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)5 CSSErrorHandler (com.gargoylesoftware.css.parser.CSSErrorHandler)3 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)3 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)3 Selector (com.gargoylesoftware.css.parser.selector.Selector)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IncorrectnessListener (com.gargoylesoftware.htmlunit.IncorrectnessListener)1 ScriptException (com.gargoylesoftware.htmlunit.ScriptException)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)1 DisabledElement (com.gargoylesoftware.htmlunit.html.DisabledElement)1