Example usage for org.jsoup.nodes Element hasText

List of usage examples for org.jsoup.nodes Element hasText

Introduction

In this page you can find the example usage for org.jsoup.nodes Element hasText.

Prototype

public boolean hasText() 

Source Link

Document

Test if this element has any text content (that is not just whitespace).

Usage

From source file:org.sakaiproject.nakamura.files.migrator.PageMigrator.java

boolean isEmpty(Element htmlElement) {
    // filter out TinyMCE instances
    htmlElement.select(".mceEditor").remove();
    String htmlContent = htmlElement.text().trim();
    String[] elementNames = new String[] { "img", "iframe", "frame", "input", "select", "option" };
    boolean containsElement = false;
    for (String elementName : elementNames) {
        if (!htmlElement.select(elementName).isEmpty()) {
            containsElement = true;//  w w w  . j  a  v  a2 s.  c  o m
        }
    }
    return !(htmlElement.hasText() || containsElement);
}

From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java

/**
 * Images placed in a link should have a non-empty text alternative to enable visitors who do not see the image to
 * follow the link./*from   w  w  w .j av a2s . c om*/
 */
public void validateRpd7s4() {
    for (Element link : getElements(ELEM_LINK)) {

        // Look for images in the link.
        boolean hasNonEmptyAlt = false;
        for (Element child : getChildren(link, ELEM_IMG)) {
            if (StringUtils.isNotEmpty(getAttributeValue(child, ATTR_ALT))) {
                hasNonEmptyAlt = true;
            }
        }

        // Look for text in the link.
        boolean hasText = false;
        for (Element linkChild : link.getAllElements()) {
            if (linkChild.hasText()) {
                hasText = true;
            }
        }

        // Images in links must have a not empty alt attribute if there's no text in the link.
        assertTrue(Type.ERROR, "rpd7s4.links", hasNonEmptyAlt || hasText);
    }
}

From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java

/**
 * Do not describe the mechanism behind following a link.
 *//*  w w  w .j av a2 s.c  om*/
public void validateRpd8s1() {
    List<String> forbiddenLinkTexts = Arrays.asList(messages.getString("rpd8s1.forbiddenLinkTexts").split(","));

    for (Element link : getElements(ELEM_LINK)) {
        for (Element linkChild : link.getAllElements()) {
            if (linkChild.hasText()) {
                for (String forbiddenLinkText : forbiddenLinkTexts) {
                    assertFalse(Type.ERROR, "rpd8s1.link",
                            StringUtils.containsIgnoreCase(linkChild.text(), forbiddenLinkText));
                }
            }
        }
    }
}