Search in sources :

Example 36 with DOMNode

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

the class DeploymentTest method calculateHash.

private void calculateHash(final NodeInterface start, final StringBuilder buf, final int depth) {
    buf.append(start.getType()).append("{");
    hash(start, buf);
    // indent
    for (int i = 0; i < depth; i++) {
        System.out.print("    ");
    }
    System.out.println(start.getType() + ": " + start.getUuid().substring(0, 5));
    if (start instanceof ShadowDocument) {
        for (final DOMNode child : ((ShadowDocument) start).getElements()) {
            // only include toplevel elements of the shadow document
            if (child.getParent() == null) {
                calculateHash(child, buf, depth + 1);
            }
        }
    } else if (start instanceof DOMNode) {
        for (final DOMNode child : ((DOMNode) start).getChildren()) {
            calculateHash(child, buf, depth + 1);
        }
    }
    buf.append("}");
}
Also used : ShadowDocument(org.structr.web.entity.dom.ShadowDocument) DOMNode(org.structr.web.entity.dom.DOMNode)

Example 37 with DOMNode

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

the class SimpleTest method testSites.

@Test
public void testSites() {
    try (final Tx tx = app.tx()) {
        // setup two pages and two sites
        // page one -> site one, listens on one:8875
        // page two -> site two, listens on two:8875
        final Page pageOne = app.create(Page.class, "page-one");
        try {
            final Element html = pageOne.createElement("html");
            ((DOMNode) html).setProperties(((DOMNode) html).getSecurityContext(), new PropertyMap(DOMNode.visibleToPublicUsers, true));
            final Text textNode = pageOne.createTextNode("page-1");
            ((DOMNode) textNode).setProperties(((DOMNode) textNode).getSecurityContext(), new PropertyMap(DOMNode.visibleToPublicUsers, true));
            pageOne.appendChild(html);
            html.appendChild(textNode);
        } catch (DOMException dex) {
            logger.warn("", dex);
            throw new FrameworkException(422, dex.getMessage());
        }
        final Page pageTwo = app.create(Page.class, "page-two");
        try {
            final Element html = pageTwo.createElement("html");
            ((DOMNode) html).setProperties(((DOMNode) html).getSecurityContext(), new PropertyMap(DOMNode.visibleToPublicUsers, true));
            final Text textNode = pageTwo.createTextNode("page-2");
            ((DOMNode) textNode).setProperties(((DOMNode) textNode).getSecurityContext(), new PropertyMap(DOMNode.visibleToPublicUsers, true));
            pageTwo.appendChild(html);
            html.appendChild(textNode);
        } catch (DOMException dex) {
            logger.warn("", dex);
            throw new FrameworkException(422, dex.getMessage());
        }
        final PropertyMap siteOneProperties = new PropertyMap();
        final PropertyKey<Site> siteKey = StructrApp.key(Page.class, "site");
        final PropertyKey<Integer> positionKey = StructrApp.key(Page.class, "position");
        final PropertyKey<Integer> portKey = StructrApp.key(Site.class, "port");
        final PropertyKey<String> hostnameKey = StructrApp.key(Site.class, "hostname");
        siteOneProperties.put(Site.name, "site-one");
        siteOneProperties.put(Site.visibleToPublicUsers, true);
        siteOneProperties.put(hostnameKey, "localhost");
        siteOneProperties.put(portKey, 8875);
        final PropertyMap siteTwoProperties = new PropertyMap();
        siteTwoProperties.put(Site.name, "site-two");
        siteTwoProperties.put(Site.visibleToPublicUsers, true);
        siteTwoProperties.put(hostnameKey, "127.0.0.1");
        siteTwoProperties.put(portKey, 8875);
        final Site siteOne = app.create(Site.class, siteOneProperties);
        final Site siteTwo = app.create(Site.class, siteTwoProperties);
        final PropertyMap pageOneProperties = new PropertyMap();
        pageOneProperties.put(siteKey, siteOne);
        pageOneProperties.put(Page.visibleToPublicUsers, true);
        pageOneProperties.put(positionKey, 10);
        pageOne.setProperties(pageOne.getSecurityContext(), pageOneProperties);
        final PropertyMap pageTwoProperties = new PropertyMap();
        pageTwoProperties.put(siteKey, siteTwo);
        pageTwoProperties.put(Page.visibleToPublicUsers, true);
        pageTwoProperties.put(positionKey, 10);
        pageTwo.setProperties(pageTwo.getSecurityContext(), pageTwoProperties);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    RestAssured.given().filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().response().contentType("text/html").statusCode(200).body(Matchers.containsString("page-1")).when().get("http://localhost:8875/");
    RestAssured.given().filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().response().contentType("text/html").statusCode(200).body(Matchers.containsString("page-2")).when().get("http://127.0.0.1:8875/");
}
Also used : Site(org.structr.web.entity.Site) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMElement(org.structr.web.entity.dom.DOMElement) Element(org.w3c.dom.Element) Page(org.structr.web.entity.dom.Page) Text(org.w3c.dom.Text) DOMException(org.w3c.dom.DOMException) PropertyMap(org.structr.core.property.PropertyMap) DOMNode(org.structr.web.entity.dom.DOMNode) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 38 with DOMNode

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

the class SiteTest method makePublicRecursively.

private void makePublicRecursively(final DOMNode node) throws FrameworkException {
    node.setProperty(StructrApp.key(DOMNode.class, "visibleToAuthenticatedUsers"), true);
    node.setProperty(StructrApp.key(DOMNode.class, "visibleToPublicUsers"), true);
    for (final DOMNode child : node.getChildren()) {
        makePublicRecursively(child);
    }
}
Also used : DOMNode(org.structr.web.entity.dom.DOMNode)

Example 39 with DOMNode

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

the class UiScriptingTest method testScripting.

@Test
public void testScripting() {
    NodeInterface detailsDataObject = null;
    Page page = null;
    DOMNode html = null;
    DOMNode head = null;
    DOMNode body = null;
    DOMNode title = null;
    DOMNode div = null;
    DOMNode p = null;
    DOMNode text = null;
    try (final Tx tx = app.tx()) {
        detailsDataObject = app.create(TestOne.class, "TestOne");
        page = Page.createNewPage(securityContext, "testpage");
        page.setProperties(page.getSecurityContext(), new PropertyMap(Page.visibleToPublicUsers, true));
        assertTrue(page != null);
        assertTrue(page instanceof Page);
        html = (DOMNode) page.createElement("html");
        head = (DOMNode) page.createElement("head");
        body = (DOMNode) page.createElement("body");
        title = (DOMNode) page.createElement("title");
        div = (DOMNode) page.createElement("div");
        p = (DOMNode) page.createElement("p");
        text = (DOMNode) page.createTextNode("x");
        // add HTML element to page
        page.appendChild(html);
        // add HEAD and BODY elements to HTML
        html.appendChild(head);
        html.appendChild(body);
        // add TITLE element to HEAD
        head.appendChild(title);
        body.appendChild(div);
        div.appendChild(p);
        final PropertyMap changedProperties = new PropertyMap();
        changedProperties.put(StructrApp.key(DOMElement.class, "restQuery"), "/divs");
        changedProperties.put(StructrApp.key(DOMElement.class, "dataKey"), "div");
        p.setProperties(p.getSecurityContext(), changedProperties);
        p.appendChild(text);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        final RenderContext ctx = new RenderContext(securityContext, new RequestMockUp(), new ResponseMockUp(), RenderContext.EditMode.NONE);
        ctx.setDetailsDataObject(detailsDataObject);
        ctx.setPage(page);
        test(p, text, "${{ return Structr.get('div').id}}", "<p>" + div.getUuid() + "</p>", ctx);
        test(p, text, "${{ return Structr.get('page').id}}", "<p>" + page.getUuid() + "</p>", ctx);
        test(p, text, "${{ return Structr.get('parent').id}}", "<p>" + p.getUuid() + "</p>", ctx);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : RenderContext(org.structr.web.common.RenderContext) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) TestOne(org.structr.web.entity.TestOne) DOMNode(org.structr.web.entity.dom.DOMNode) DOMElement(org.structr.web.entity.dom.DOMElement) NodeInterface(org.structr.core.graph.NodeInterface) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 40 with DOMNode

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

the class CustomHtmlAttributeTest 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;
}
Also used : DOMNode(org.structr.web.entity.dom.DOMNode) Node(org.w3c.dom.Node)

Aggregations

DOMNode (org.structr.web.entity.dom.DOMNode)61 FrameworkException (org.structr.common.error.FrameworkException)26 Tx (org.structr.core.graph.Tx)19 PropertyMap (org.structr.core.property.PropertyMap)19 Page (org.structr.web.entity.dom.Page)19 DOMException (org.w3c.dom.DOMException)16 App (org.structr.core.app.App)14 StructrApp (org.structr.core.app.StructrApp)14 SecurityContext (org.structr.common.SecurityContext)12 GraphObject (org.structr.core.GraphObject)9 NodeInterface (org.structr.core.graph.NodeInterface)9 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)8 StructrUiTest (org.structr.web.StructrUiTest)8 ShadowDocument (org.structr.web.entity.dom.ShadowDocument)8 AbstractNode (org.structr.core.entity.AbstractNode)7 Template (org.structr.web.entity.dom.Template)7 Document (org.w3c.dom.Document)6 IOException (java.io.IOException)5 PropertyKey (org.structr.core.property.PropertyKey)5