List of usage examples for org.jsoup.nodes Node hasAttr
public boolean hasAttr(String attributeKey)
From source file:org.opens.tanaguru.rules.elementchecker.helper.RuleCheckHelper.java
/** * Extract the text of an image link/*from w w w. j av a 2 s.com*/ * * @param element * @return */ public static String extractImageLinkText(Element element) { StringBuilder strb = new StringBuilder(); for (Node node : element.childNodes()) { if (node instanceof TextNode) { strb.append(((TextNode) node).text()); } else if (node instanceof Element && StringUtils.equalsIgnoreCase(node.nodeName(), HtmlElementStore.IMG_ELEMENT) && node.hasAttr(ALT_ATTR)) { strb.append(node.attr(ALT_ATTR).trim()); } else if (node instanceof Element) { strb.append(extractImageLinkText((Element) node)); } } return StringUtil.normaliseWhitespace(strb.toString().trim()); }