List of usage examples for org.jsoup.nodes Element hasAttr
public boolean hasAttr(String attributeKey)
From source file:org.asqatasun.rules.elementselector.LinkElementSelector.java
/** * /*w w w .j av a 2 s. co m*/ * @param linkElement * @param linkText * @return whether the current link have a context */ protected boolean doesLinkHaveContext(Element linkElement, String linkText) { // does the current link have a title attribute? if (considerTitleAsContext && linkElement.hasAttr(TITLE_ATTR) && !StringUtils.equalsIgnoreCase(linkElement.attr(TITLE_ATTR), linkText)) { return true; } if (linkElement.hasAttr(ARIA_LABEL_ATTR) && StringUtils.isNotBlank(linkElement.attr(ARIA_LABEL_ATTR))) { return true; } if (linkElement.hasAttr(ARIA_LABELLEDBY_ATTR) && StringUtils.isNotBlank(linkElement.attr(ARIA_LABELLEDBY_ATTR))) { return true; } // does the parent of the current link have some text? if (StringUtils.isNotBlank(linkElement.parent().ownText())) { return true; } // does the current element have a previous sibling of heading type? if (isOneOfPrecedingSiblingofHeadingType(linkElement)) { return true; } // does one of the parent of the current element have a previous sibling // of heading type or is found in the PARENT_CONTEXT_ELEMENTS list? for (Element parent : linkElement.parents()) { if (PARENT_CONTEXT_ELEMENTS.contains(parent.tagName()) || isOneOfPrecedingSiblingofHeadingType(parent)) { return true; } } return false; }
From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule03101.java
@Override protected void select(SSPHandler sspHandler) { super.select(sspHandler); // From the selected form elements, only keep the one without id // or with an id not unique on the page for (Element el : getElements().get()) { if (!el.hasAttr(ID_ATTR) || StringUtils.isEmpty(el.id().trim()) || CssLikeSelectorBuilder .getNumberOfElements(sspHandler, CssLikeSelectorBuilder.buildSelectorFromId(el.id())) >= 2) { elementsWithoutUniqueId.add(el); }/*www. j a va 2 s .co m*/ } }
From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule06021.java
/** * /*w ww . j a v a2 s. co m*/ * @param element * @return */ private boolean doesElementHaveRequestedTargetAttribute(Element element) { if (!element.hasAttr(TARGET_ATTR)) { return false; } String targetValue = element.attr(TARGET_ATTR); return !(StringUtils.equalsIgnoreCase(targetValue, TOP_TARGET_VALUE) || StringUtils.equalsIgnoreCase(targetValue, PARENT_TARGET_VALUE) || StringUtils.equalsIgnoreCase(targetValue, SELF_TARGET_VALUE)); }
From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule06031.java
/** * //from w w w .java 2 s .co m * @param element * @return */ private boolean doesElementHaveRequestedTargetAttribute(Element element) { if (!element.hasAttr(TARGET_ATTR)) { return false; } String targetValue = element.attr(TARGET_ATTR); if (StringUtils.equalsIgnoreCase(targetValue, TOP_TARGET_VALUE) || StringUtils.equalsIgnoreCase(targetValue, PARENT_TARGET_VALUE) || StringUtils.equalsIgnoreCase(targetValue, SELF_TARGET_VALUE)) { return false; } return true; }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010204.java
/** * /*from w w w . j a va2 s. c o m*/ * @param svgElements * @param svgElementsWithoutRoleImage * @param ariaAttrOnSvgOrChild * @param svgElementsWithDescOrTitleChild * @param titleAttrOnSvgOrChild */ private void extractMalformedPatternDetectedElements(ElementHandler<Element> svgElements, ElementHandler<Element> svgElementsWithoutRoleImage, ElementHandler<Element> ariaAttrOnSvgOrChild, ElementHandler<Element> svgElementsWithDescOrTitleChild, ElementHandler<Element> titleAttrOnSvgOrChild, ElementHandler<Element> wellFormedSvgElements) { for (Element element : svgElements.get()) { boolean patternDetected = false; if (!StringUtils.equalsIgnoreCase(element.attr(ROLE_ATTR), "img")) { svgElementsWithoutRoleImage.add(element); patternDetected = true; } if (element.hasAttr(ARIA_LABEL_ATTR) || element.hasAttr(ARIA_LABELLEDBY_ATTR) || element.hasAttr(ARIA_DESCRIBEDBY_ATTR) || !element.select(ARIA_DESCRIBEDBY_CSS_LIKE_QUERY + "," + ARIA_LABEL_CSS_LIKE_QUERY + "," + ARIA_LABELLEDBY_CSS_LIKE_QUERY).isEmpty()) { ariaAttrOnSvgOrChild.add(element); patternDetected = true; } if (!element.select(NOT_EMPTY_ARIA_TITLE_CSS_LIKE_QUERY + "," + NOT_EMPTY_ARIA_DESC_CSS_LIKE_QUERY) .isEmpty()) { svgElementsWithDescOrTitleChild.add(element); patternDetected = true; } if (element.hasAttr(TITLE_ELEMENT) || !element.select("[title]").isEmpty()) { titleAttrOnSvgOrChild.add(element); patternDetected = true; } if (wellFormedSvgElements != null && !patternDetected) { wellFormedSvgElements.add(element); } } }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010301.java
@Override protected void select(SSPHandler sspHandler) { super.select(sspHandler); Iterator<Element> iter = getSelectionWithoutMarkerHandler().get().iterator(); // The elements with a longdesc attribute are seen as informative. // They are added to the selection with marker while (iter.hasNext()) { Element el = iter.next(); if (el.hasAttr(LONGDESC_ATTR)) { iter.remove();/*from ww w . j av a 2 s . c om*/ getSelectionWithMarkerHandler().add(el); } } }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010306.java
/** * /* ww w . j av a 2 s . co m*/ * @param element * @return whether the aria label exists and is empty */ private boolean isRoleImagePresent(Element element) { return element.hasAttr(ROLE_ATTR) && StringUtils.equalsIgnoreCase("img", element.attr(ROLE_ATTR)); }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010306.java
/** * /* w w w .j a v a2s . c o m*/ * @param element * @return whether the aria label exists and is empty */ private boolean isAriaLabelExistsAndEmpty(Element element) { return element.hasAttr(ARIA_LABEL_ATTR) && StringUtils.isEmpty(getAriaLabelAttrText(element)); }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010306.java
/** * /*from w w w . ja v a2s . co m*/ * @param element * @return whether the aria label exists and is not empty */ private boolean isAriaLabelExistsAndNotEmpty(Element element) { return element.hasAttr(ARIA_LABEL_ATTR) && StringUtils.isNotEmpty(getAriaLabelAttrText(element)); }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule010306.java
/** * /*from www.j a v a 2 s. c om*/ * @param element * @return whether the aria label and the title are present, not empty * and identical */ private boolean isTitleExistsAndNotEmpty(Element element) { return element.hasAttr(TITLE_ATTR) && StringUtils.isNotEmpty(getTitleAttrText(element)); }