當前位置: 首頁>>代碼示例>>Java>>正文


Java TextNode.text方法代碼示例

本文整理匯總了Java中org.jsoup.nodes.TextNode.text方法的典型用法代碼示例。如果您正苦於以下問題:Java TextNode.text方法的具體用法?Java TextNode.text怎麽用?Java TextNode.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.nodes.TextNode的用法示例。


在下文中一共展示了TextNode.text方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: appendTextSkipHidden

import org.jsoup.nodes.TextNode; //導入方法依賴的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

示例2: mapAllElements

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public void mapAllElements(String selector, String fieldName) {
    Elements elements = jsoupDocument.select(selector);
    for (int i = 0; i < elements.size(); i++) {
        Element element = elements.get(i);


        StringBuilder value = new StringBuilder();
        for(Element subElements : element.getAllElements()) {
            for (TextNode textNode : subElements.textNodes()) {
                final String text = textNode.text();
                value.append(text);
                value.append(" ");
            }
        }
        document.addField(fieldName, value.toString().trim());
    }
}
 
開發者ID:tblsoft,項目名稱:solr-cmd-utils,代碼行數:18,代碼來源:HtmlJsoupFilter.java

示例3: operate

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
@Override
public String operate(Element element) {
    int index = 0;
    StringBuilder accum = new StringBuilder();
    for (Node node : element.childNodes()) {
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode) node;
            if (group == 0) {
                accum.append(textNode.text());
            } else if (++index == group) {
                return textNode.text();
            }
        }
    }
    return accum.toString();
}
 
開發者ID:zongtui,項目名稱:zongtui-webcrawler,代碼行數:17,代碼來源:ElementOperator.java

示例4: head

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
@Override
public void head(Node node, int depth) {
  if (node instanceof TextNode) {
    TextNode text = (TextNode) node;
    String textContent = text.text();

    if (textLen >= maxTextLen) {
      text.text("");
    } else if (textLen + textContent.length() > maxTextLen) {
      int ptr = maxTextLen - textLen;
      if (!killwords) {
        ptr = Functions.movePointerToJustBeforeLastWord(ptr, textContent) - 1;
      }

      text.text(textContent.substring(0, ptr) + ending);
      textLen = maxTextLen;
    } else {
      textLen += textContent.length();
    }
  }
}
 
開發者ID:HubSpot,項目名稱:jinjava,代碼行數:22,代碼來源:TruncateHtmlFilter.java

示例5: processTextNode

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
/**
 * Process text node to check for {{ }} vue expressions.
 * @param node Current node being processed
 */
private void processTextNode(TextNode node)
{
    String elementText = node.text();

    Matcher matcher = VUE_MUSTACHE_PATTERN.matcher(elementText);

    int lastEnd = 0;
    StringBuilder newText = new StringBuilder();
    while (matcher.find())
    {
        int start = matcher.start();
        int end = matcher.end();
        if (start > 0)
            newText.append(elementText.substring(lastEnd, start));

        currentExpressionReturnType = "String";
        String expressionString = elementText.substring(start + 2, end - 2).trim();
        String processedExpression = processExpression(expressionString);
        newText.append("{{ ").append(processedExpression).append(" }}");
        lastEnd = end;
    }
    if (lastEnd > 0)
    {
        newText.append(elementText.substring(lastEnd));
        node.text(newText.toString());
    }
}
 
開發者ID:Axellience,項目名稱:vue-gwt,代碼行數:32,代碼來源:TemplateParser.java

示例6: getAttributeValueOfJSoupTextNode

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public static String getAttributeValueOfJSoupTextNode(TextNode textNode,
		String attribute) {
	if(attribute.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_TEXT))
		return textNode.text();
	else
		return null;
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:8,代碼來源:HtmlTextNode.java

示例7: head

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
@Override
public void head(Node node, int depth) {
  if (node instanceof Element) {
    Element element = (Element) node;
    String tagName = element.tag().getName();
    if (tagName.equals(HtmlTags.POLYMER_ELEMENT.getName())) {
      renameAttributesAttributeValue(element);
    } else if (tagName.equals("script")) {
      insideScriptElement = true;
    } else {
      renameAllAnnotatedEventAttributes(element);
      renameAllAttributeValues(element);
    }
  } else if (node instanceof TextNode) {
    TextNode textNode = (TextNode) node;
    textNode.text(renameStringWithDatabindingDirectives(textNode.getWholeText()));
  } else if (insideScriptElement && node instanceof DataNode) {
    DataNode dataNode = (DataNode) node;
    String js = dataNode.getWholeData();
    try {
      js = JsRenamer.renameProperties(renameMap, js);
    } catch (JavaScriptParsingException e) {
      System.err.println(e);
    }
    dataNode.setWholeData(js);
  }
}
 
開發者ID:PolymerLabs,項目名稱:PolymerRenamer,代碼行數:28,代碼來源:HtmlRenamer.java

示例8: runDependencyRecursive_OnlyText

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public static String runDependencyRecursive_OnlyText(int level,
		Node currNode, String parent) {

	String text_of_chunk = "";
	level++;

	for (Node curr : currNode.childNodes()) {
		// TextNode de niveau 1

		// System.out.println(curr.nodeName());

		// a - b et i sont des terminaux.
		if (curr instanceof TextNode) {
			TextNode currTextNode = (TextNode) curr;
			printLevel(level, " [" + level + "] " + currTextNode.text());
			text_of_chunk += currTextNode.text();
		}
		// bold, link, italic, etc.
		text_of_chunk += runDependencyRecursive_OnlyText(level, curr,
				"test");
	}

	if (text_of_chunk.length() == 0) {
		// System.out.println("Erreur");
		text_of_chunk = "";
	}

	return text_of_chunk;

}
 
