org.jsoup.nodes.Element.appendText()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(180)

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

Element.appendText介绍

[英]Create and append a new TextNode to this element.
[中]创建新的TextNode并将其附加到此元素。

代码示例

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

cellElement.attr("plain-text", true);
  cellElement
      .appendText(Optional.ofNullable(state.text).orElse(""));
  break;
case HTML:

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

new UICreateEvent(context.getRequest(), context.getUIClass()));
if (title != null) {
  head.appendElement("title").appendText(title);
    .appendText("html, body {height:100%;margin:0;}");

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

public Element appendText(String text) {
  return originElement.appendText(text);
}

代码示例来源:origin: basis-technology-corp/Java-readability

@Override
public void characters(char[] data, int start, int length) throws SAXException {
  assert currentElement != null;
  currentElement.appendText(new String(data, start, length));
}
@Override

代码示例来源:origin: dstl/baleen

/**
 * Add text to element
 *
 * @param e the element
 * @param text the text buffer containing the substring
 * @param start the start offset within the text
 * @param end the end offset within the text
 * @return true, if successful
 */
private boolean appendText(final Element e, final String text, final int start, final int end) {
 if (start < end && end <= text.length()) {
  e.appendText(text.substring(start, end));
  return true;
 } else {
  return false;
 }
}

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

@Override
  public void set(Element elem) {
    elem.appendText("test-append");
  }
});

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

@Override
public void set(Element elem) {
  elem.empty();
  elem.appendText(renderText);
}

代码示例来源:origin: mangstadt/ez-vcard

/**
 * Appends text to the element, replacing newlines with {@code <br>} tags.
 * @param text the text to append
 */
public void append(String text) {
  boolean first = true;
  String lines[] = text.split("\\r\\n|\\n|\\r");
  for (String line : lines) {
    if (!first) {
      //replace newlines with "<br>" tags
      element.appendElement("br");
    }
    if (line.length() > 0) {
      element.appendText(line);
    }
    first = false;
  }
}

代码示例来源:origin: stackoverflow.com

// Load HTML file
String charsetName = "UTF-8";
Document doc = Jsoup.parse(new File("dummy.html"), charsetName);
System.out.println("BEFORE:\n" + doc.outerHtml());

// Replace each link nodes with its respective CSS file content
for (Element link : doc.select("link[rel=stylesheet]")) {
  String cssFilename = link.attr("href");

  Element style = new Element(Tag.valueOf("style"), "");
  style.appendText("/* " + cssFilename + " */");
  style.appendText(loadCssFileContent(cssFilename, charsetName));

  link.replaceWith(style);
}

System.out.println("\nAFTER:\n" + doc.outerHtml());

private static String loadCssFileContent(String path, String charsetName) throws IOException {
  byte[] encoded = Files.readAllBytes(Paths.get(path));
  return new String(encoded, charsetName);
}

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

