use of org.asqatasun.rules.keystore.HtmlElementStore.AREA_ELEMENT in project Asqatasun by Asqatasun.
the class AbstractMarkerPageRuleImplementation method sortMarkerElements.
/**
* To sort marker elements, we extract for each of them the value of the
* "id" attribute the value of the "class" attribute and the value of the
* "role" attribute. If one of these three values belongs to the marker
* value list set by the user, we consider that the element is characterised
* and we add it to the "elementMarkerList".
*/
protected void sortMarkerElements(ElementHandler<Element> selectionWithMarkerHandler, ElementHandler<Element> selectionWithoutMarkerHandler) {
if ((CollectionUtils.isEmpty(markerList) && CollectionUtils.isEmpty(inverseMarkerList)) || selectionWithoutMarkerHandler.isEmpty()) {
return;
}
Iterator<Element> iter = selectionWithoutMarkerHandler.get().iterator();
Element el;
while (iter.hasNext()) {
el = iter.next();
Collection<String> ids = new ArrayList<>(Collections.singletonList(el.id()));
Collection<String> classNames = el.classNames();
Collection<String> roles = new ArrayList<>(Collections.singletonList(el.attr(ROLE_ATTR)));
if (el.tagName().equals(AREA_ELEMENT)) {
Optional<Element> mapElement = el.parents().stream().filter(e -> e.tagName().equals(MAP_ELEMENT)).findFirst();
if (mapElement.isPresent()) {
classNames.addAll(mapElement.get().classNames());
ids.add(mapElement.get().id());
roles.add(mapElement.get().attr(ROLE_ATTR));
}
}
// marker element selection.
if (CollectionUtils.isNotEmpty(ids) || CollectionUtils.isNotEmpty(classNames) || CollectionUtils.isNotEmpty(roles)) {
if (checkAttributeBelongsToMarkerList(ids, classNames, roles, markerList)) {
selectionWithMarkerHandler.add(el);
iter.remove();
}
// removed from the global collection
if (checkAttributeBelongsToMarkerList(ids, classNames, roles, inverseMarkerList)) {
iter.remove();
}
}
}
}
Aggregations