Search in sources :

Example 11 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.

the class Rgaa32016Rule060303 method testTitleAttributeLink.

/**
     * 
     * @param sspHandler
     * @param el
     * @param linkText
     * @return 
     */
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
    // content identical to the link text, returns not applicable.
    if (!el.hasAttr(TITLE_ATTR)) {
        return TestSolution.NOT_APPLICABLE;
    }
    String attrValue = el.attr(TITLE_ATTR);
    if (StringUtils.isBlank(attrValue)) {
        return TestSolution.NOT_APPLICABLE;
    }
    if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
        return TestSolution.NOT_APPLICABLE;
    }
    ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
    TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
    titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
    return tsHandler.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 12 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.

the class Rgaa32016Rule080301 method removeElementWithParentWithLangAttr.

/**
     * Remove elements from the current elementHandler when an element has a
     * parent with a lang attribute
     *
     * @param elementHandler
     */
private void removeElementWithParentWithLangAttr() {
    if (elementWithLang.isEmpty()) {
        return;
    }
    ElementHandler<Element> elementWithParentWithLang = new ElementHandlerImpl();
    for (Element el : elementWithoutLang.get()) {
        if (isElementHasParentWithLang(el)) {
            elementWithParentWithLang.add(el);
        }
    }
    elementWithoutLang.removeAll(elementWithParentWithLang);
    elementWithLang.addAll(elementWithParentWithLang.get());
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl)

Example 13 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.

the class Rgaa32016Rule060301 method testTitleAttributeLink.

/**
     * 
     * @param sspHandler
     * @param el
     * @param linkText
     * @return 
     */
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
    // content identical to the link text, returns not applicable.
    if (!el.hasAttr(TITLE_ATTR)) {
        return TestSolution.NOT_APPLICABLE;
    }
    String attrValue = el.attr(TITLE_ATTR);
    if (StringUtils.isBlank(attrValue)) {
        return TestSolution.NOT_APPLICABLE;
    }
    if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
        return TestSolution.NOT_APPLICABLE;
    }
    ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
    TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
    titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
    return tsHandler.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 14 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.

the class Rgaa32016Rule060301 method testLink.

/**
     * 
     * @param sspHandler
     * @param el
     * @return 
     */
private TestSolution testLink(SSPHandler sspHandler, Element el) {
    ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
    TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
    // reset the service for each tested element. We use the collection 
    // handled by the service to feed the local collection of remarks
    prs.resetService();
    // check the pertinence of the link
    getDecidableElementsChecker().check(sspHandler, elHandler, tsHandler);
    // get the processRemark for eventually override it with the result
    // returned by the title pertinence checker
    ProcessRemark remark = prs.getRemarkList().iterator().next();
    // to nmi but the inverse is impossible.
    if (tsHandler.getTestSolution().equals(TestSolution.FAILED)) {
        // check the pertinence of the title of the link
        String linkText = getDecidableElementsChecker().getTextElementBuilder().buildTextFromElement(el);
        if (testTitleAttributeLink(sspHandler, el, linkText).equals(TestSolution.NEED_MORE_INFO)) {
            //override result (evidence element have already been collected
            remark.setIssue(TestSolution.NEED_MORE_INFO);
            remark.setMessageCode(CHECK_LINK_PERTINENCE_MSG);
            remarks.add(remark);
            return TestSolution.NEED_MORE_INFO;
        }
    }
    remarks.add(remark);
    return tsHandler.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) ProcessRemark(org.asqatasun.entity.audit.ProcessRemark)

Example 15 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.

the class Rgaa32016Rule110102 method putLabelElementHandlerIntoTheMap.

/**
     * This method linked each label which have an input child on a page to its
     * form in a map.
     */
private void putLabelElementHandlerIntoTheMap() {
    for (Element el : labelElementHandler.get()) {
        Element tmpElement = el.parent();
        while (tmpElement != null && StringUtils.isNotBlank(tmpElement.tagName())) {
            if (tmpElement.tagName().equals(FORM_ELEMENT)) {
                if (labelFormMap.containsKey(tmpElement)) {
                    Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY);
                    if (!els.isEmpty()) {
                        labelFormMap.get(tmpElement).add(el);
                    }
                } else {
                    Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY);
                    if (!els.isEmpty()) {
                        ElementHandler<Element> labelElement = new ElementHandlerImpl();
                        labelElement.add(el);
                        labelFormMap.put(tmpElement, labelElement);
                    }
                }
                break;
            }
            tmpElement = tmpElement.parent();
        }
    }
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) Elements(org.jsoup.select.Elements)

Aggregations

ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)88 Element (org.jsoup.nodes.Element)87 Document (org.jsoup.nodes.Document)51 File (java.io.File)49 IOException (java.io.IOException)44 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)14 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)14 SimpleElementSelector (org.asqatasun.rules.elementselector.SimpleElementSelector)9 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)5 Nomenclature (org.asqatasun.entity.reference.Nomenclature)4 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)4 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)4 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TextEmptinessChecker (org.asqatasun.rules.elementchecker.text.TextEmptinessChecker)3 InputFormElementWithExplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector)3 InputFormElementWithInplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector)3