Search in sources :

Example 16 with Document

use of org.apache.tapestry5.dom.Document in project helloworld-web by dbelob.

the class IndexTest method loadingIndexTest.

@Test
public void loadingIndexTest() {
    Document document = tester.renderPage("Index");
    String markup = document.toString();
    assertTrue(markup.contains("Hello, World!"));
}
Also used : Document(org.apache.tapestry5.dom.Document) Test(org.junit.Test)

Example 17 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class PageDocumentGeneratorImpl method render.

public Document render(String logicalPageName) {
    Page page = pageCache.get(logicalPageName);
    MarkupWriter writer = markupWriterFactory.newMarkupWriter(logicalPageName);
    markupRenderer.renderPageMarkup(page, writer);
    return writer.getDocument();
}
Also used : Page(org.apache.tapestry5.internal.structure.Page) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Example 18 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class DocumentLinkerImpl method addScriptElements.

private void addScriptElements(Element root) {
    String rootElementName = root.getName();
    Element body = rootElementName.equals("html") ? findOrCreateElement(root, "body", false) : null;
    // "true" once those initializations all run.
    if (body != null) {
        body.attribute("data-page-initialized", Boolean.toString(!hasScriptsOrInitializations));
    }
    if (!hasScriptsOrInitializations) {
        return;
    }
    if (!rootElementName.equals("html")) {
        throw new RuntimeException(String.format("The root element of the rendered document was <%s>, not <html>. A root element of <html> is needed when linking JavaScript and stylesheet resources.", rootElementName));
    }
    // TAPESTRY-2364
    addContentToBody(body);
}
Also used : Element(org.apache.tapestry5.dom.Element)

Example 19 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class DocumentLinkerImpl method addStylesheetsToHead.

/**
 * Locates the head element under the root ("html") element, creating it if necessary, and adds the stylesheets to
 * it.
 *
 * @param root
 *         element of document
 * @param stylesheets
 *         to add to the document
 */
protected void addStylesheetsToHead(Element root, List<StylesheetLink> stylesheets) {
    int count = stylesheets.size();
    if (count == 0) {
        return;
    }
    // This only applies when the document is an HTML document. This may need to change in the
    // future, perhaps configurable, to allow for html and xhtml and perhaps others. Does SVG
    // use stylesheets?
    String rootElementName = root.getName();
    // Not an html document, don't add anything.
    if (!rootElementName.equals("html")) {
        return;
    }
    Element head = findOrCreateElement(root, "head", true);
    // Create a temporary container element.
    Element container = createTemporaryContainer(head, "style", "stylesheet-container");
    for (int i = 0; i < count; i++) {
        stylesheets.get(i).add(container);
    }
    container.pop();
}
Also used : Element(org.apache.tapestry5.dom.Element)

Example 20 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class MarkupWriterImplTest method preamble_content.

@Test
public void preamble_content() throws Exception {
    MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());
    w.comment(" preamble start ");
    w.write("preamble text");
    w.cdata("CDATA content");
    w.writeRaw("&nbsp;");
    w.element("root");
    w.end();
    // You really shouldn't have any text after the close tag of the document, so it
    // gets moved to the top, to the "preamble", before the first element.
    w.comment(" content after root element in preamble ");
    assertEquals(w.getDocument().toString(), readFile("preamble_content.txt"));
}
Also used : XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Aggregations

Document (org.apache.tapestry5.dom.Document)20 Test (org.testng.annotations.Test)19 PageTester (org.apache.tapestry5.test.PageTester)11 Element (org.apache.tapestry5.dom.Element)8 MarkupWriter (org.apache.tapestry5.MarkupWriter)4 Document (elemental2.dom.Document)2 Element (elemental2.dom.Element)2 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)2 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 TestPageForActionLinkWithStream (org.apache.tapestry5.integration.app2.pages.TestPageForActionLinkWithStream)1 TestPageForHttpHeaders (org.apache.tapestry5.integration.app2.pages.TestPageForHttpHeaders)1 Page (org.apache.tapestry5.internal.structure.Page)1 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)1 ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1