Search in sources :

Example 6 with Body

use of org.structr.web.entity.html.Body 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 7 with Body

use of org.structr.web.entity.html.Body in project structr by structr.

the class DeploymentTest method test04ContentTypes.

@Test
public void test04ContentTypes() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test04");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test04");
        createElement(page, head, "link");
        createElement(page, head, "link");
        createComment(page, head, "commentöäüÖÄÜß+#");
        final Link link3 = createElement(page, head, "link");
        final PropertyMap link3Properties = new PropertyMap();
        link3Properties.put(StructrApp.key(Link.class, "_html_href"), "/");
        link3Properties.put(StructrApp.key(Link.class, "_html_media"), "screen");
        link3Properties.put(StructrApp.key(Link.class, "_html_type"), "stylesheet");
        link3.setProperties(link3.getSecurityContext(), link3Properties);
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        createElement(page, div1, "h1", "private");
        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) 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) Body(org.structr.web.entity.html.Body) Link(org.structr.web.entity.html.Link) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 8 with Body

use of org.structr.web.entity.html.Body in project structr by structr.

the class DeploymentTest method test21ExportGrants.

@Test
public void test21ExportGrants() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    final SecurityContext context1 = SecurityContext.getInstance(user1, AccessMode.Backend);
    final App app1 = StructrApp.getInstance(context1);
    try (final Tx tx = app1.tx()) {
        final Page page = Page.createNewPage(context1, "test21");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test21");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Content content = createContent(page, div1, "<b>Test</b>");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        // create grants
        page.grant(Permission.read, user2);
        div1.grant(Permission.read, user2);
        content.grant(Permission.read, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true, false);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) 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) Div(org.structr.web.entity.html.Div) Content(org.structr.web.entity.dom.Content) SecurityContext(org.structr.common.SecurityContext) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 9 with Body

use of org.structr.web.entity.html.Body in project structr by structr.

the class DeploymentTest method test26Escaping.

@Test
public void test26Escaping() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test25");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test25");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Content content1 = createContent(page, div1, "<div><script>var test = '<h3>Title</h3>';</script></div>");
        content1.setProperty(StructrApp.key(Content.class, "contentType"), "text/html");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    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) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 10 with Body

use of org.structr.web.entity.html.Body in project structr by structr.

the class DeploymentTest method test03ContentTypes.

@Test
public void test03ContentTypes() {
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createNewPage(securityContext, "test03");
        final Html html = createElement(page, page, "html");
        final Head head = createElement(page, html, "head");
        createElement(page, head, "title", "test03");
        final Body body = createElement(page, html, "body");
        final Div div1 = createElement(page, body, "div");
        final Script script = createElement(page, div1, "script");
        final Content content = createContent(page, script, "$(function () {\n\n" + "$('a[data-toggle=\"tab\"]').on('click', function (e) {\n\n" + "var id = $(e.target).attr(\"href\").substr(1) // activated tab\n" + "window.location.hash = id;\n" + "});\n\n" + "});");
        // workaround for strange importer behaviour
        script.setProperty(StructrApp.key(Script.class, "_html_type"), "text/javascript");
        content.setProperty(StructrApp.key(Content.class, "contentType"), "text/javascript");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    compare(calculateHash(), true);
}
Also used : Div(org.structr.web.entity.html.Div) Script(org.structr.web.entity.html.Script) Head(org.structr.web.entity.html.Head) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Content(org.structr.web.entity.dom.Content) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Body(org.structr.web.entity.html.Body) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Body (org.structr.web.entity.html.Body)29 Head (org.structr.web.entity.html.Head)29 Test (org.junit.Test)28 FrameworkException (org.structr.common.error.FrameworkException)28 Tx (org.structr.core.graph.Tx)28 StructrUiTest (org.structr.web.StructrUiTest)28 Page (org.structr.web.entity.dom.Page)28 Html (org.structr.web.entity.html.Html)28 Div (org.structr.web.entity.html.Div)22 MailTemplate (org.structr.core.entity.MailTemplate)10 Template (org.structr.web.entity.dom.Template)10 Content (org.structr.web.entity.dom.Content)8 PropertyMap (org.structr.core.property.PropertyMap)6 DOMNode (org.structr.web.entity.dom.DOMNode)6 GraphObject (org.structr.core.GraphObject)4 NodeAttribute (org.structr.core.graph.NodeAttribute)4 Principal (org.structr.core.entity.Principal)3 StringProperty (org.structr.core.property.StringProperty)3 User (org.structr.web.entity.User)3 Script (org.structr.web.entity.html.Script)3