use of org.structr.web.entity.html.Div in project structr by structr.
the class DeploymentTest method test31RoundtripWithEmptyContentElements.
@Test
public void test31RoundtripWithEmptyContentElements() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createNewPage(securityContext, "test31");
final Html html = createElement(page, page, "html");
final Head head = createElement(page, html, "head");
createElement(page, head, "title", "test31");
final Body body = createElement(page, html, "body");
final Div div1 = createElement(page, body, "div");
final Div div2 = createElement(page, div1, "div", "");
final Table table1 = createElement(page, div2, "table");
final Thead thead = createElement(page, table1, "thead");
final Tbody tbody = createElement(page, table1, "tbody");
final Tr tr1 = createElement(page, thead, "tr");
final Tr tr2 = createElement(page, tbody, "tr");
final Td td11 = createElement(page, tr1, "td");
final Content c1 = createContent(page, td11, "");
final Td td12 = createElement(page, tr1, "td", "content12");
final P p1 = createElement(page, td12, "p", "");
final Ul ul = createElement(page, p1, "ul");
final Li li = createElement(page, ul, "li", "");
final Td td21 = createElement(page, tr2, "td", "content21");
final Td td22 = createElement(page, tr2, "td", "content22");
final Select select = createElement(page, td11, "select");
final Option option1 = createElement(page, select, "option", "");
final Option option2 = createElement(page, select, "option", "value2");
final Content c2 = createContent(page, div2, "");
final Table table2 = createElement(page, div2, "table");
// include visibility flags
page.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
c1.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
c2.setProperty(AbstractNode.visibleToAuthenticatedUsers, true);
// modify visibility to produce two consecutive deployment instruction comments
td12.setProperty(AbstractNode.visibleToPublicUsers, true);
table2.setProperty(AbstractNode.visibleToPublicUsers, true);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
compare(calculateHash(), true);
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class DeploymentTest method test37SharedComponentTemplate.
@Test
public void test37SharedComponentTemplate() {
// setup
try (final Tx tx = app.tx()) {
final Page page = Page.createSimplePage(securityContext, "page1");
final Div div = (Div) page.getElementsByTagName("div").item(0);
try {
final DOMNode newNode = (DOMNode) page.createTextNode("#template");
newNode.unlockSystemPropertiesOnce();
newNode.setProperties(newNode.getSecurityContext(), new PropertyMap(NodeInterface.type, Template.class.getSimpleName()));
// append template
div.appendChild(newNode);
// create component from div
createComponent(div);
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
compare(calculateHash(), true);
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class DeploymentTest method test35WidgetWithSharedComponentCreation.
@Test
public void test35WidgetWithSharedComponentCreation() {
// 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:component src=\"TestComponent\">\n" + " <div data-structr-meta-name=\"TestComponent\">\n" + " Test123\n" + " </div>\n" + "</structr:component>"), new NodeAttribute<>(StructrApp.key(Widget.class, "configuration"), ""), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToPublicUsers"), true), new NodeAttribute<>(StructrApp.key(Widget.class, "visibleToAuthenticatedUsers"), true));
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("widgetHostBaseUrl", "https://widgets.structr.org/structr/rest/widgets");
paramMap.put("parentId", widgetToImport.getProperty(new StartNode<>("owner", PrincipalOwnsNode.class)));
paramMap.put("source", widgetToImport.getProperty(new StringProperty("source")));
paramMap.put("processDeploymentInfo", false);
Widget.expandWidget(securityContext, testPage, div, baseUri, paramMap, false);
Widget.expandWidget(securityContext, testPage, div, baseUri, paramMap, false);
makePublic(testPage, html, head, body, div, div2);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// test
try (final Tx tx = app.tx()) {
Div div = app.nodeQuery(Div.class).andName("WidgetTestPage-Div").getFirst();
assertEquals(2, div.treeGetChildCount());
Object obj = null;
for (DOMNode n : div.getAllChildNodes()) {
obj = n;
break;
}
assertTrue(Div.class.isAssignableFrom(obj.getClass()));
Div clonedNode = (Div) obj;
assertEquals(0, clonedNode.getChildNodes().getLength());
assertEquals(3, app.nodeQuery(Div.class).andName("TestComponent").getResult().size());
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.web.entity.html.Div in project structr by structr.
the class DeploymentTest method test10SharedComponent.
@Test
public void test10SharedComponent() {
// setup
try (final Tx tx = app.tx()) {
// create first page
final Page page1 = Page.createNewPage(securityContext, "test10_1");
final Html html1 = createElement(page1, page1, "html");
final Head head1 = createElement(page1, html1, "head");
createElement(page1, head1, "title", "test10_1");
final Body body1 = createElement(page1, html1, "body");
final Div div1 = createElement(page1, body1, "div");
createElement(page1, div1, "div", "test1");
createElement(page1, div1, "div", "test1");
final Div component = createComponent(div1);
// create second page
final Page page2 = Page.createNewPage(securityContext, "test10_2");
final Html html2 = createElement(page2, page2, "html");
final Head head2 = createElement(page2, html2, "head");
createElement(page2, head2, "title", "test10_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);
}
use of org.structr.web.entity.html.Div 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.");
}
}
Aggregations