com.vaadin.flow.dom.Element.isTextNode()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(131)

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

Element.isTextNode介绍

[英]Checks whether this element represents a text node.
[中]检查此元素是否表示文本节点。

代码示例

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

/**
 * Checks whether the given element is a <code>script</code> or not.
 *
 * @param element
 *            the element to check
 * @return <code>true</code> if a script, <code>false</code> if not
 */
public static boolean isScript(Element element) {
  return !element.isTextNode()
      && "script".equalsIgnoreCase(element.getTag());
}

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

/**
 * Checks whether the given element is a custom element or not.
 * <p>
 * Custom elements (Web Components) are recognized by having at least one
 * dash in the tag name.
 *
 * @param element
 *            the element to check
 * @return <code>true</code> if a custom element, <code>false</code> if not
 */
public static boolean isCustomElement(Element element) {
  return !element.isTextNode() && element.getTag().contains("-");
}

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

private Element[] getNonTextNodes() {
  return getElement().getChildren()
      .filter(element -> !element.isTextNode())
      .toArray(Element[]::new);
}

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

private void appendTextContent(StringBuilder builder,
    Predicate<? super Element> childFilter) {
  if (isTextNode()) {
    builder.append(getText());
  } else {
    getChildren().filter(childFilter)
        .forEach(e -> e.appendTextContent(builder, childFilter));
  }
}

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

/**
 * Returns the text content for this element by including children matching
 * the given filter.
 *
 * @param childFilter
 *            the filter used to decide whether to include a child or not
 * @return the text content for this element and any matching child nodes
 *         recursively, never {@code null}
 */
private String getTextContent(Predicate<? super Element> childFilter) {
  if (isTextNode()) {
    return getStateProvider().getTextContent(getNode());
  } else {
    StringBuilder builder = new StringBuilder();
    appendTextContent(builder, childFilter);
    return builder.toString();
  }
}

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

/**
 * Sets the text content of this element, replacing any existing children.
 *
 * @param textContent
 *            the text content to set, <code>null</code> is interpreted as
 *            an empty string
 * @return this element
 */
public Element setText(String textContent) {
  if (textContent == null) {
    // Browsers work this way
    textContent = "";
  }
  if (isTextNode()) {
    getStateProvider().setTextContent(getNode(), textContent);
  } else {
    if (textContent.isEmpty()) {
      removeAllChildren();
    } else {
      setTextContent(textContent);
    }
  }
  return this;
}

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

if (element.isTextNode()) {
  return new TextNode(element.getText(), document.baseUri());

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

private void setTextContent(String textContent) {
  Element child;
  if (getChildCount() == 1 && getChild(0).isTextNode()) {
    child = getChild(0).setText(textContent);
  } else {
    child = createText(textContent);
  }
  removeAllChildren();
  appendChild(child);
}

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

if (icon != null && icon.getElement().isTextNode()) {
  throw new IllegalArgumentException(
      "Text node can't be used as an icon.");

相关文章

微信公众号

最新文章

更多