開發者ID:fauconnier,項目名稱:LaToe,代碼行數:31,代碼來源:HTML_Service.java

示例9: toHtml

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public String toHtml(String s2) {
	RTFEditorKit rtfeditorkit = new RTFEditorKit();
	DefaultStyledDocument defaultstyleddocument = new DefaultStyledDocument();
	readString(s2, defaultstyleddocument, rtfeditorkit);
	scanDocument(defaultstyleddocument);

	// Parse all rtf elements
	for (RtfElementParser r : parserItems) {
		r.parseDocElements(entries.entrySet().iterator());
	}

	// Parse all textnodes
	for (Map.Entry<TextNode, Element> entry : entries.entrySet()) {
		TextNode txtNode = entry.getKey();
		// Replace \n an element node
		while (txtNode.getWholeText().contains("\n")){
			int pos = txtNode.getWholeText().indexOf("\n");
			String txt = txtNode.getWholeText();
			txtNode.before(new TextNode(txt.substring(0, pos), ""));
			txtNode.before(new org.jsoup.nodes.Element(Tag.valueOf("br"), ""));
			txtNode.text(txt.substring(pos + 1));
		}
		
	}

	return removeEmptyNodes(body).toString();
}
 
開發者ID:frickler,項目名稱:Html2Rtf,代碼行數:28,代碼來源:Rtf2Html.java

示例10: stripEndBlankNodes

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
/**
 * 刪除 HTMl 元素中右邊所有連續的空白字符、空節點。 TODO 目前對於直接位於 body 的空白文本不會刪除,待完善
 */
private static boolean stripEndBlankNodes(Element element) {
    // 查找直屬於當前元素的空白文本節點並將內容設置為空串
    // 對於非空白的文本節點,將文字左邊的空白字符刪除
    List<TextNode> childNodes = element.textNodes();
    for (int i = childNodes.size() - 1; i >= 0; i--) {
        TextNode tn = childNodes.get(i);
        if (StringUtils.isBlank(tn.text())) {
            tn.text("");
        } else {
            Node nextSibling = tn.nextSibling();
            logger.debug("stripEndBlankNodes() -> textNode' next sibling: {}", nextSibling);
            if (nextSibling == null) {
                tn.text(StringUtils.stripEnd(tn.text()));
                return true;
            }
        }
    }

    Elements children = element.children();
    for (int i = children.size() - 1; i >= 0; i--) {
        Element c = children.get(i);
        // 如果發現空節點則刪除掉
        if (isBlankElement(c)) {
            c.remove();
            logger.debug("stripEndBlankNodes() -> Removed element:\n{}\n", c);
            continue;
        }

        // 如果節點不空白且無子節點,表明已經找到了 HTML 最後一個非空節點,跳出本次循環並結束遞歸
        if (c.children().isEmpty()) {
            return true;
        }

        // 遞歸子節點
        if (stripEndBlankNodes(c)) {
            return true;
        }
    }

    return false;
}
 
開發者ID:akuma,項目名稱:meazza,代碼行數:45,代碼來源:HtmlUtils.java

示例11: CountInfo

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public CountInfo(TextNode tNode) {
    this.tNode = tNode;
    String text = tNode.text();
    this.textCount = TextUtils.countText(text);
    this.puncCount = TextUtils.countPunc(text);
}
 
開發者ID:hfut-dmic,項目名稱:ContentExtractor,代碼行數:7,代碼來源:ContentExtractor.java

示例12: runDependencyRecursive_NewChunk

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
public static String runDependencyRecursive_NewChunk(int level,
		Node currNode, String parent) {

	Chunk_Lara currChunk = new Chunk_Lara(0, 0, 0, 0);
	currChunk.setLevel(level);
	currChunk.setType(parent);

	String text_of_chunk = "";

	level++;
	for (Node curr : currNode.childNodes()) {

		// a - b et i sont des terminaux.
		if (!curr.nodeName().equals("b") && !curr.nodeName().equals("i")
				&& !curr.nodeName().equals("a")
				&& !curr.nodeName().equals("strong")
				&& !curr.nodeName().equals("em")
				&& !curr.nodeName().equals("div")
				&& !curr.nodeName().equals("font")
				&& !curr.nodeName().equals("span")
				&& !curr.nodeName().equals("u")) {

			if (curr instanceof TextNode) {
				TextNode currTextNode = (TextNode) curr;
				printLevel(level, " [" + level + "] " + currTextNode.text());
				text_of_chunk += currTextNode.text();
			}
			// // bold, link, italic, etc.
			// text_of_chunk += runDependencyRecursive_OnlyText(level, curr,
			// "test");
		} else {
			// node = a, b or a
			text_of_chunk += runDependencyRecursive_OnlyText(level, curr,
					"test");

			// TextNode currTextNode = (TextNode) curr;

		}
	}

	if (text_of_chunk.length() == 0) {
		// System.out.println("Erreur");
		text_of_chunk = "";
	}

	currChunk.setText(text_of_chunk);
	currListChunk.add(currChunk);

	return text_of_chunk;
}
 
開發者ID:fauconnier,項目名稱:LaToe,代碼行數:51,代碼來源:HTML_Service.java

示例13: getText

import org.jsoup.nodes.TextNode; //導入方法依賴的package包/類
@Override
public String getText() {
	TextNode textNode = (TextNode) node;
	return textNode.text();
}
 
開發者ID:jaeksoft,項目名稱:opensearchserver,代碼行數:6,代碼來源:JSoupHtmlNode.java


注:本文中的org.jsoup.nodes.TextNode.text方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。