本文整理匯總了Java中org.jsoup.nodes.Node類的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Node類屬於org.jsoup.nodes包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: tail
import org.jsoup.nodes.Node; //導入依賴的package包/類
@NonNull
@Override
public TailFilterDecision tail(Node node, int depth) {
if (signatureFound) {
return TailFilterDecision.CONTINUE;
}
if (node instanceof Element) {
Element element = (Element) node;
boolean elementIsBr = element.tag().equals(BR);
if (elementIsBr || element.tag().equals(P)) {
lastElementCausedLineBreak = true;
brElementPrecedingDashes = elementIsBr ? element : null;
return TailFilterDecision.CONTINUE;
}
}
lastElementCausedLineBreak = false;
return TailFilterDecision.CONTINUE;
}
示例3: gatherWuBi
import org.jsoup.nodes.Node; //導入依賴的package包/類
private String gatherWuBi(Element tagContentEL) {
Elements spans = tagContentEL.select("span.diczx7");
for (Element span : spans) {
if (span.text().equals("五筆:")) {
// 後一個兄弟文本節點
Node textNode = span.nextSibling();
if (textNode instanceof TextNode) {
String wubi=((TextNode) textNode).text();
//去掉特殊字符
wubi=wubi.replaceAll("\\W", "");
return wubi;
}
}
}
return null;
}
示例4: appendTextSkipHidden
import org.jsoup.nodes.Node; //導入依賴的package包/類
private void appendTextSkipHidden(Element e, StringBuilder accum, int indent) {
for (Node child : e.childNodes()) {
if (unlikely(child)) {
continue;
}
if (child instanceof TextNode) {
TextNode textNode = (TextNode) child;
String txt = textNode.text();
accum.append(txt);
} else if (child instanceof Element) {
Element element = (Element) child;
if (accum.length() > 0 && element.isBlock()
&& !lastCharIsWhitespace(accum))
accum.append(' ');
else if (element.tagName().equals("br"))
accum.append(' ');
appendTextSkipHidden(element, accum, indent + 1);
}
}
}
示例5: traverse
import org.jsoup.nodes.Node; //導入依賴的package包/類
/**
* Start a depth-first traverse of the root and all of its descendants.
* @param root the root node point to traverse.
*/
public void traverse(Node root) {
Node node = root;
int depth = 0;
while (node != null) {
visitor.head(node, depth);
if (node.childNodeSize() > 0) {
node = node.childNode(0);
depth++;
} else {
while (node.nextSibling() == null && depth > 0) {
visitor.tail(node, depth);
node = node.parentNode();
depth--;
}
visitor.tail(node, depth);
if (node == root)
break;
node = node.nextSibling();
}
}
}
示例6: getFirstNonEmptyNodeChild
import org.jsoup.nodes.Node; //導入依賴的package包/類
public Node getFirstNonEmptyNodeChild(Element parent) {
if (parent == null) return null;
if (parent.childNodeSize() == 0) return null;
if (parent.childNode(0) instanceof Element) {
return parent.childNode(0);
}
if (parent.childNode(0) instanceof TextNode && ((TextNode) parent.childNode(0)).text().replaceAll("\u00A0", " ").trim().length() > 0) {
return parent.childNode(0);
}
else {
return getNextNonEmptyNode(parent.childNode(0));
}
}
示例7: getChildNodes
import org.jsoup.nodes.Node; //導入依賴的package包/類
@SuppressWarnings("unchecked")
protected List<? extends Node> getChildNodes(final Node node, final String withName) {
if (node==null)
return Collections.EMPTY_LIST;
if (Selector.UNIVERSAL_TAG.equals(withName))
return filter(node.childNodes());
ArrayList<Node> result = new ArrayList<Node>();
List<Node> children = node.childNodes();
for(Node child : children)
if (nameMatches(child, withName))
result.add(child);
return result;
}
示例8: 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;
}
示例9: mergeToResult
import org.jsoup.nodes.Node; //導入依賴的package包/類
private void mergeToResult(Node node)
{
Node lastAddedNode = getLastAddedNode();
//the <br><br> is a paragraph separator
if (lastAddedNode != null && node.nodeName().equalsIgnoreCase("br") && lastAddedNode
.nodeName().equalsIgnoreCase("br")) {
insertAsNewParagraph(node);
return;
}
if (lastAddedNode == null) {
insertAsNewParagraph(node);
return;
}
AncestorState ancestorState = getAncestorState(lastAddedNode, node);
switch (ancestorState) {
case BLOCKLEVEL:
insertAsNewParagraph(node);
return;
case INNERTEXT_ONLY:
appendToLastParagraph(node);
return;
}
}
示例10: getAncestorState
import org.jsoup.nodes.Node; //導入依賴的package包/類
/**
* Visit from lastNode and currentNode to the first common ancestor of these
* 2 nodes, - if all the visited ancestors are
* INNERTEXT returns
* {@link ParagraphsExplorer.AncestorState#INNERTEXT_ONLY} - if one of the
* visited ancestors is
* isBlockTag(Node) returns
* {@link ParagraphsExplorer.AncestorState#BLOCKLEVEL} - otherwise returns
* {@link ParagraphsExplorer.AncestorState#UNKNOW}
*/
public static AncestorState getAncestorState(Node lastNode, Node currentNode)
{
if (lastNode == null || currentNode == null) {
throw new InvalidParameterException();
}
Node ancestor = NodeHelper.nearestCommonAncestor(lastNode, currentNode);
AncestorState as1 = getAncestorStateOfBranch(ancestor, lastNode);
if (as1 == AncestorState.BLOCKLEVEL) {
return AncestorState.BLOCKLEVEL;
}
AncestorState as2 = getAncestorStateOfBranch(ancestor, currentNode);
if (as2 == AncestorState.BLOCKLEVEL) {
return AncestorState.BLOCKLEVEL;
}
if (as1 == AncestorState.INNERTEXT_ONLY && as2 == AncestorState.INNERTEXT_ONLY) {
return AncestorState.INNERTEXT_ONLY;
}
return AncestorState.UNKNOW;
}
示例11: isAncestor
import org.jsoup.nodes.Node; //導入依賴的package包/類
/**
* Returns true if node1 is ancestor of node2 or node1 == node2
*
* @param node1 node 1
* @param node2 node 2
* @return boolean value
*/
public static boolean isAncestor(Node node1, Node node2)
{
if (node1 == node2) {
return true;
}
Node ancestor = node2;
while (ancestor != null) {
if (ancestor == node1) {
return true;
}
ancestor = ancestor.parent();
}
return false;
}
示例12: initRawInfo
import org.jsoup.nodes.Node; //導入依賴的package包/類
public void initRawInfo()
{
StringBuilder sb = new StringBuilder();
for (Node n : this) {
// NodeHelper.cleanEmptyElements(n);
if (n instanceof TextNode) {
this.setTagName(getPath(n));
String nodeRawText = ((TextNode) n).text();
sb.append(Utils.normalizeBreaks(nodeRawText).trim());
if (NodeHelper.isLink(n)) {
charsCountInLinks += nodeRawText.length();
}
}
}
rawText = sb.toString();
}
示例13: mergeToResult
import org.jsoup.nodes.Node; //導入依賴的package包/類
private void mergeToResult(Node node)
{
Node lastAddedNode = getLastAddedNode();
//the <br><br> is a paragraph separator
if (lastAddedNode != null && node.nodeName().equalsIgnoreCase("br") && lastAddedNode
.nodeName().equalsIgnoreCase("br")) {
insertAsNewParagraph(node);
return;
}
if (lastAddedNode == null) {
insertAsNewParagraph(node);
return;
}
AncestorState ancestorState = getAncestorState(lastAddedNode, node);
switch (ancestorState) {
case BLOCKLEVEL:
insertAsNewParagraph(node);
return;
case INNERTEXT_ONLY:
appendToLastParagraph(node);
}
}
示例14: replaceNonTranslatableNode
import org.jsoup.nodes.Node; //導入依賴的package包/類
@Test
public void replaceNonTranslatableNode() {
String node1 = "<span translate=\"no\">do not translate</span>";
String node2 = "<em>translate</em>";
String node4 = "<span class=\"notranslate\">do not translate</span>";
String node5 = "<span id=\"private-notes-testing\">do not translate</span>";
String node6 = "<span>translate this</span>";
String node7 = "<p>translate this</p>";
String html = "<div>" + node1 + node2 + node4 + node5 + node6 +
node7 + "</div>";
TranslatableHTMLNode
node = ArticleUtil.replaceNonTranslatableNode(1, html);
assertThat(node.getPlaceholderIdMap()).hasSize(3);
assertThat(node.getPlaceholderIdMap().values()).extracting(
Node::toString)
.contains(node1, node4, node5)
.doesNotContain(node6, node7);
assertThat(node.getHtml()).doesNotContain(node1)
.doesNotContain(node4)
.doesNotContain(node5).contains(node2, node6, node7);
}
示例15: replacePlaceholderWithNode
import org.jsoup.nodes.Node; //導入依賴的package包/類
@Test
public void replacePlaceholderWithNode() {
Map<String, Node> nodeIdMap = new HashMap<>();
String html = "<div>";
for (int i = 0; i < 5; i++) {
Attributes attrs = new Attributes();
String id = "id" + i;
attrs.put("id", id);
Element ele = new Element(Tag.valueOf("span"), "", attrs);
ele.append("The original node");
nodeIdMap.put(id, ele);
Element placeholder = ArticleUtil.generatePlaceholderNode(id);
html += placeholder.outerHtml();
}
html += "</div>";
String results = ArticleUtil.replacePlaceholderWithNode(nodeIdMap, html);
for (Node originalNode: nodeIdMap.values()) {
assertThat(results).contains(originalNode.outerHtml());
}
}