Example usage for org.jsoup.nodes Node hasAttr

List of usage examples for org.jsoup.nodes Node hasAttr

Introduction

In this page you can find the example usage for org.jsoup.nodes Node hasAttr.

Prototype

public boolean hasAttr(String attributeKey) 

Source Link

Document

Test if this element has an attribute.

Usage

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());
}