use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110102 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();
}
}
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110103 method check.
@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
/* If the page has no input form element, the test is not applicable */
if (inputFormMap.entrySet().isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) {
/* The attribute Emptiness Checker. Keep default value i.e failed
when attribute is empty
*/
ElementChecker attributeEmptinessChecker = new TextEmptinessChecker(new TextAttributeOfElementBuilder(ARIA_LABELLEDBY_ATTR), ARIA_LABELLEDBY_EMPTY_MSG, null);
attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler);
ElementHandler<Element> inputWithoutLabel = new ElementHandlerImpl();
ElementHandler<Element> notUniqueLabel = new ElementHandlerImpl();
for (Element el : entry.getValue().get()) {
if (StringUtils.isNotEmpty(el.attr(ARIA_LABELLEDBY_ATTR))) {
ElementHandler<Element> labelHandler = new ElementHandlerImpl();
labelHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromAttributeTypeAndValue(ID_ATTR, el.attr(ARIA_LABELLEDBY_ATTR))));
if (labelHandler.get().isEmpty()) {
inputWithoutLabel.add(el);
} else if (labelHandler.get().size() > 1) {
notUniqueLabel.add(el);
notUniqueLabel.addAll(labelHandler.get());
}
}
}
/* Check if the form element has a label associated */
ElementChecker elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITHOUT_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, inputWithoutLabel, testSolutionHandler);
/* Check if the id attr of the label associated to the form element is unique */
elementPresenceChecker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, FORM_ELEMENT_WITH_NOT_UNIQUE_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
elementPresenceChecker.check(sspHandler, notUniqueLabel, testSolutionHandler);
}
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule110103 method putInputElementHandlerIntoTheMap.
/**
* This method linked each input on a page to its form in a map.
*/
private void putInputElementHandlerIntoTheMap() {
for (Element el : inputElementHandler.get()) {
Element tmpElement = el.parent();
while (StringUtils.isNotBlank(tmpElement.tagName())) {
if (tmpElement.tagName().equals(FORM_ELEMENT)) {
if (inputFormMap.containsKey(tmpElement)) {
inputFormMap.get(tmpElement).add(el);
} else {
ElementHandler<Element> inputElement = new ElementHandlerImpl();
inputElement.add(el);
inputFormMap.put(tmpElement, inputElement);
}
break;
}
tmpElement = tmpElement.parent();
}
}
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule100102 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_V2);
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_V2);
ElementHandler<Element> ehHeightAttrNotImg = new ElementHandlerImpl();
secHeightAttrNotImg.selectElements(sspHandler, ehHeightAttrNotImg);
attrElementHandlerMap.put(HEIGHT_ATTR, ehHeightAttrNotImg);
}
use of org.asqatasun.ruleimplementation.ElementHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa32016Rule100102 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_V2);
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_V2);
ElementHandler<Element> ehHeightAttrNotImg = new ElementHandlerImpl();
secHeightAttrNotImg.selectElements(sspHandler, ehHeightAttrNotImg);
attrElementHandlerMap.put(HEIGHT_ATTR, ehHeightAttrNotImg);
}
Aggregations