当前位置: 首页>>代码示例>>Java>>正文


Java Node类代码示例

本文整理汇总了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");
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:HtmlToPlainText.java

示例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;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:21,代码来源:HtmlSignatureRemover.java

示例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;
}
 
开发者ID:yizhuoyan,项目名称:case-html-data-gather,代码行数:17,代码来源:HTMLDataGather.java

示例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);
        }
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:21,代码来源:OutputFormatter.java

示例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();
        }
    }
}
 
开发者ID:cpusoft,项目名称:common,代码行数:27,代码来源:NodeTraversor.java

示例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));
    }

}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:18,代码来源:JsoupSession.java

示例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;
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:18,代码来源:JsoupNodeHelper.java

示例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;
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:24,代码来源:Paragraph.java

示例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;
    }
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:25,代码来源:ParagraphsExplorer.java

示例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;
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:31,代码来源:ParagraphsExplorer.java

示例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;
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:24,代码来源:NodeHelper.java

示例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();
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:19,代码来源:Paragraph.java

示例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);
    }
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:24,代码来源:ParagraphsExplorer.java

示例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);
}
 
开发者ID:zanata,项目名称:zanata-mt,代码行数:22,代码来源:ArticleUtilTest.java

示例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());
    }
}
 
开发者ID:zanata,项目名称:zanata-mt,代码行数:23,代码来源:ArticleUtilTest.java


注:本文中的org.jsoup.nodes.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。