当前位置: 首页>>代码示例>>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;未经允许,请勿转载。