Example usage for org.jsoup.nodes Element parents

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

Introduction

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

Prototype

public Elements parents() 

Source Link

Document

Get this element's parent and ancestors, up to the document root.

Usage

From source file:org.opens.tanaguru.rules.elementselector.ImageElementSelector.java

/**
 * /*www . j av  a2s.c  o m*/
 * @param elementHandler 
 */
private void excludeLinksFromSelection(ElementHandler<Element> elementHandler) {
    if (!excludeCompositeLink && !excludeImageLink) {
        return;
    }
    ElementHandler linkHandler = new ElementHandlerImpl();
    for (Element el : elementHandler.get()) {
        Element link = el.parents().select(A_ELEMENT).first();
        if (excludeImageLink && isImageLink(link, el)) {
            linkHandler.add(el);
        } else if (excludeCompositeLink && isCompositeLink(link, el)) {
            linkHandler.add(el);
        }
    }
    elementHandler.removeAll(linkHandler);
}

From source file:org.opens.tanaguru.rules.elementselector.LinkElementSelector.java

/**
 * /*from www . ja  v a  2 s . c om*/
 * @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.equals(linkElement.attr(TITLE_ATTR), linkText)) {
        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;
}