Search in sources :

Example 1 with Template

use of org.structr.web.entity.dom.Template in project structr by structr.

the class DeploymentTest method test18NonNamedNonSharedTemplateWithChildren.

@Test
public void test18NonNamedNonSharedTemplateWithChildren() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test18");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test18");
        final Body body = createElement(page, html, "body");
        final Template template = createTemplate(page, body, "${render(children)}");
        final Template sharedTemplate = createComponent(template);
        // remove original template from page
        app.delete(template);
        createElement(page, sharedTemplate, "div");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 2 with Template

use of org.structr.web.entity.dom.Template in project structr by structr.

the class DeploymentTest method test11TemplateInTbody.

@Test
public void test11TemplateInTbody() {
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test11");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test11_1");
        final Body body1 = createElement(page1, html1, "body");
        final Table table = createElement(page1, body1, "table");
        final Tbody tbody = createElement(page1, table, "tbody");
        final Template template1 = createTemplate(page1, tbody, "<tr><td>${user.name}</td></tr>");
        final PropertyMap template1Properties = new PropertyMap();
        template1Properties.put(StructrApp.key(DOMNode.class, "functionQuery"), "find('User')");
        template1Properties.put(StructrApp.key(DOMNode.class, "dataKey"), "user");
        template1.setProperties(template1.getSecurityContext(), template1Properties);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Head(org.structr.web.entity.html.Head) Table(org.structr.web.entity.html.Table) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Tbody(org.structr.web.entity.html.Tbody) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 3 with Template

use of org.structr.web.entity.dom.Template in project structr by structr.

the class DeploymentTest method test34WidgetWithTemplate.

@Test
public void test34WidgetWithTemplate() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page testPage = Page.createNewPage(securityContext, "WidgetTestPage");
        final Html html = createElement(testPage, testPage, "html");
        final Head head = createElement(testPage, html, "head");
        final Body body = createElement(testPage, html, "body");
        final Div div = createElement(testPage, body, "div");
        final Div div2 = createElement(testPage, body, "div");
        div.setProperty(AbstractNode.name, "WidgetTestPage-Div");
        div2.setProperty(AbstractNode.name, "WidgetTestPage-Div2");
        Widget widgetToImport = app.create(Widget.class, new NodeAttribute<>(StructrApp.key(Widget.class, "name"), "TestWidget"), new NodeAttribute<>(StructrApp.key(Widget.class, "source"), "<!-- @structr:content(text/html) --><structr:template>${{Structr.print(\"<div>Test</div>\");}}</structr:template>"), new NodeAttribute<>(StructrApp.key(Widget.class, "configuration"), "{\"processDeploymentInfo\": true}"), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToPublicUsers"), true), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToAuthenticatedUsers"), true));
        Importer importer = new Importer(securityContext, widgetToImport.getProperty(new StringProperty("source")), null, null, true, true);
        importer.setIsDeployment(true);
        importer.setCommentHandler(new DeploymentCommentHandler());
        importer.parse(true);
        DOMNode template = importer.createComponentChildNodes(div, testPage);
        div.appendChild(template);
        makePublic(testPage, html, head, body, div, div2, template);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    try (final Tx tx = app.tx()) {
        Div div = (Div) app.nodeQuery().andName("WidgetTestPage-Div").getFirst();
        assertEquals(1, div.treeGetChildCount());
        Object obj = div.treeGetFirstChild();
        assertTrue(Template.class.isAssignableFrom(obj.getClass()));
        Template template = (Template) obj;
        assertEquals("${{Structr.print(\"<div>Test</div>\");}}", template.getTextContent());
        assertEquals("text/html", template.getContentType());
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Widget(org.structr.web.entity.Widget) Html(org.structr.web.entity.html.Html) StringProperty(org.structr.core.property.StringProperty) Page(org.structr.web.entity.dom.Page) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Div(org.structr.web.entity.html.Div) DeploymentCommentHandler(org.structr.web.maintenance.deploy.DeploymentCommentHandler) GraphObject(org.structr.core.GraphObject) DOMNode(org.structr.web.entity.dom.DOMNode) Body(org.structr.web.entity.html.Body) Importer(org.structr.web.importer.Importer) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 4 with Template

use of org.structr.web.entity.dom.Template in project structr by structr.

the class DeploymentTest method test08SharedTemplateInTwoPages.

@Test
public void test08SharedTemplateInTwoPages() {
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test08_1");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test08_1");
        final Body body1 = createElement(page1, html1, "body");
        final Div div1 = createElement(page1, body1, "div");
        final Template template1 = createTemplate(page1, div1, "template source - öäüÖÄÜß'\"'`");
        final Template component = createComponent(template1);
        // create second page
        final Page page2 = Page.createNewPage(securityContext, "test08_2");
        final Html html2 = createElement(page2, page2, "html");
        final Head head2 = createElement(page2, html2, "head");
        createElement(page2, head2, "title", "test08_2");
        final Body body2 = createElement(page2, html2, "body");
        final Div div2 = createElement(page2, body2, "div");
        // re-use template from above
        cloneComponent(component, div2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 5 with Template

use of org.structr.web.entity.dom.Template in project structr by structr.

the class DeploymentTest method test17NamedNonSharedTemplateWithChildren.

@Test
public void test17NamedNonSharedTemplateWithChildren() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test17");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test17");
        final Body body = createElement(page, html, "body");
        final Template template = createTemplate(page, body, "${render(children)}");
        template.setProperty(AbstractNode.name, "a-template");
        final Template sharedTemplate = createComponent(template);
        // remove original template from page
        app.delete(template);
        createElement(page, sharedTemplate, "div");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Template(org.structr.web.entity.dom.Template) MailTemplate(org.structr.core.entity.MailTemplate) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Template (org.structr.web.entity.dom.Template)21 Tx (org.structr.core.graph.Tx)15 FrameworkException (org.structr.common.error.FrameworkException)14 MailTemplate (org.structr.core.entity.MailTemplate)13 Page (org.structr.web.entity.dom.Page)13 Test (org.junit.Test)12 StructrUiTest (org.structr.web.StructrUiTest)12 Body (org.structr.web.entity.html.Body)10 Head (org.structr.web.entity.html.Head)10 Html (org.structr.web.entity.html.Html)10 PropertyMap (org.structr.core.property.PropertyMap)8 DOMNode (org.structr.web.entity.dom.DOMNode)8 Div (org.structr.web.entity.html.Div)7 NodeAttribute (org.structr.core.graph.NodeAttribute)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 TreeMap (java.util.TreeMap)2 PropertyKey (org.structr.core.property.PropertyKey)2 ShadowDocument (org.structr.web.entity.dom.ShadowDocument)2