Search in sources :

Example 21 with TextNode

use of org.jsoup.nodes.TextNode in project ez-vcard by mangstadt.

the class HCardElementTest method assertTextNodeValue.

private static void assertTextNodeValue(Node node, String expected) {
    TextNode textNode = (TextNode) node;
    String actual = textNode.text();
    assertEquals(expected, actual);
}
Also used : TextNode(org.jsoup.nodes.TextNode)

Example 22 with TextNode

use of org.jsoup.nodes.TextNode in project ez-vcard by mangstadt.

the class HCardElement method visitForValue.

private void visitForValue(Element element, StringBuilder value) {
    for (Node node : element.childNodes()) {
        if (node instanceof Element) {
            Element e = (Element) node;
            if (e.classNames().contains("type")) {
                // ignore "type" elements
                continue;
            }
            if ("br".equals(e.tagName())) {
                // convert "<br>" to a newline
                value.append(NEWLINE);
                continue;
            }
            if ("del".equals(e.tagName())) {
                // skip "<del>" tags
                continue;
            }
            visitForValue(e, value);
            continue;
        }
        if (node instanceof TextNode) {
            TextNode t = (TextNode) node;
            value.append(t.text());
            continue;
        }
    }
}
Also used : Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode)

Example 23 with TextNode

use of org.jsoup.nodes.TextNode in project Java-readability by basis-technology-corp.

the class XmlDataMap method recurse.

private void recurse(Element element) {
    ElementAction action = classifyElement(element);
    if (action == ElementAction.Whitespace || action == ElementAction.Sentence) {
        appendSpace();
    }
    for (Node childNode : element.childNodes()) {
        // though we could use canonical XML to get rid of them.
        if (childNode instanceof TextNode && action != ElementAction.Banned) {
            TextNode textContent = (TextNode) childNode;
            String textString = textContent.text();
            append(textContent, textString);
        } else if (childNode instanceof Element) {
            recurse((Element) childNode);
        }
    }
    if (action == ElementAction.Whitespace) {
        appendSpace();
    } else if (action == ElementAction.Sentence) {
        appendPeriod();
    } else if (action == ElementAction.Mark) {
        Mark mark = new Mark();
        mark.setOffset(pcDataOffset);
        mark.setTag(element.tagName());
    }
}
Also used : Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode)

Example 24 with TextNode

use of org.jsoup.nodes.TextNode in project Asqatasun by Asqatasun.

the class DeepTextWithoutAltElementBuilder method buildTextFromElement.

@Override
public String buildTextFromElement(Element element) {
    StringBuilder elementText = new StringBuilder();
    for (Node child : element.childNodes()) {
        if (child instanceof TextNode && !((TextNode) child).isBlank()) {
            elementText.append(SPACER);
            elementText.append(StringUtils.trim(((TextNode) child).text()));
        } else if (child instanceof Element) {
            elementText.append(SPACER);
            elementText.append(buildTextFromElement((Element) child));
        }
    }
    if (StringUtils.isBlank(StringUtils.trim(elementText.toString()))) {
        if (StringUtils.isNotBlank(element.attr(TITLE_ATTR))) {
            return element.attr(TITLE_ATTR);
        }
    }
    return elementText.toString();
}
Also used : Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode)

Example 25 with TextNode

use of org.jsoup.nodes.TextNode in project Asqatasun by Asqatasun.

the class DeepTextElementBuilder method buildTextFromElement.

@Override
public String buildTextFromElement(Element element) {
    StringBuilder elementText = new StringBuilder();
    if (element.hasAttr(ALT_ATTR)) {
        elementText.append(SPACER);
        elementText.append(altAttrTextBuilder.buildTextFromElement(element));
    }
    for (Node child : element.childNodes()) {
        if (child instanceof TextNode && !((TextNode) child).isBlank()) {
            elementText.append(SPACER);
            elementText.append(StringUtils.trim(((TextNode) child).text()));
        } else if (child instanceof Element) {
            elementText.append(SPACER);
            elementText.append(buildTextFromElement((Element) child));
        }
    }
    return StringUtils.trim(elementText.toString());
}
Also used : Node(org.jsoup.nodes.Node) TextNode(org.jsoup.nodes.TextNode) Element(org.jsoup.nodes.Element) TextNode(org.jsoup.nodes.TextNode)

Aggregations

TextNode (org.jsoup.nodes.TextNode)52 Element (org.jsoup.nodes.Element)41 Node (org.jsoup.nodes.Node)37 Document (org.jsoup.nodes.Document)19 ArrayList (java.util.ArrayList)16 Elements (org.jsoup.select.Elements)14 IOException (java.io.IOException)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 JSONException (org.json.JSONException)6 Copy (de.geeksfactory.opacclient.objects.Copy)5 DetailedItem (de.geeksfactory.opacclient.objects.DetailedItem)5 HashMap (java.util.HashMap)5 NameValuePair (org.apache.http.NameValuePair)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 Test (org.junit.jupiter.api.Test)5 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)4 Detail (de.geeksfactory.opacclient.objects.Detail)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URI (java.net.URI)4 Matcher (java.util.regex.Matcher)4