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());
}
}
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());
}
}
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());
}
}
Aggregations