styles.appendText(bodySizeContent);
styles.appendText(".v-reconnect-dialog {" //
    + "position: absolute;" //
    + "top: 1em;" //
styles.appendText(".v-system-error {" //
    + "color: red;" //
    + "background: white;" //

代码示例来源:origin: org.aperteworkflow/webapi

private void createButton(Element parent, String actionButtonId, String buttonClass, String iconClass,
             String messageKey, String descriptionKey, String clickFunction) {
  Element buttonNode = parent.ownerDocument().createElement("button")
      .attr("class", buttonClass != null ? "btn btn-" + buttonClass : "btn")
      .attr("disabled", "true")
      .attr("id", actionButtonId)
      .attr("data-toggle", "tooltip")
      .attr("data-placement", "bottom")
      .attr("title", i18Source.getMessage(descriptionKey));
  Element buttonIcon = parent.ownerDocument().createElement("span")
      .attr("class", iconClass != null ? "glyphicon glyphicon-" + iconClass : "glyphicon");
  parent.appendChild(buttonNode);
  buttonNode.appendChild(buttonIcon);
  buttonNode.appendText(i18Source.getMessage(messageKey));
  scriptBuilder.append("$('#").append(actionButtonId).append("').click(function() { ").append(clickFunction).append("('").append(getViewedObjectId()).append("');  });");
  scriptBuilder.append("$('#").append(actionButtonId).append("').tooltip();");
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args)
{
  Document document = Jsoup.parse("<html>" +
      "  <body>" +
      "   <div id='foo'>" +
      "     <p id='bar'>TEST</p>" +
      "   </div>" +
      "  </body>" +
      "</html>");

  System.out.println("Add blah to the Element with ID: foo");
  Element foo = document.getElementById("foo");
  foo.appendText("blah");

  System.out.println(document.html());

  System.out.println("Get the content of a div having a p:");
  for (Element div : document.getElementsByTag("div"))
  {
    for (Element p : div.getElementsByTag("p"))
    {
      System.out.println(p.text());
    }

  }
}

代码示例来源:origin: stackoverflow.com

public static Node toTextElement(String str) {
  Element e = new Element(Tag.valueOf("text"), "");
  e.appendText(str);
  return e;
}

public static void replaceTextNodes(Node root) {
  if (root instanceof TextNode)
    root.replaceWith(toTextElement(((TextNode) root).text()));
  else
    for (Node child : root.childNodes())
      replaceTextNodes(child);
}

代码示例来源:origin: org.aperteworkflow/webapi

private void addClaimActionButton(Element parent) {
  String actionButtonId = "action-button-claim";
  Element buttonNode = parent.ownerDocument().createElement("button")
      .attr("class", "btn btn-warning")
      .attr("disabled", "true")
      .attr("id", actionButtonId);
  parent.appendChild(buttonNode);
  Element cancelButtonIcon = parent.ownerDocument().createElement("span")
      .attr("class", "glyphicon glyphicon-download");
  parent.appendChild(buttonNode);
  buttonNode.appendChild(cancelButtonIcon);
  buttonNode.appendText(i18Source.getMessage("button.claim"));
  Long processStateConfigurationId = task.getCurrentProcessStateConfiguration().getId();
  scriptBuilder.append("$('#").append(actionButtonId)
      .append("').click(function() { claimTaskFromQueue('#action-button-claim','null', '")
      .append(processStateConfigurationId).append("','")
      .append(task.getInternalTaskId())
      .append("'); });")
      .append("$('#").append(actionButtonId)
      .append("').tooltip({placement: 'bottom', title: '").append(i18Source.getMessage("button.claim.descrition")).append("'});");
}

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

private static void setupMetaAndTitle(Element head,
    BootstrapContext context) {
  head.appendElement(META_TAG).attr("http-equiv", "Content-Type").attr(
      CONTENT_ATTRIBUTE,
      ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
  head.appendElement(META_TAG).attr("http-equiv", "X-UA-Compatible")
      .attr(CONTENT_ATTRIBUTE, "IE=edge");
  head.appendElement("base").attr("href", getServiceUrl(context));
  head.appendElement(META_TAG).attr("name", VIEWPORT)
      .attr(CONTENT_ATTRIBUTE, BootstrapUtils
          .getViewportContent(context).orElse(Viewport.DEFAULT));
  if (!BootstrapUtils.getMetaTargets(context).isEmpty()) {
    BootstrapUtils.getMetaTargets(context)
        .forEach((name, content) -> head.appendElement(META_TAG)
            .attr("name", name)
            .attr(CONTENT_ATTRIBUTE, content));
  }
  resolvePageTitle(context).ifPresent(title -> {
    if (!title.isEmpty()) {
      head.appendElement("title").appendText(title);
    }
  });
}

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

/**
 * Writes the declarative design to the given table cell element.
 *
 * @since 7.5.0
 * @param cellElement
 *            Element to write design to
 * @param designContext
 *            the design context
 */
protected void writeDesign(Element cellElement,
    DesignContext designContext) {
  switch (cellState.type) {
  case TEXT:
    cellElement.attr("plain-text", true);
    cellElement.appendText(getText());
    break;
  case HTML:
    cellElement.append(getHtml());
    break;
  case WIDGET:
    cellElement.appendChild(
        designContext.createElement(getComponent()));
    break;
  }
}

代码示例来源:origin: com.vaadin.addon/vaadin-touchkit-agpl

element = document.createElement("script");
element.attr("type", "text/javascript");
element.appendText("\nwindow.name = '"
    + response.getUiClass().hashCode() + "';\n");
head.appendChild(element);

代码示例来源:origin: zhegexiaohuozi/JsoupXpath

/**
   * 函数具体逻辑
   *
   * @param scope 上下文
   * @return 计算好的节点
   */
  @Override
  public XValue call(Scope scope) {
    Elements context = new Elements();
    for (Element el:scope.context()){
      context.addAll(el.children());
      String  txt = el.ownText();
      if (StringUtils.isNotBlank(txt)){
        Element et = new Element("");
        et.appendText(txt);
        context.add(et);
      }
    }
    return XValue.create(context);
  }
}

代码示例来源:origin: cn.wanghaomiao/JsoupXpath

/**
   * 函数具体逻辑
   *
   * @param scope 上下文
   * @return 计算好的节点
   */
  @Override
  public XValue call(Scope scope) {
    Elements context = new Elements();
    for (Element el:scope.context()){
      context.addAll(el.children());
      String  txt = el.ownText();
      if (StringUtils.isNotBlank(txt)){
        Element et = new Element("");
        et.appendText(txt);
        context.add(et);
      }
    }
    return XValue.create(context);
  }
}

代码示例来源:origin: theonedev/onedev

element.addClass("commit");
element.attr("href", commitUrl);
element.appendText(textNode.getWholeText());
textNode.replaceWith(element);

相关文章

Element类方法