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

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

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

Element.appendElement介绍

[英]Create a new element by tag name, and add it as the last child.
[中]按标记名创建新元素,并将其添加为最后一个子元素。

代码示例

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

/**
 Create a valid, empty shell of a document, suitable for adding more elements to.
 @param baseUri baseUri of document
 @return document with html, head, and body elements.
 */
public static Document createShell(String baseUri) {
  Validate.notNull(baseUri);
  Document doc = new Document(baseUri);
  Element html = doc.appendElement("html");
  html.appendElement("head");
  html.appendElement("body");
  return doc;
}

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

/**
 Set the document's {@code title} element. Updates the existing element, or adds {@code title} to {@code head} if
 not present
 @param title string to set as title
 */
public void title(String title) {
  Validate.notNull(title);
  Element titleEl = getElementsByTag("title").first();
  if (titleEl == null) { // add to head
    head().appendElement("title").text(title);
  } else {
    titleEl.text(title);
  }
}

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

head.appendElement("meta").attr("charset", charset().displayName());

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

/**
 Normalise the document. This happens after the parse phase so generally does not need to be called.
 Moves any text content that is not in the body element into the body.
 @return this document after normalisation
 */
public Document normalise() {
  Element htmlEl = findFirstElementByTagName("html", this);
  if (htmlEl == null)
    htmlEl = appendElement("html");
  if (head() == null)
    htmlEl.prependElement("head");
  if (body() == null)
    htmlEl.appendElement("body");
  // pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care
  // of. do in inverse order to maintain text order.
  normaliseTextNodes(head());
  normaliseTextNodes(htmlEl);
  normaliseTextNodes(this);
  normaliseStructure("head", htmlEl);
  normaliseStructure("body", htmlEl);
  
  ensureMetaCharsetElement();
  
  return this;
}

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

@Override
public void writeDesign(Element design, DesignContext designContext) {
  super.writeDesign(design, designContext);
  // Parameters, in alphabetic order
  List<String> paramNames = new ArrayList<>();
  for (String param : getParameterNames()) {
    paramNames.add(param);
  }
  Collections.sort(paramNames);
  for (String param : paramNames) {
    design.appendElement("parameter").attr("name", param).attr("value",
        getParameter(param));
  }
}

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

/**
 * Fills in the design with rows and empty columns. This needs to be done
 * for empty {@link GridLayout}, because there's no other way to serialize
 * info about number of columns and rows if there are absolutely no
 * components in the {@link GridLayout}
 *
 * @param design
 * @param designContext
 */
private void writeEmptyColsAndRows(Element design,
    DesignContext designContext) {
  int rowCount = getState(false).rows;
  int colCount = getState(false).columns;
  // only write cols and rows tags if size is not 1x1
  if (rowCount == 1 && colCount == 1) {
    return;
  }
  for (int i = 0; i < rowCount; i++) {
    Element row = design.appendElement("row");
    for (int j = 0; j < colCount; j++) {
      row.appendElement("column");
    }
  }
}

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

private void writeRow(Element container, T item, DesignContext context) {
  Element tableRow = container.appendElement("tr");
  tableRow.attr("item", serializeDeclarativeRepresentation(item));
  if (getSelectionModel().isSelected(item)) {
    tableRow.attr("selected", true);
  }
  for (Column<T, ?> column : getColumns()) {
    Object value = column.valueProvider.apply(item);
    tableRow.appendElement("td")
        .append(Optional.ofNullable(value).map(Object::toString)
            .map(DesignFormatter::encodeForTextNode)
            .orElse(""));
  }
}

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

/**
 * Writes the declarative design to the given table section element.
 *
 * @param tableSectionElement
 *            Element to write design to
 * @param designContext
 *            the design context
 */
public void writeDesign(Element tableSectionElement,
    DesignContext designContext) {
  for (ROW row : getRows()) {
    Element tr = tableSectionElement.appendElement("tr");
    row.writeDesign(tr, designContext);
  }
}

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

private void writeStructure(Element design, DesignContext designContext) {
  if (getColumns().isEmpty()) {
    return;
  }
  Element tableElement = design.appendElement("table");
  Element colGroup = tableElement.appendElement("colgroup");
  getColumns().forEach(column -> column
      .writeDesign(colGroup.appendElement("col"), designContext));
  // Always write thead. Reads correctly when there no header rows
  getHeader().writeDesign(tableElement.appendElement("thead"),
      designContext);
  if (designContext.shouldWriteData(this)) {
    Element bodyElement = tableElement.appendElement("tbody");
    writeData(bodyElement, designContext);
  }
  if (getFooter().getRowCount() > 0) {
    getFooter().writeDesign(tableElement.appendElement("tfoot"),
        designContext);
  }
}

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

Element cellElement = trElement.appendElement(getCellTagName());

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

private void writeRow(Element container, T item, T parent,
    DesignContext context) {
  Element tableRow = container.appendElement("tr");
  tableRow.attr("item", serializeDeclarativeRepresentation(item));
  if (parent != null) {
    tableRow.attr("parent", serializeDeclarativeRepresentation(parent));
  }
  if (getSelectionModel().isSelected(item)) {
    tableRow.attr("selected", true);
  }
  for (Column<T, ?> column : getColumns()) {
    Object value = column.getValueProvider().apply(item);
    tableRow.appendElement("td")
        .append(Optional.ofNullable(value).map(Object::toString)
            .map(DesignFormatter::encodeForTextNode)
            .orElse(""));
  }
  getDataProvider().fetch(new HierarchicalQuery<>(null, item)).forEach(
      childItem -> writeRow(container, childItem, item, context));
}

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

