org.jsoup.nodes.TextNode.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中org.jsoup.nodes.TextNode.<init>()方法的一些代码示例,展示了TextNode.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextNode.<init>()方法的具体详情如下:
包路径:org.jsoup.nodes.TextNode
类名称:TextNode
方法名:<init>

TextNode.<init>介绍

[英]Create a new TextNode representing the supplied (unencoded) text).
[中]创建一个表示所提供(未编码)文本的新文本节点)。

代码示例

代码示例来源:origin: org.jsoup/jsoup

/**
 * Create a new TextNode from HTML encoded (aka escaped) data.
 * @param encodedText Text containing encoded HTML (e.g. &amp;lt;)
 * @param baseUri Base uri
 * @return TextNode containing unencoded data (e.g. &lt;)
 * @deprecated use {@link TextNode#createFromEncoded(String)} instead, as LeafNodes don't carry base URIs.
 */
public static TextNode createFromEncoded(String encodedText, String baseUri) {
  String text = Entities.unescape(encodedText);
  return new TextNode(text);
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Create a new TextNode from HTML encoded (aka escaped) data.
 * @param encodedText Text containing encoded HTML (e.g. &amp;lt;)
 * @return TextNode containing unencoded data (e.g. &lt;)
 */
public static TextNode createFromEncoded(String encodedText) {
  String text = Entities.unescape(encodedText);
  return new TextNode(text);
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Create and prepend a new TextNode to this element.
 * 
 * @param text the unencoded text to add
 * @return this element
 */
public Element prependText(String text) {
  Validate.notNull(text);
  TextNode node = new TextNode(text);
  prependChild(node);
  return this;
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Create and append a new TextNode to this element.
 * 
 * @param text the unencoded text to add
 * @return this element
 */
public Element appendText(String text) {
  Validate.notNull(text);
  TextNode node = new TextNode(text);
  appendChild(node);
  return this;
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Set the text of this element. Any existing contents (text or elements) will be cleared
 * @param text unencoded text
 * @return this element
 */
public Element text(String text) {
  Validate.notNull(text);
  empty();
  TextNode textNode = new TextNode(text);
  appendChild(textNode);
  return this;
}

代码示例来源:origin: org.jsoup/jsoup

private void normaliseTextNodes(Element element) {
  List<Node> toMove = new ArrayList<>();
  for (Node node: element.childNodes) {
    if (node instanceof TextNode) {
      TextNode tn = (TextNode) node;
      if (!tn.isBlank())
        toMove.add(tn);
    }
  }
  for (int i = toMove.size()-1; i >= 0; i--) {
    Node node = toMove.get(i);
    element.removeChild(node);
    body().prependChild(new TextNode(" "));
    body().prependChild(node);
  }
}

代码示例来源:origin: org.jsoup/jsoup

void insert(Token.Character token) {
  final String data = token.getData();
  insertNode(token.isCData() ? new CDataNode(data) : new TextNode(data));
}

代码示例来源:origin: org.jsoup/jsoup

void insert(Token.Character characterToken) {
  Node node;
  // characters in script and style go in as datanodes, not text nodes
  final String tagName = currentElement().tagName();
  final String data = characterToken.getData();
  if (characterToken.isCData())
    node = new CDataNode(data);
  else if (tagName.equals("script") || tagName.equals("style"))
    node = new DataNode(data);
  else
    node = new TextNode(data);
  currentElement().appendChild(node); // doesn't use insertNode, because we don't foster these; and will always have a stack.
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Split this text node into two nodes at the specified string offset. After splitting, this node will contain the
 * original text up to the offset, and will have a new text node sibling containing the text after the offset.
 * @param offset string offset point to split node at.
 * @return the newly created text node containing the text after the offset.
 */
public TextNode splitText(int offset) {
  final String text = coreValue();
  Validate.isTrue(offset >= 0, "Split offset must be not be negative");
  Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");
  String head = text.substring(0, offset);
  String tail = text.substring(offset);
  text(head);
  TextNode tailNode = new TextNode(tail);
  if (parent() != null)
    parent().addChildren(siblingIndex()+1, tailNode);
  return tailNode;
}

代码示例来源:origin: org.jsoup/jsoup

public void head(Node source, int depth) {
  if (source instanceof Element) {
    Element sourceEl = (Element) source;
    if (whitelist.isSafeTag(sourceEl.tagName())) { // safe, clone and copy safe attrs
      ElementMeta meta = createSafeElement(sourceEl);
      Element destChild = meta.el;
      destination.appendChild(destChild);
      numDiscarded += meta.numAttribsDiscarded;
      destination = destChild;
    } else if (source != root) { // not a safe tag, so don't add. don't count root against discarded.
      numDiscarded++;
    }
  } else if (source instanceof TextNode) {
    TextNode sourceText = (TextNode) source;
    TextNode destText = new TextNode(sourceText.getWholeText());
    destination.appendChild(destText);
  } else if (source instanceof DataNode && whitelist.isSafeTag(source.parent().nodeName())) {
   DataNode sourceData = (DataNode) source;
   DataNode destData = new DataNode(sourceData.getWholeData());
   destination.appendChild(destData);
  } else { // else, we don't care about comments, xml proc instructions, etc
    numDiscarded++;
  }
}

代码示例来源:origin: k9mail/k-9

public void head(Node source, int depth) {
  if (elementToSkip != null) {
    return;
  }
  if (source instanceof Element) {
    Element sourceElement = (Element) source;
    if (isSafeTag(sourceElement)) {
      String sourceTag = sourceElement.tagName();
      Attributes destinationAttributes = sourceElement.attributes().clone();
      Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes);
      destination.appendChild(destinationChild);
      destination = destinationChild;
    } else if (source != root) {
      elementToSkip = sourceElement;
    }
  } else if (source instanceof TextNode) {
    TextNode sourceText = (TextNode) source;
    TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri());
    destination.appendChild(destinationText);
  } else if (source instanceof DataNode && isSafeTag(source.parent())) {
    DataNode sourceData = (DataNode) source;
    DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri());
    destination.appendChild(destinationData);
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
   * Escape a string which may contain html.
   *
   * @param maybeHtml
   *            the text to escape
   * @return escaped string
   */
  public static String escape(String maybeHtml) {
    return new TextNode(maybeHtml, null).outerHtml();
  }
}

代码示例来源:origin: com.cognifide.aet/jobs

@Override
 public void visit(Node node) {
  if (node instanceof TextNode || node instanceof Comment || node instanceof DataNode) {
   node.replaceWith(new TextNode(StringUtils.EMPTY, node.baseUri()));
  }
 }
}

代码示例来源:origin: astamuse/asta4d

public final static Element text(String text) {
  TextNode node = new TextNode(text, "");
  Element wrap = new GroupNode();
  wrap.appendChild(node);
  return wrap;
}

代码示例来源:origin: Cognifide/aet

@Override
 public void visit(Node node) {
  if (node instanceof TextNode || node instanceof Comment || node instanceof DataNode) {
   node.replaceWith(new TextNode(StringUtils.EMPTY, node.baseUri()));
  }
 }
}

代码示例来源:origin: astamuse/asta4d

void insert(Token.Character characterToken) {
  Node node;
  // characters in script and style go in as datanodes, not text nodes
  String tagName = currentElement().tagName();
  if (tagName.equals("script") || tagName.equals("style"))
    node = new DataNode(characterToken.getData(), baseUri);
  else
    node = new TextNode(characterToken.getData(), baseUri);
  currentElement().appendChild(node); // doesn't use insertNode, because we don't foster these; and will always have a stack.
}

代码示例来源:origin: org.jbehave/jbehave-rest

protected void cleanNodes(Element body, String tag) {
    for (Element element : body.getElementsByTag(tag)) {
      if (element == null || element.parent() == null) {
        continue;
      }
      for (Element child : element.children().select(tag)) {
        cleanNodes(child, tag);
      }
      element.replaceWith(new TextNode(element.text() + "<br/>", ""));
    }
  }
}

代码示例来源:origin: br.com.objectos/sitebricks

private void parseCdata() {
 tq.consume("<![CDATA[");
 String rawText = tq.chompTo("]]>");
 TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape
 if (pendingAnnotation != null)
  pendingAnnotation.apply(textNode);
 lines(textNode, rawText);
 add(textNode);
}

代码示例来源:origin: dhanji/sitebricks

private void parseCdata() {
 tq.consume("<![CDATA[");
 String rawText = tq.chompTo("]]>");
 TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape
 if (pendingAnnotation != null)
  pendingAnnotation.apply(textNode);
 lines(textNode, rawText);
 add(textNode);
}

代码示例来源:origin: com.google.sitebricks/sitebricks

private void parseCdata() {
 tq.consume("<![CDATA[");
 String rawText = tq.chompTo("]]>");
 TextNode textNode = new TextNode(rawText, baseUri); // constructor does not escape
 if (pendingAnnotation != null)
  pendingAnnotation.apply(textNode);
 lines(textNode, rawText);
 add(textNode);
}

相关文章