本文整理汇总了Java中org.jsoup.nodes.Node.nodeName方法的典型用法代码示例。如果您正苦于以下问题:Java Node.nodeName方法的具体用法?Java Node.nodeName怎么用?Java Node.nodeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Node
的用法示例。
在下文中一共展示了Node.nodeName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: head
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
@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");
}
}
示例2: getPath
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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;
}
示例3: head
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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");
}
示例4: tail
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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")));
}
示例5: head
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
public void head(Node node, int i)
{
String name = node.nodeName();
if (node instanceof TextNode)
accum.append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
else if (name.equals("li"))
accum.append("\n * ");
else if (name.equals("dt"))
accum.append(" ");
else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
accum.append("\n");
}
示例6: tail
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
public void tail(Node node, int depth)
{
String name = node.nodeName();
if (StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5"))
accum.append("\n");
}
示例7: tail
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
@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--;
}
}
示例8: parseText
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
private List<Alert> parseText(String html) {
List<Alert> alerts = new ArrayList<Alert>();
Document doc = Jsoup.parseBodyFragment(html);
List<Node> nodes = doc.body().childNodes();
String status = "", title = "", detail = "";
boolean isFirst = true;
boolean hasDetail = false;
StringBuilder builder = new StringBuilder();
for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++) {
Node node= nodes.get(nodeIndex);
String nodeName = node.nodeName();
if ("span".equals(nodeName)) {
Element elem = (Element)node;
String clazz = elem.attr("class");
if (clazz.indexOf("Title") == 0) {
// Previous alert is done. Collect
if (isFirst) {
isFirst = false;
} else {
alerts.add(buildTempAlert(status, title, detail, hasDetail, builder));
// Reset hasDetail;
hasDetail = false;
builder = new StringBuilder();
}
// Extract the new status
status = elem.text().toUpperCase();
}
// Other spans will be disregarded, like "DateStyle" spans
} else if ("br".equals(nodeName)) {
// Append <br> and they will be treated later.
builder.append("<br>");
} else if ("a".equals(nodeName) && ((Element)node).hasAttr("onclick")) {
// Title found! Has detail
hasDetail = true;
title = ((Element)node).text();
builder = new StringBuilder(); // Now builder builds detail
} else {
builder.append(node.outerHtml());
}
}
alerts.add(buildTempAlert(status, title, detail, hasDetail, builder));
return alerts;
}
示例9: getHtmlStartingFromText
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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);
}
}
示例10: getName
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
@Override
public String getName(final Node n) {
return n.nodeName();
}
示例11: getHtmlStartingFromNode
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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);
}
}
示例12: updateMentionUidToEmail
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
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());
}
}
示例13: stripTags
import org.jsoup.nodes.Node; //导入方法依赖的package包/类
private void stripTags(StringBuilder builder, List<Node> nodesList) {
for (Node node : nodesList) {
String nodeName = node.nodeName();
if (nodeName.equalsIgnoreCase("#text")) {
builder.append(node.toString().trim()).append(" ");
} else {
if (nodeName.equalsIgnoreCase(NodeTypes.ANCHOR.toString())) {
if (node.attributes().hasKey(AttribTypes.HREF.toString()))
builder.append(node.attr(AttribTypes.HREF.toString()));
} else if (nodeName.equalsIgnoreCase(NodeTypes.HASHTAG.toString())) {
if (node.attributes().hasKey(AttribTypes.TAG.toString()))
builder.append("#").append(node.attr(AttribTypes.TAG.toString())).append(" ");
} else if (nodeName.equalsIgnoreCase(NodeTypes.MENTION.toString())) {
SymUser user = new SymUser();
user.setEmailAddress("UID:" + node.attr(AttribTypes.UID.toString()));
user.setId(Long.valueOf(node.attr(AttribTypes.UID.toString())));
if (node.attributes().hasKey(AttribTypes.UID.toString())) {
if (symClient != null)
try {
user = symClient.getUsersClient().getUserFromId(Long.valueOf(node.attr(AttribTypes.UID.toString())));
} catch (UsersClientException e) {
logger.error("Could not identify user from userID", e);
}
} else if (node.attributes().hasKey(AttribTypes.EMAIL.toString())) {
user.setEmailAddress(node.attr(AttribTypes.EMAIL.toString()));
}
builder.append(user.getEmailAddress());
} else if (nodeName.equalsIgnoreCase(NodeTypes.CASHTAG.toString())) {
if (node.attributes().hasKey(AttribTypes.TAG.toString()))
builder.append("$").append(node.attr(AttribTypes.TAG.toString())).append(" ");
} else {
// recurse
stripTags(builder, node.childNodes());
}
}
}
}