Search in sources :

Example 71 with ElementHandlerImpl

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

the class ImageElementSelectorTest method testSelectElements2_1.

/**
     * Test of selectElements method, of class ImageElementSelector.
     */
public void testSelectElements2_1() {
    LOGGER.debug("selectElements2-1");
    Document doc = null;
    try {
        doc = Jsoup.parse(new File("src/test/resources/images/image-link-1.html"), Charset.defaultCharset().displayName());
    } catch (IOException ex) {
    }
    initMockContext(HtmlElementStore.IMG_ELEMENT, doc);
    ElementHandler<Element> elementHandler = new ElementHandlerImpl();
    ImageElementSelector instance = new ImageElementSelector(HtmlElementStore.IMG_ELEMENT, false, true);
    instance.selectElements(sspHandler, elementHandler);
    assertTrue(elementHandler.get().size() == 1);
    assertTrue(elementHandler.get().iterator().next().nodeName().equals(HtmlElementStore.IMG_ELEMENT));
    verifyMockContext();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) File(java.io.File)

Example 72 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl 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 73 with ElementHandlerImpl

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

the class Rgaa22Rule09081 method removeElementWithParentWithLangAttr.

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

Example 74 with ElementHandlerImpl

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

the class Rgaa22Rule06031 method select.

@Override
protected void select(SSPHandler sspHandler) {
    /* the image link element selector */
    LinkElementSelector compositeLinkElementSelector = new CompositeLinkElementSelector(false, true);
    ElementHandler<Element> elHandler = new ElementHandlerImpl();
    compositeLinkElementSelector.selectElements(sspHandler, elHandler);
    for (Element el : compositeLinkElementSelector.getDecidableElements().get()) {
        if (doesElementHaveRequestedTargetAttribute(el)) {
            compositeLinks.add(el);
        }
    }
    LinkElementSelector areaLinkElementSelector = new AreaLinkElementSelector(false);
    elHandler.clean();
    areaLinkElementSelector.selectElements(sspHandler, elHandler);
    for (Element el : areaLinkElementSelector.getDecidableElements().get()) {
        if (doesElementHaveRequestedTargetAttribute(el)) {
            compositeLinks.add(el);
        }
    }
}
Also used : AreaLinkElementSelector(org.asqatasun.rules.elementselector.AreaLinkElementSelector) CompositeLinkElementSelector(org.asqatasun.rules.elementselector.CompositeLinkElementSelector) AreaLinkElementSelector(org.asqatasun.rules.elementselector.AreaLinkElementSelector) LinkElementSelector(org.asqatasun.rules.elementselector.LinkElementSelector) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) CompositeLinkElementSelector(org.asqatasun.rules.elementselector.CompositeLinkElementSelector)

Example 75 with ElementHandlerImpl

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

the class Rgaa30Rule060301 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)

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