Search in sources :

Example 1 with MAP_ELEMENT

use of org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.MAP_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();
            }
        }
    }
}
Also used : ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker) ElementSelector(org.asqatasun.rules.elementselector.ElementSelector) java.util(java.util) CollectionUtils(org.apache.commons.collections.CollectionUtils) Element(org.jsoup.nodes.Element) ROLE_ATTR(org.asqatasun.rules.keystore.AttributeStore.ROLE_ATTR) AREA_ELEMENT(org.asqatasun.rules.keystore.HtmlElementStore.AREA_ELEMENT) Nonnull(javax.annotation.Nonnull) StringUtils(org.apache.commons.lang3.StringUtils) SSPHandler(org.asqatasun.processor.SSPHandler) MAP_ELEMENT(org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.MAP_ELEMENT) Parameter(org.asqatasun.entity.parameterization.Parameter) Element(org.jsoup.nodes.Element)

Aggregations

java.util (java.util)1 Nonnull (javax.annotation.Nonnull)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 SSPHandler (org.asqatasun.processor.SSPHandler)1 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)1 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)1 ROLE_ATTR (org.asqatasun.rules.keystore.AttributeStore.ROLE_ATTR)1 AREA_ELEMENT (org.asqatasun.rules.keystore.HtmlElementStore.AREA_ELEMENT)1 Element (org.jsoup.nodes.Element)1 MAP_ELEMENT (org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.MAP_ELEMENT)1