use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class ElementImpl method querySelectorAll.
/**
* {@inheritDoc}
*/
@Override
public NodeList querySelectorAll(String selector) {
final ArrayList<Node> al = new ArrayList<>();
if (selector == null) {
return new NodeListImpl(al);
}
if (selector.isEmpty()) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "The provided selector is empty.");
}
if (selector.trim().isEmpty()) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "is not a valid selector.");
}
SelectorList selectorList = CSSUtilities.getSelectorList(selector);
if (selectorList != null) {
NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
childNodes.forEach(child -> {
for (Selector select : selectorList) {
if (child instanceof Element && StyleSheetAggregator.selects(select, child, null)) {
al.add(child);
}
}
});
}
return new NodeListImpl(al);
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class DocumentImpl method querySelector.
/**
* {@inheritDoc}
*/
@Override
public Element querySelector(String selectors) {
SelectorList selectorList = CSSUtilities.getSelectorList(selectors);
List<Element> elem = new ArrayList<>();
if (selectorList != null) {
NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
childNodes.forEach(child -> {
for (Selector selector : selectorList) {
if (child instanceof Element && StyleSheetAggregator.selects(selector, child, null)) {
elem.add((Element) child);
}
}
});
}
return elem.size() > 0 ? elem.get(0) : null;
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class CSS3Parser method styleRule.
//
// ruleset
// : selector [ COMMA S* selector ]*
// '{' S* declaration [ ';' S* declaration ]* '}' S*
// ;
//
public final void styleRule() throws ParseException {
SelectorList selList = null;
boolean start = false;
Token t;
try {
t = token;
selList = selectorList();
jj_consume_token(LBRACE);
label_40: while (true) {
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case S:
{
;
break;
}
default:
jj_la1[62] = jj_gen;
break label_40;
}
jj_consume_token(S);
}
start = true;
handleStartSelector(selList, createLocator(t.next));
styleDeclaration();
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case RBRACE:
{
jj_consume_token(RBRACE);
break;
}
case 0:
{
jj_consume_token(0);
break;
}
default:
jj_la1[63] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
} catch (CSSParseException e) {
getErrorHandler().error(e);
error_skipblock("ignoringRule", e);
} catch (ParseException e) {
CSSParseException cpe = toCSSParseException("invalidStyleRule", e);
getErrorHandler().error(cpe);
error_skipblock("ignoringFollowingDeclarations", cpe);
} finally {
if (start) {
handleEndSelector(selList);
}
}
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class AbstractCSSParser method parseSelectors.
/**
* Parse a comma separated list of selectors.
*
* @param source source to be parsed
* @return a selector list
* @exception CSSException Any CSS exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
public SelectorList parseSelectors(final InputSource source) throws IOException {
source_ = source;
ReInit(getCharStream(source));
SelectorList sl = null;
try {
sl = parseSelectorsInternal();
} catch (final ParseException e) {
getErrorHandler().error(toCSSParseException("invalidSelectorList", e));
} catch (final TokenMgrError e) {
getErrorHandler().error(toCSSParseException(e));
} catch (final CSSParseException e) {
getErrorHandler().error(e);
}
return sl;
}
use of com.gargoylesoftware.css.parser.selector.SelectorList in project LoboEvolution by LoboEvolution.
the class DocumentImpl method querySelectorAll.
/**
* {@inheritDoc}
*/
@Override
public NodeList querySelectorAll(String selector) {
final ArrayList<Node> al = new ArrayList<>();
if (selector == null) {
return new NodeListImpl(al);
}
if (selector.isEmpty()) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "The provided selector is empty.");
}
if (selector.trim().isEmpty()) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "is not a valid selector.");
}
SelectorList selectorList = CSSUtilities.getSelectorList(selector);
if (selectorList != null) {
NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
childNodes.forEach(child -> {
for (Selector select : selectorList) {
if (child instanceof Element && StyleSheetAggregator.selects(select, child, null)) {
al.add(child);
}
}
});
}
return new NodeListImpl(al);
}
Aggregations