Java Code Examples for org.jsoup.internal.StringUtil

The following examples show how to use org.jsoup.internal.StringUtil. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flow   Source File: UsageStatisticsExporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source Project: Recaf   Source File: FormattingVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public void head(Node node, int depth) {
	String name = node.nodeName();
	// TextNodes carry all user-readable text in the DOM.
	if(node instanceof TextNode)
		text(((TextNode) node).text());
	// Other nodes are used only for formatting, not content
	else if(name.equals("li"))
		text("\n * ");
	else if(name.equals("dt"))
		text("  ");
	else if(StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
		spacing(node);
}
 
Example 3
Source Project: flow   Source File: IndexHtmlRequestHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void should_export_usage_statistics_in_development_mode()
        throws IOException {
    deploymentConfiguration.setProductionMode(false);

    indexHtmlRequestHandler.synchronizedHandleRequest(session,
            createVaadinRequest("/"), response);

    String indexHtml = responseOutput
            .toString(StandardCharsets.UTF_8.name());
    Document document = Jsoup.parse(indexHtml);

    Elements bodyInlineElements = document.body()
            .getElementsByTag("script");
    assertEquals(2, bodyInlineElements.size());

    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 || {}; "
                    + "window.Vaadin.registrations = window.Vaadin.registrations || [];\n"
                    + "window.Vaadin.registrations.push(" + entries + ");");

    assertEquals(StringUtil.normaliseWhitespace(expected),
            bodyInlineElements.get(1).childNode(0).outerHtml());
}
 
Example 4
Source Project: storm-crawler   Source File: TextExtractor.java    License: Apache License 2.0 5 votes vote down vote up
private static void appendNormalisedText(StringBuilder accum,
        TextNode textNode) {
    String text = textNode.getWholeText();

    if (preserveWhitespace(textNode.parent())
            || textNode instanceof CDataNode)
        accum.append(text);
    else
        StringUtil.appendNormalisedWhitespace(accum, text,
                lastCharIsWhitespace(accum));
}
 
Example 5
Source Project: Recaf   Source File: FormattingVisitor.java    License: MIT License 4 votes vote down vote up
@Override
public void tail(Node node, int depth) {
	String name = node.nodeName();
	if(StringUtil.in(name, "br", "dd", "dt", "p", "h1", "h2", "h3", "h4", "h5", "ul", "ol", "table"))
		spacing(node);
}