org.jsoup.nodes.Document#appendElement ( )源码实例Demo

下面列出了org.jsoup.nodes.Document#appendElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: flow   文件: UsageStatisticsExporterTest.java
@Test
public void should_append_script_element_to_the_body(){
    Document document = new Document("");
    Element html = document.appendElement("html");
    html.appendElement("body");

    UsageStatisticsExporter.exportUsageStatisticsToDocument(document);

    String entries = UsageStatistics.getEntries().map(entry -> {
        JsonObject json = Json.createObject();

        json.put("is", entry.getName());
        json.put("version", entry.getVersion());

        return json.toString();
    }).collect(Collectors.joining(","));

    String expected = StringUtil.normaliseWhitespace(
            "window.Vaadin = window.Vaadin || {};\n" +
                    "window.Vaadin.registrations = window.Vaadin.registrations || [];\n"
                    + "window.Vaadin.registrations.push(" + entries
                    + ");");

    Elements bodyInlineElements = document.body().getElementsByTag("script");
    assertEquals(StringUtil.normaliseWhitespace(expected), bodyInlineElements.get(0).childNode(0).outerHtml());
}
 
源代码2 项目: flow   文件: BootstrapHandler.java
/**
 * Returns the bootstrap page for the given context.
 *
 * @param context
 *            Context to generate bootstrap page for.
 * @return A document with the corresponding HTML page.
 */
@Override
public Document getBootstrapPage(BootstrapContext context) {
    DeploymentConfiguration config = context.getSession()
            .getConfiguration();

    Document document = new Document("");
    DocumentType doctype = new DocumentType("html", "", "");
    document.appendChild(doctype);

    Element html = document.appendElement("html");
    html.attr("lang", context.getUI().getLocale().getLanguage());
    Element head = html.appendElement("head");
    html.appendElement("body");

    List<Element> dependenciesToInlineInBody = setupDocumentHead(head,
            context);
    dependenciesToInlineInBody.forEach(
            dependency -> document.body().appendChild(dependency));
    setupDocumentBody(document);

    document.outputSettings().prettyPrint(false);

    BootstrapUtils.getInlineTargets(context)
            .ifPresent(targets -> handleInlineTargets(context, head,
                    document.body(), targets));

    BootstrapUtils.getInitialPageSettings(context).ifPresent(
            initialPageSettings -> handleInitialPageSettings(context,
                    head, initialPageSettings));

    if (!config.isProductionMode()) {
        UsageStatisticsExporter
                .exportUsageStatisticsToDocument(document);
    }

    setupPwa(document, context);

    if (!config.isProductionMode()) {
        showWebpackErrors(document);
    }

    BootstrapPageResponse response = new BootstrapPageResponse(
            context.getRequest(), context.getSession(),
            context.getResponse(), document, context.getUI(),
            context.getUriResolver());
    context.getSession().getService().modifyBootstrapPage(response);

    return document;
}