@Override
public void writeDesign(Element design, DesignContext designContext) {
  super.writeDesign(design, designContext);
  String altText = getAltText();
  if (altText != null && !altText.isEmpty()) {
    design.append(altText);
  }
  for (Resource r : getSources()) {
    Attributes attr = design.appendElement("source").attributes();
    DesignAttributeHandler.writeAttribute("href", attr, r, null,
        Resource.class, designContext);
  }
}

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

head.appendElement("meta").attr("http-equiv", "Content-Type").attr(
    "content", ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
head.appendElement("meta").attr("http-equiv", "X-UA-Compatible")
    .attr("content", "IE=11");
  head.appendElement("meta").attr("name", "viewport").attr("content",
      viewportContent);
    new UICreateEvent(context.getRequest(), context.getUIClass()));
if (title != null) {
  head.appendElement("title").appendText(title);
head.appendElement("style").attr("type", "text/css")
    .appendText("html, body {height:100%;margin:0;}");
if (themeName != null) {
  String themeUri = getThemeUri(context, themeName);
  head.appendElement("link").attr("rel", "shortcut icon")
      .attr("type", "image/vnd.microsoft.icon")
      .attr("href", themeUri + "/favicon.ico");
  head.appendElement("link").attr("rel", "icon")
      .attr("type", "image/vnd.microsoft.icon")
      .attr("href", themeUri + "/favicon.ico");
      .resolveVaadinUri(dependency.getUrl());
  if (type == Type.HTMLIMPORT) {
    head.appendElement("link").attr("rel", "import").attr("href",
        url);

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

@Override
public void writeDesign(Element design, DesignContext designContext) {
  super.writeDesign(design, designContext);
  if (getPoster() != null) {
    Attributes attr = design.appendElement("poster").attributes();
    DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
        null, Resource.class, designContext);
  }
}

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

private void writeItem(Element design, DesignContext designContext, T item,
    T parent) {
  Element itemElement = design.appendElement("node");
  itemElement.attr("item", serializeDeclarativeRepresentation(item));
  if (parent != null) {
    itemElement.attr("parent",
        serializeDeclarativeRepresentation(parent));
  }
  if (getSelectionModel().isSelected(item)) {
    itemElement.attr("selected", true);
  }
  Resource icon = getItemIconGenerator().apply(item);
  DesignAttributeHandler.writeAttribute("icon", itemElement.attributes(),
      icon, null, Resource.class, designContext);
  String text = getItemCaptionGenerator().apply(item);
  itemElement.html(
      Optional.ofNullable(text).map(Object::toString).orElse(""));
  getDataProvider().fetch(new HierarchicalQuery<>(null, item)).forEach(
      childItem -> writeItem(design, designContext, childItem, item));
}

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

@Override
protected Element writeItem(Element design, T item, DesignContext context) {
  Element element = design.appendElement("option");
  String caption = getItemCaptionGenerator().apply(item);
  if (caption != null) {
    element.html(DesignFormatter.encodeForTextNode(caption));
  } else {
    element.html(DesignFormatter.encodeForTextNode(item.toString()));
  }
  element.attr("item", item.toString());
  Resource icon = getItemIconGenerator().apply(item);
  if (icon != null) {
    DesignAttributeHandler.writeAttribute("icon", element.attributes(),
        icon, null, Resource.class, context);
  }
  String style = getStyleGenerator().apply(item);
  if (style != null) {
    element.attr("style", style);
  }
  if (isSelected(item)) {
    element.attr("selected", true);
  }
  return element;
}

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

mainDiv.attr("style", style);
mainDiv.appendElement("div").addClass("v-app-loading");
mainDiv.appendElement("noscript").append(
    "You have to enable javascript in your browser to use an application built with Vaadin.");
fragmentNodes.add(mainDiv);

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

Element row = design.appendElement("row");
    col = row.appendElement("column");
    col = row.appendElement("column");

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

/**
 * Writes a data source Item to a design. Hierarchical select components
 * should override this method to recursively write any child items as well.
 *
 * @param design
 *            the element into which to insert the item
 * @param item
 *            the item to write
 * @param context
 *            the DesignContext instance used in writing
 * @return a JSOUP element representing the {@code item}
 */
protected Element writeItem(Element design, T item, DesignContext context) {
  Element element = design.appendElement("option");
  String caption = getItemCaptionGenerator().apply(item);
  if (caption != null) {
    element.html(DesignFormatter.encodeForTextNode(caption));
  } else {
    element.html(DesignFormatter.encodeForTextNode(item.toString()));
  }
  element.attr("item", serializeDeclarativeRepresentation(item));
  Resource icon = getItemIconGenerator().apply(item);
  if (icon != null) {
    DesignAttributeHandler.writeAttribute("icon", element.attributes(),
        icon, null, Resource.class, context);
  }
  return element;
}

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

Element tabElement = design.appendElement("tab");

相关文章

微信公众号

最新文章

更多

Element类方法