use of org.structr.web.entity.dom.DOMNode in project structr by structr.
the class DeploymentTest method createElement.
private <T extends Node> T createElement(final Page page, final DOMNode parent, final String tag, final String... content) {
final T child = (T) page.createElement(tag);
parent.appendChild((DOMNode) child);
if (content != null && content.length > 0) {
for (final String text : content) {
final Node node = page.createTextNode(text);
child.appendChild(node);
}
}
return child;
}
use of org.structr.web.entity.dom.DOMNode 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.dom.DOMNode 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.dom.DOMNode 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.dom.DOMNode in project structr by structr.
the class SimpleTest method test01DOMChildren.
@Test
public void test01DOMChildren() {
final String pageName = "page-01";
final String pageTitle = "Page Title";
try (final Tx tx = app.tx()) {
Page page = Page.createNewPage(securityContext, pageName);
if (page != null) {
DOMElement html = (DOMElement) page.createElement("html");
DOMElement head = (DOMElement) page.createElement("head");
DOMElement title = (DOMElement) page.createElement("title");
Text titleText = page.createTextNode(pageTitle);
for (AbstractRelationship r : page.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("PAGE", r.getRelType().name());
}
html.appendChild(head);
for (AbstractRelationship r : head.getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
head.appendChild(title);
title.appendChild(titleText);
for (AbstractRelationship r : ((DOMNode) titleText).getIncomingRelationships()) {
System.out.println("============ Relationship: " + r.toString());
assertEquals("CONTAINS", r.getRelType().name());
}
}
tx.success();
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations