use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class CSSUtilities method getSelectorList.
/**
* <p>getSelectorList.</p>
*
* @param selectors a {@link java.lang.String} object.
* @return a {@link com.gargoylesoftware.css.parser.selector.SelectorList} object.
*/
public static SelectorList getSelectorList(final String selectors) {
final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
SelectorList selectorList = null;
try {
selectorList = parser.parseSelectors(selectors);
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
return selectorList;
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class CSS3Parser method parseSelectorsInternal.
public final SelectorList parseSelectorsInternal() throws ParseException {
SelectorList selectors;
label_41: while (true) {
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case S:
{
;
break;
}
default:
jj_la1[64] = jj_gen;
break label_41;
}
jj_consume_token(S);
}
selectors = selectorList();
jj_consume_token(0);
return selectors;
}
use of com.gargoylesoftware.css.parser.selector.SelectorList 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.selector.SelectorList 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());
}
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project htmlunit by HtmlUnit.
the class CSSStyleSheet method parseSelectors.
/**
* 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
*/
public SelectorList parseSelectors(final String source) {
SelectorList selectors;
try {
final CSSErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler();
final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
parser.setErrorHandler(errorHandler);
selectors = parser.parseSelectors(source);
// in case of error parseSelectors returns null
if (null == selectors) {
selectors = new SelectorListImpl();
}
} catch (final Throwable t) {
if (LOG.isErrorEnabled()) {
LOG.error("Error parsing CSS selectors from '" + source + "': " + t.getMessage(), t);
}
selectors = new SelectorListImpl();
}
return selectors;
}
Aggregations