use of com.gargoylesoftware.css.parser.selector.Selector in project LoboEvolution by LoboEvolution.
the class ElementImpl method querySelector.
/**
* {@inheritDoc}
*/
@Override
public Element querySelector(String selectors) {
try {
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;
} catch (Exception e) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "Is not a valid selector.");
}
}
use of com.gargoylesoftware.css.parser.selector.Selector 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.");
}
try {
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);
} catch (Exception e) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "Is not a valid selector.");
}
}
use of com.gargoylesoftware.css.parser.selector.Selector in project LoboEvolution by LoboEvolution.
the class CSS3Parser method selectorList.
public final SelectorList selectorList() throws ParseException {
SelectorListImpl selList = new SelectorListImpl();
Selector sel;
sel = selector();
selList.setLocator(sel.getLocator());
label_42: while (true) {
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case COMMA:
{
;
break;
}
default:
jj_la1[65] = jj_gen;
break label_42;
}
jj_consume_token(COMMA);
label_43: while (true) {
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case S:
{
;
break;
}
default:
jj_la1[66] = jj_gen;
break label_43;
}
jj_consume_token(S);
}
selList.add(sel);
sel = selector();
selList.setLocator(sel.getLocator());
}
selList.add(sel);
return selList;
}
use of com.gargoylesoftware.css.parser.selector.Selector in project LoboEvolution by LoboEvolution.
the class CSS3Parser method selector.
//
// selector
// : simple_selector_sequence [ combinator simple_selector_sequence ]*
// ;
//
public final Selector selector() throws ParseException {
Selector sel;
char comb;
try {
sel = simpleSelector(null, ' ');
label_44: while (true) {
if (jj_2_1(2)) {
;
} else {
break label_44;
}
comb = combinator();
sel = simpleSelector(sel, comb);
}
label_45: while (true) {
switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
case S:
{
;
break;
}
default:
jj_la1[67] = jj_gen;
break label_45;
}
jj_consume_token(S);
}
return sel;
} catch (ParseException e) {
throw toCSSParseException("invalidSelector", e);
}
}
use of com.gargoylesoftware.css.parser.selector.Selector 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.");
}
try {
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);
} catch (Exception e) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "Is not a valid selector.");
}
}
Aggregations