Package org.structr.web.entity.dom

Examples of org.structr.web.entity.dom.Page


    final App app = StructrApp.getInstance(securityContext);

    if (nodeToClone != null) {

      try {
        final Page pageToClone = nodeToClone instanceof Page ? (Page) nodeToClone : null;

        if (pageToClone != null) {

          //final List<DOMNode> elements = pageToClone.getProperty(Page.elements);
         
          DOMNode firstChild = (DOMNode) pageToClone.getFirstChild().getNextSibling();
         
          if (firstChild == null) {
            firstChild = (DOMNode) pageToClone.treeGetFirstChild();
          }
         
          final DOMNode newHtmlNode = cloneAndAppendChildren(securityContext, firstChild);
          final Page newPage = Page.createNewPage(securityContext, newName);
         
          newPage.appendChild(newHtmlNode);

        }

      } catch (FrameworkException fex) {
View Full Code Here


  }

  public void testVariableReplacement() {

    final Date now = new Date();
    Page page      = null;
    DOMNode html   = null;
    DOMNode head   = null;
    DOMNode body   = null;
    DOMNode title  = null;
    DOMNode h1     = null;
    DOMNode div1   = null;
    DOMNode p1     = null;
    DOMNode div2   = null;
    DOMNode p2     = null;
    DOMNode div3   = null;
    DOMNode p3     = null;
    DOMNode a      = null;
    DOMNode div4   = null;
    DOMNode p4     = null;

    try (final Tx tx = app.tx()) {

      page = Page.createNewPage(securityContext, "testpage");

      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");
      h1    = (DOMNode) page.createElement("h1");
      div1  = (DOMNode) page.createElement("div");
      p1    = (DOMNode) page.createElement("p");
      div2  = (DOMNode) page.createElement("div");
      p2    = (DOMNode) page.createElement("p");
      div3  = (DOMNode) page.createElement("div");
      p3    = (DOMNode) page.createElement("p");
      a     = (DOMNode) page.createElement("a");
      div4  = (DOMNode) page.createElement("div");
      p4    = (DOMNode) page.createElement("p");

      // 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);

      // add H1 element to BODY
      body.appendChild(h1);

      // add DIV element 1 to BODY
      body.appendChild(div1);
      div1.appendChild(p1);

      // add DIV element 2 to DIV
      div1.appendChild(div2);
      div2.appendChild(p2);

      // add DIV element 3 to DIV
      div2.appendChild(div3);
      div3.appendChild(p3);

      // add link to p3
      p3.appendChild(a);
      a.setProperty(LinkSource.linkable, page);

      body.appendChild(div4);
      div4.appendChild(p4);

      p4.setProperty(DOMElement.restQuery, "/divs");
      p4.setProperty(DOMElement.dataKey, "div");

      NodeList paragraphs = page.getElementsByTagName("p");
      assertEquals(p1, paragraphs.item(0));
      assertEquals(p2, paragraphs.item(1));
      assertEquals(p3, paragraphs.item(2));
      assertEquals(p4, paragraphs.item(3));

      // create users
      final User tester1 = app.create(User.class, new NodeAttribute<>(User.name, "tester1"), new NodeAttribute<>(User.eMail, "tester1@test.com"));
      final User tester2 = app.create(User.class, new NodeAttribute<>(User.name, "tester2"), new NodeAttribute<>(User.eMail, "tester2@test.com"));

      assertNotNull("User tester1 should exist.", tester1);
      assertNotNull("User tester2 should exist.", tester2);

      tx.success();

    } catch (FrameworkException fex) {

      fail("Unexpected exception");
    }

    try (final Tx tx = app.tx()) {

      final RenderContext ctx = new RenderContext();
      ctx.setPage(page);

      // test for "empty" return value
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${err}"));
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.error}"));
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.this.this.error}"));
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${parent.error}"));
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${this.owner}"));
      assertEquals("", p1.replaceVariables(securityContext, ctx, "${parent.owner}"));

      // other functions are tested in the ActionContextTest in structr-core, see there.
      assertEquals("true", p1.replaceVariables(securityContext, ctx, "${true}"));
      assertEquals("false", p1.replaceVariables(securityContext, ctx, "${false}"));
      assertEquals("yes", p1.replaceVariables(securityContext, ctx, "${if(true, \"yes\", \"no\")}"));
      assertEquals("no", p1.replaceVariables(securityContext, ctx, "${if(false, \"yes\", \"no\")}"));
      assertEquals("true", p1.replaceVariables(securityContext, ctx, "${if(true, true, false)}"));
      assertEquals("false", p1.replaceVariables(securityContext, ctx, "${if(false, true, false)}"));

      assertEquals("${element} should evaluate to the current DOM node", p1.toString(), p1.replaceVariables(securityContext, ctx, "${element}"));

      assertNull(p1.replaceVariables(securityContext, ctx, "${if(true, null, \"no\")}"));
      assertNull(p1.replaceVariables(securityContext, ctx, "${null}"));

      assertEquals("Invalid replacement result", "/testpage?" + page.getUuid(), p1.replaceVariables(securityContext, ctx, "/${page.name}?${page.id}"));
      assertEquals("Invalid replacement result", "/testpage?" + page.getUuid(), a.replaceVariables(securityContext, ctx, "/${link.name}?${link.id}"));

      // these tests find single element => success
      assertEquals("Invalid replacement result", page.getUuid(), a.replaceVariables(securityContext, ctx, "${get(find('Page', 'name', 'testpage'), 'id')}"));
      assertEquals("Invalid replacement result", a.getUuid(), a.replaceVariables(securityContext, ctx, "${get(find('A'), 'id')}"));

      // this test finds multiple <p> elements => error
      assertEquals("Invalid replacement result", Functions.ERROR_MESSAGE_GET_ENTITY, a.replaceVariables(securityContext, ctx, "${get(find('P'), 'id')}"));
View Full Code Here

   *
   * @throws FrameworkException
   */
  private void fixLostComponents() throws FrameworkException {
   
    Page hiddenDoc                            = getOrCreateHiddenDocument();
    SecurityContext securityContext           = SecurityContext.getSuperUserInstance();
    Result<DOMNode> result                    = StructrApp.getInstance(securityContext).nodeQuery(DOMNode.class).getResult();
    final CreateRelationshipCommand createRel = StructrApp.getInstance(securityContext).command(CreateRelationshipCommand.class);
   
    for (DOMNode node : result.getResults()) {
     
      if (node.hasChildNodes()
        && (node.hasIncomingRelationships(Sync.class) || node.hasRelationship(Sync.class))
        && (!hiddenDoc.equals(node.getOwnerDocument()))
        ) {
       
        try {
       
          DOMNode clonedNode = (DOMNode) node.cloneNode(false);
View Full Code Here

   * @throws IOException
   * @throws FrameworkException
   */
  private Page notFound(final HttpServletResponse response, final SecurityContext securityContext) throws IOException, FrameworkException {

    final Page errorPage = StructrApp.getInstance(securityContext).nodeQuery(Page.class).and(Page.showOnErrorCodes, "404", false).getFirst();

    if (errorPage != null) {

      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
      return errorPage;
View Full Code Here

    for (Linkable node : entryPoints) {

      if (node instanceof Page) { // && path.equals(node.getPath())) {

        final Page page = (Page) node;
        final Site site = page.getProperty(Page.site);

        if (site != null) {

          final String serverName = request.getServerName();
          final int    serverPort = request.getServerPort();
View Full Code Here

    final App app                         = StructrApp.getInstance(securityContext);
    final String id                       = webSocketData.getId();

    try (final Tx tx = app.tx()) {

      final Page page                = app.get(Page.class, id);
      final List<GraphObject> result = new LinkedList<>();

      if (page != null) {

        collectActiveElements(result, page, Collections.EMPTY_SET, null, 0);
View Full Code Here

    final Result<Page> results = StructrApp.getInstance(securityContext).nodeQuery(Page.class).sort(Page.position).order(false).getResult();
    Collections.sort(results.getResults(), new GraphObjectComparator(Page.position, GraphObjectComparator.ASCENDING));

    // Find first visible page
    Page page = null;

    if (!results.isEmpty()) {

      int i = 0;
View Full Code Here

    final Map<String, Object> nodeData = webSocketData.getNodeData();
    final String modifiedHtml = (String) nodeData.get("source");
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);

    Page modifiedPage = null;

    Page sourcePage = getPage(pageId);
    if (sourcePage != null) {

      try {

        // parse page from modified source
View Full Code Here

        return;

      }

      Page page = getPage(pageId);
      if (page != null) {

        try {
          Widget.expandWidget(getWebSocket().getSecurityContext(), page, parentDOMNode, baseUrl, nodeData);
         
View Full Code Here

  }

  public Page readPage() throws FrameworkException {

    Page page = Page.createNewPage(securityContext, name);

    if (page != null) {

      page.setProperty(AbstractNode.visibleToAuthenticatedUsers, authVisible);
      page.setProperty(AbstractNode.visibleToPublicUsers, publicVisible);
      createChildNodes(parsedDocument, page, page);
      logger.log(Level.INFO, "##### Finished fetching {0} for page {1} #####", new Object[]{address, name});

    }
View Full Code Here

TOP

Related Classes of org.structr.web.entity.dom.Page

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.