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