Search in sources :

Example 16 with ElementHandlerImpl

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

the class Aw22Rule10012 method select.

@Override
protected void select(SSPHandler sspHandler) {
    totalNumberOfElements = sspHandler.getTotalNumberOfElements();
    // retrieve element from the nomenclature
    Nomenclature deprecatedHtmlAttr = nomenclatureLoaderService.loadByCode(PRESENTATION_ATTR_NOM);
    for (String deprecatedAttr : deprecatedHtmlAttr.getValueList()) {
        SimpleElementSelector sec = new SimpleElementSelector(buildQuery(deprecatedAttr));
        ElementHandler<Element> eh = new ElementHandlerImpl();
        sec.selectElements(sspHandler, eh);
        attrElementHandlerMap.put(deprecatedAttr, eh);
    }
    // elements with width attribute that are not img
    SimpleElementSelector secWidthAttrNotImg = new SimpleElementSelector(ELEMENT_WITH_WITDH_ATTR_NOT_IMG);
    ElementHandler<Element> ehWithAttrNotImg = new ElementHandlerImpl();
    secWidthAttrNotImg.selectElements(sspHandler, ehWithAttrNotImg);
    attrElementHandlerMap.put(WIDTH_ATTR, ehWithAttrNotImg);
    // elements with width attribute that are not img
    SimpleElementSelector secHeightAttrNotImg = new SimpleElementSelector(ELEMENT_WITH_HEIGHT_ATTR_NOT_IMG);
    ElementHandler<Element> ehHeightAttrNotImg = new ElementHandlerImpl();
    secHeightAttrNotImg.selectElements(sspHandler, ehHeightAttrNotImg);
    attrElementHandlerMap.put(HEIGHT_ATTR, ehHeightAttrNotImg);
}
Also used : Nomenclature(org.asqatasun.entity.reference.Nomenclature) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Example 17 with ElementHandlerImpl

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

the class Aw22Rule06031 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 18 with ElementHandlerImpl

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

the class Aw22Rule06034 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 19 with ElementHandlerImpl

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

the class Aw22Rule08031 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 20 with ElementHandlerImpl

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

the class Rgaa22Rule07081 method select.

@Override
protected void select(SSPHandler sspHandler) {
    super.select(sspHandler);
    // retrieve element from the nomenclature
    Nomenclature deprecatedHtmlTags = nomenclatureLoaderService.loadByCode(PRESENTATION_TAG_NOM);
    // add each element of the nomenclature to the selector
    MultipleElementSelector mes = new MultipleElementSelector();
    for (String deprecatedTag : deprecatedHtmlTags.getValueList()) {
        mes.addCssQuery(deprecatedTag.toLowerCase());
    }
    mes.selectElements(sspHandler, deprecatedElementHandler);
    // retrieve element from the nomenclature
    Nomenclature deprecatedHtmlAttr = nomenclatureLoaderService.loadByCode(PRESENTATION_ATTR_NOM);
    for (String deprecatedAttr : deprecatedHtmlAttr.getValueList()) {
        SimpleElementSelector sec = new SimpleElementSelector(buildQuery(deprecatedAttr));
        ElementHandler eh = new ElementHandlerImpl();
        sec.selectElements(sspHandler, eh);
        attrElementHandlerMap.put(deprecatedAttr, eh);
    }
}
Also used : Nomenclature(org.asqatasun.entity.reference.Nomenclature) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) ElementHandler(org.asqatasun.ruleimplementation.ElementHandler) MultipleElementSelector(org.asqatasun.rules.elementselector.MultipleElementSelector)

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