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!"));
}
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();
}
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);
}
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();
}
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(" ");
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"));
}
Aggregations