use of org.structr.web.entity.html.Head 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.");
}
}
use of org.structr.web.entity.html.Head 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);
}
use of org.structr.web.entity.html.Head 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);
}
use of org.structr.web.entity.html.Head 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);
}
use of org.structr.web.entity.html.Head 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);
}
Aggregations