Search in sources :

Example 1 with NodeTraversor

use of org.jsoup.select.NodeTraversor in project jsoup by jhy.

the class Cleaner method copySafeNodes.

private int copySafeNodes(Element source, Element dest) {
    CleaningVisitor cleaningVisitor = new CleaningVisitor(source, dest);
    NodeTraversor traversor = new NodeTraversor(cleaningVisitor);
    traversor.traverse(source);
    return cleaningVisitor.numDiscarded;
}
Also used : NodeTraversor(org.jsoup.select.NodeTraversor)

Example 2 with NodeTraversor

use of org.jsoup.select.NodeTraversor in project jsoup by jhy.

the class Node method traverse.

/**
     * Perform a depth-first traversal through this node and its descendants.
     * @param nodeVisitor the visitor callbacks to perform on each node
     * @return this node, for chaining
     */
public Node traverse(NodeVisitor nodeVisitor) {
    Validate.notNull(nodeVisitor);
    NodeTraversor traversor = new NodeTraversor(nodeVisitor);
    traversor.traverse(this);
    return this;
}
Also used : NodeTraversor(org.jsoup.select.NodeTraversor)

Example 3 with NodeTraversor

use of org.jsoup.select.NodeTraversor in project jsoup by jhy.

the class HtmlToPlainText method getPlainText.

/**
     * Format an Element to plain-text
     * @param element the root element to format
     * @return formatted text
     */
public String getPlainText(Element element) {
    FormattingVisitor formatter = new FormattingVisitor();
    NodeTraversor traversor = new NodeTraversor(formatter);
    // walk the DOM, and call .head() and .tail() for each node
    traversor.traverse(element);
    return formatter.toString();
}
Also used : NodeTraversor(org.jsoup.select.NodeTraversor)

Example 4 with NodeTraversor

use of org.jsoup.select.NodeTraversor in project flow by vaadin.

the class TemplateParser method collectIncludeNodes.

private static List<TextNode> collectIncludeNodes(Element element) {
    List<TextNode> includeNodes = new ArrayList<>();
    new NodeTraversor(new NodeVisitor() {

        @Override
        public void head(Node node, int depth) {
        // nop
        }

        @Override
        public void tail(Node node, int depth) {
            if (node instanceof TextNode) {
                TextNode textNode = (TextNode) node;
                String text = textNode.getWholeText();
                if (text.contains(INCLUDE_PREFIX)) {
                    includeNodes.add(textNode);
                }
            }
        }
    }).traverse(element);
    return includeNodes;
}
Also used : TextNode(org.jsoup.nodes.TextNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Node(org.jsoup.nodes.Node) ArrayList(java.util.ArrayList) TextNode(org.jsoup.nodes.TextNode) NodeTraversor(org.jsoup.select.NodeTraversor) NodeVisitor(org.jsoup.select.NodeVisitor)

Example 5 with NodeTraversor

use of org.jsoup.select.NodeTraversor in project Saber-Bot by notem.

the class HTMLStripper method cleanDescription.

/**
 * removes HTML tags from a google calendar event's description
 * @param description  an event description possibly containing HTML tags
 * @return an event description free of HTML tags
 */
public static String cleanDescription(String description) {
    FormattingVisitor formatter = new FormattingVisitor();
    new NodeTraversor(formatter).traverse(Jsoup.parse(description));
    return formatter.toString();
}
Also used : NodeTraversor(org.jsoup.select.NodeTraversor)

Aggregations

NodeTraversor (org.jsoup.select.NodeTraversor)8 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)1 ArrayList (java.util.ArrayList)1 Node (org.jsoup.nodes.Node)1 TextNode (org.jsoup.nodes.TextNode)1 NodeVisitor (org.jsoup.select.NodeVisitor)1