Search in sources :

Example 16 with SimpleElementSelector

use of org.asqatasun.rules.elementselector.SimpleElementSelector in project Asqatasun by Asqatasun.

the class AbstractDownloadableLinkRuleImplementation method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // invoke getElementChecker instead of super.check() to use local
    // collection of elements
    setServicesToChecker(getElementChecker());
    getElementChecker().check(sspHandler, linkWithSimpleExtension, testSolutionHandler);
    TestSolution checkerSolution = testSolutionHandler.getTestSolution();
    if (checkerSolution.equals(TestSolution.NOT_APPLICABLE) && !getElements().isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
        sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
        return;
    }
    if (checkerSolution.equals(TestSolution.PASSED)) {
        // the test result is NMI
        if (getElements().get().size() > linkWithSimpleExtension.get().size()) {
            testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
            sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
            return;
        }
        // we search whether the page contains form, if yes, the result 
        // is nmi, if not, the test is not applicable
        ElementHandler<Element> formHandler = new ElementHandlerImpl();
        new SimpleElementSelector(FORM_ELEMENT).selectElements(sspHandler, formHandler);
        if (formHandler.isEmpty()) {
            testSolutionHandler.cleanTestSolutions();
            testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        } else {
            testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
            sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_DOWNLOADABLE_DOCUMENT_FROM_FORM_MSG, this.getTest().getCode()));
        }
    }
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Example 17 with SimpleElementSelector

use of org.asqatasun.rules.elementselector.SimpleElementSelector in project Asqatasun by Asqatasun.

the class Rgaa22Rule09081 method select.

@Override
protected void select(SSPHandler sspHandler) {
    super.select(sspHandler);
    new SimpleElementSelector(ELEMENT_WITH_LANG_ATTR_CSS_LIKE_QUERY).selectElements(sspHandler, elementWithLang);
    if (elementWithLang.isEmpty()) {
        return;
    }
    new SimpleElementSelector(ELEMENT_WITHOUT_LANG_ATTR_CSS_LIKE_QUERY).selectElements(sspHandler, elementWithoutLang);
    removeElementWithParentWithLangAttr(elementWithoutLang);
}
Also used : SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Example 18 with SimpleElementSelector

use of org.asqatasun.rules.elementselector.SimpleElementSelector in project Asqatasun by Asqatasun.

the class Rgaa22Rule06021 method select.

@Override
protected void select(SSPHandler sspHandler) {
    ElementHandler<Element> tmpElHandler = new ElementHandlerImpl();
    /* the image link element selector */
    LinkElementSelector linkElementSelector = new LinkElementSelector(false);
    linkElementSelector.selectElements(sspHandler, tmpElHandler);
    for (Element el : linkElementSelector.getDecidableElements().get()) {
        if (doesElementHaveRequestedTargetAttribute(el)) {
            imageLinks.add(el);
        }
    }
    LinkElementSelector compositeLinkElementSelector = new CompositeLinkElementSelector(false, false);
    tmpElHandler.clean();
    compositeLinkElementSelector.selectElements(sspHandler, tmpElHandler);
    for (Element el : compositeLinkElementSelector.getDecidableElements().get()) {
        if (doesElementHaveRequestedTargetAttribute(el)) {
            imageLinks.add(el);
        }
    }
    linkSelected = imageLinks.get().size();
    ElementSelector formElementSelector = new SimpleElementSelector(HtmlElementStore.FORM_ELEMENT);
    tmpElHandler.clean();
    formElementSelector.selectElements(sspHandler, tmpElHandler);
    for (Element el : tmpElHandler.get()) {
        if (doesElementHaveRequestedTargetAttribute(el)) {
            formWithTargetHandler.add(el);
        }
    }
}
Also used : CompositeLinkElementSelector(org.asqatasun.rules.elementselector.CompositeLinkElementSelector) LinkElementSelector(org.asqatasun.rules.elementselector.LinkElementSelector) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) CompositeLinkElementSelector(org.asqatasun.rules.elementselector.CompositeLinkElementSelector) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) ElementSelector(org.asqatasun.rules.elementselector.ElementSelector) CompositeLinkElementSelector(org.asqatasun.rules.elementselector.CompositeLinkElementSelector) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) LinkElementSelector(org.asqatasun.rules.elementselector.LinkElementSelector)

