Java Code Examples for org.jsoup.nodes.Node#nodeName()

The following examples show how to use org.jsoup.nodes.Node#nodeName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lemminx   File: HtmlToPlainText.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void head(Node node, int depth) {
	String name = node.nodeName();
	if (node instanceof TextNode) {
		append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
	} else if (name.equals("ul")) {
		listNesting++;
	} else if (name.equals("li")) {
		append("\n ");
		for (int i = 1; i < listNesting; i++) {
			append("  ");
		}
		if (listNesting == 1) {
			append("* ");
		} else {
			append("- ");
		}
	} else if (name.equals("dt")) {
		append("  ");
	} else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr")) {
		append("\n");
	}
}
 
Example 2
Source Project: dkpro-c4corpus   File: Paragraph.java    License: Apache License 2.0 6 votes vote down vote up
public String getPath(Node n)
{
    String nodePath = "";
    while (n != null) {
        if (n instanceof TextNode) {
            n = n.parent();
        }
        if (NodeHelper.isInnerText(n)) {
            n = n.parent();
        }
        String parentNodeName = n.nodeName();
        nodePath = parentNodeName + "." + nodePath;

        if (!parentNodeName.equalsIgnoreCase("html")) {
            n = n.parent();
        }
        else {
            break;
        }
    }

    return nodePath;
}
 
Example 3
Source Project: jsoup-learning   File: HtmlToPlainText.java    License: MIT License 5 votes vote down vote up
public void tail(Node node, int depth) {
    String name = node.nodeName();
    if (name.equals("br"))
        append("\n");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5"))
        append("\n\n");
    else if (name.equals("a"))
        append(String.format(" <%s>", node.absUrl("href")));
}
 
Example 4
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
    else if (name.equals("dt"))
        append("  ");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
        append("\n");
}
 
Example 5
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
    else if (name.equals("dt"))
        append("  ");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
        append("\n");
}
 
Example 6
public void tail(Node node, int depth) {
    String name = node.nodeName();
    if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
        append("\n");
    else if (name.equals("a"))
        append(String.format(" <%s>", node.absUrl("href")));
}
 
Example 7
Source Project: lemminx   File: HtmlToPlainText.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void tail(Node node, int depth) {
	String name = node.nodeName();
	if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5")) {
		append("\n");
	} else if (StringUtil.in(name, "th", "td")) {
		append(" ");
	} else if (name.equals("a")) {
		append(String.format(" <%s>", node.absUrl("href")));
	} else if (name.equals("ul")) {
		listNesting--;
	}
}
 
Example 8
Source Project: jsoup-learning   File: HtmlToPlainText.java    License: MIT License 5 votes vote down vote up
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
}
 
Example 9
Source Project: Recaf   File: FormattingVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public void head(Node node, int depth) {
	String name = node.nodeName();
	// TextNodes carry all user-readable text in the DOM.
	if(node instanceof TextNode)
		text(((TextNode) node).text());
	// Other nodes are used only for formatting, not content
	else if(name.equals("li"))
		text("\n * ");
	else if(name.equals("dt"))
		text("  ");
	else if(StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
		spacing(node);
}
 
Example 10
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
    else if (name.equals("dt"))
        append("  ");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
        append("\n");
}
 
Example 11
public void tail(Node node, int depth) {
    String name = node.nodeName();
    if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
        append("\n");
    else if (name.equals("a"))
        append(String.format(" <%s>", node.absUrl("href")));
}
 
Example 12
@Override
public void tail(Node node, int depth) {
	String name = node.nodeName();
	if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5")) {
		append("\n");
	} else if (StringUtil.in(name, "th", "td")) {
		append(" ");
	} else if (name.equals("a")) {
		append(String.format(" <%s>", node.absUrl("href")));
	} else if (name.equals("ul")) {
		listNesting--;
	}
}
 
Example 13
Source Project: echo   File: HtmlToPlainText.java    License: Apache License 2.0 5 votes vote down vote up
public void head(Node node, int depth) {
  String name = node.nodeName();
  if (node instanceof TextNode) {
    append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
  } else if (name.equals("li")) {
    append("\n * ");
  } else if (name.equals("dt")) {
    append("  ");
  } else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr")) {
    append("\n");
  }
}
 
Example 14
Source Project: echo   File: HtmlToPlainText.java    License: Apache License 2.0 5 votes vote down vote up
public void tail(Node node, int depth) {
  String name = node.nodeName();
  if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5")) {
    append("\n");
  } else if (name.equals("a")) {
    append(String.format(" <%s>", node.absUrl("href")));
  }
}
 
Example 15
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
    else if (name.equals("dt"))
        append("  ");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
        append("\n");
}
 
Example 16
public void tail(Node node, int depth) {
    String name = node.nodeName();
    if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
        append("\n");
    else if (name.equals("a"))
        append(String.format(" <%s>", node.absUrl("href")));
}
 
Example 17
Source Project: Recaf   File: FormattingVisitor.java    License: MIT License 4 votes vote down vote up
@Override
public void tail(Node node, int depth) {
	String name = node.nodeName();
	if(StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5", "ul", "ol", "table"))
		spacing(node);
}
 
Example 18
public void getHtmlStartingFromText(String text, StringBuilder builder, List<Node> nodesList, boolean append) {


        for (Node node : nodesList) {
            String nodeName = node.nodeName();

            if (append) {
                builder.append(node.outerHtml());
                continue;
            }


            if (nodeName.equalsIgnoreCase("#text")) {

                if (node.toString().trim().equalsIgnoreCase(text))
                    append = true;

            }
            getHtmlStartingFromText(text, builder, node.childNodes(), append);
        }
    }
 
Example 19
private void getHtmlStartingFromNode(String nodeType, String attrib, String attribValue, StringBuilder builder, List<Node> nodesList, boolean append) {


        for (Node node : nodesList) {
            String nodeName = node.nodeName();

            if (append) {

                if (node.nodeName().equalsIgnoreCase("#text") && node.outerHtml().charAt(0) != ' ')
                    builder.append(" ");

                builder.append(node.outerHtml());

                if (!node.nodeName().equalsIgnoreCase("#text"))
                    builder.append(" ");

                continue;
            }


            if (nodeName.equalsIgnoreCase(nodeType)) {

                if (node.attributes().hasKey(attrib) && node.attr(attrib).equalsIgnoreCase(attribValue))
                    append = true;

            }
            getHtmlStartingFromNode(nodeType, attrib, attribValue, builder, node.childNodes(), append);
        }
    }
 
Example 20
private void updateMentionUidToEmail(SymphonyClient symClient, List<Node> nodesList) {


        for (Node node : nodesList) {
            String nodeName = node.nodeName();


            if (nodeName.equalsIgnoreCase(NodeTypes.MENTION.toString())) {

                if (node.attributes().hasKey(AttribTypes.UID.toString())) {

                    String uid = node.attr(AttribTypes.UID.toString());

                    SymUser user = null;
                    try {
                        user = symClient.getUsersClient().getUserFromId(Long.parseLong(uid));

                        logger.info("Translated mention uid {} to email {}", uid, user.getEmailAddress());
                    } catch (UsersClientException e) {
                        logger.error("Could not identify user email from id", e);
                    }

                    if (user != null && user.getEmailAddress() != null) {
                        uid = user.getEmailAddress();
                    }

                    Attribute emailAttribute = new Attribute(AttribTypes.EMAIL.toString(), uid);

                    node.attributes().put(emailAttribute);
                    node.removeAttr(AttribTypes.UID.toString());

                }

            }
            updateMentionUidToEmail(symClient, node.childNodes());
        }


    }