Example 19 with SimpleElementSelector

use of org.asqatasun.rules.elementselector.SimpleElementSelector in project Asqatasun by Asqatasun.

the class Rgaa30Rule060501 method select.

@Override
protected void select(SSPHandler sspHandler) {
    ElementSelector elementsSelector = new SimpleElementSelector(NOT_ANCHOR_LINK_CSS_LIKE_QUERY);
    elementsSelector.selectElements(sspHandler, linksHandler);
    for (Element el : linksHandler.get()) {
        if (StringUtils.isBlank(el.text()) && el.getElementsByAttributeValueMatching(ALT_ATTR, "^(?=\\s*\\S).*$").isEmpty()) {
            emptyLinksHandler.add(el);
        }
    }
}
Also used : Element(org.jsoup.nodes.Element) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) ElementSelector(org.asqatasun.rules.elementselector.ElementSelector) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Example 20 with SimpleElementSelector

use of org.asqatasun.rules.elementselector.SimpleElementSelector in project Asqatasun by Asqatasun.

the class Rgaa30Rule110101 method select.

@Override
protected void select(SSPHandler sspHandler) {
    // Selection of all the input form elements of the page
    ElementSelector elementSelector = new SimpleElementSelector(FORM_ELEMENT_CSS_LIKE_QUERY);
    elementSelector.selectElements(sspHandler, inputFormHandler);
    // the selection of the input form elements without label is initialised
    // with all the elements of the page, some elements will be removed later
    inputFormWithoutLabelHandler.addAll(inputFormHandler.get());
    // selection of the input form elements with explicit label
    ElementHandler<Element> inputFormLabelHandler = new ElementHandlerImpl();
    ElementSelector explicitLabelSelector = new InputFormElementWithExplicitLabelSelector(inputFormHandler);
    explicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
    // remove all the input form elements with explicit label from 
    // the selection of the input form elements without label
    inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
    // selection of the input form with inplicit label
    ElementSelector inplicitLabelSelector = new InputFormElementWithInplicitLabelSelector(inputFormHandler);
    inplicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
    // remove all the input form elements with inplicit label from 
    // the selection of the input form elements without label
    inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
    // selection of the input form elements with explicit label
    ElementHandler<Element> inputFormWithAttrHandler = new ElementHandlerImpl();
    for (Element el : inputFormWithoutLabelHandler.get()) {
        if (el.hasAttr(TITLE_ATTR) || el.hasAttr(ARIA_LABEL_ATTR) || el.hasAttr(ARIA_LABELLEDBY_ATTR)) {
            inputFormWithAttrHandler.add(el);
        }
    }
    // remove all the input form elements with title, aria-label, or 
    // aria-labelledby attributes from the selection of the input form 
    // elements without label
    inputFormWithoutLabelHandler.removeAll(inputFormWithAttrHandler.get());
}
Also used : InputFormElementWithExplicitLabelSelector(org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector) InputFormElementWithInplicitLabelSelector(org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) ElementSelector(org.asqatasun.rules.elementselector.ElementSelector) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Aggregations

SimpleElementSelector (org.asqatasun.rules.elementselector.SimpleElementSelector)28 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)16 Element (org.jsoup.nodes.Element)13 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)9 Nomenclature (org.asqatasun.entity.reference.Nomenclature)4 InputFormElementWithExplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector)4 InputFormElementWithInplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector)3 TestSolution (org.asqatasun.entity.audit.TestSolution)1 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)1 CompositeLinkElementSelector (org.asqatasun.rules.elementselector.CompositeLinkElementSelector)1 LinkElementSelector (org.asqatasun.rules.elementselector.LinkElementSelector)1 MultipleElementSelector (org.asqatasun.rules.elementselector.MultipleElementSelector)1