Package org.structr.web.entity.dom

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


    }

    // collection of properties must not depend on page
    for (AbstractRelationship rel : startNode.getChildRelationships()) {

      DOMNode endNode = (DOMNode)rel.getTargetNode();

      if (endNode == null) {

        continue;
View Full Code Here


      if (node != null) {

        if (node instanceof DOMNode) {

          // Use new DOM interface
          DOMNode domNode = (DOMNode) node;

          domNode.getParentNode().removeChild(domNode);

          try {

            // Remove node from page
            domNode.setProperty(DOMNode.syncedNodes, Collections.EMPTY_LIST);
            domNode.setProperty(DOMNode.pageId, null);

          } catch (FrameworkException ex) {

            logger.log(Level.SEVERE, "Could not remove node from page " + domNode, ex);
View Full Code Here

      return;

    }

    // check if parent node with given ID exists
    final DOMNode parentNode = (DOMNode) getNode(parentId);

    if (parentNode == null) {

      getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);

      return;

    }


    final DOMNode node = getDOMNode(id);

    try {

      DOMNode clonedNode = (DOMNode) node.cloneNode(false);
      parentNode.appendChild(clonedNode);
      clonedNode.setProperty(DOMNode.sharedComponent, node);
      clonedNode.setProperty(DOMNode.ownerDocument, (parentNode instanceof Page ? (Page) parentNode : parentNode.getProperty(DOMNode.ownerDocument)));
     
    } catch (FrameworkException ex) {

      // send DOM exception
      getWebSocket().send(MessageBuilder.status().code(422).message(ex.getMessage()).build(), true);
View Full Code Here

        try {

          final List<AbstractNode> filteredResults = new LinkedList();
          if (obj instanceof DOMNode) {

            DOMNode node = (DOMNode) obj;

            filteredResults.addAll(DOMNode.getAllChildNodes(node));

          } else if (obj instanceof LinkedTreeNode) {
           
            LinkedTreeNode node = (LinkedTreeNode) obj;

            filteredResults.addAll(node.getAllChildNodes());
           
          }

          for (NodeInterface node : filteredResults) {
            app.delete(node);
View Full Code Here

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

        }
View Full Code Here

   */
  private DOMNode cloneAndAppendChildren(final SecurityContext securityContext, final DOMNode nodeToClone) {

    final App app = StructrApp.getInstance(securityContext);

    final DOMNode newNode = (DOMNode) nodeToClone.cloneNode(false);

    final List<DOMNode> childrenToClone = (List<DOMNode>) nodeToClone.getChildNodes();

    for (final DOMNode childNodeToClone : childrenToClone) {

      final DOMNode newChildNode = (DOMNode) cloneAndAppendChildren(securityContext, childNodeToClone);
      newNode.appendChild(newChildNode);

    }

    return newNode;
View Full Code Here

   * @param sourceNode
   * @param targetNode
   */
  protected void moveChildNodes(final DOMNode sourceNode, final DOMNode targetNode) {

    DOMNode child = (DOMNode) sourceNode.getFirstChild();

    while (child != null) {

      DOMNode next = (DOMNode) child.getNextSibling();

      targetNode.appendChild(child);

      child = next;

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));
View Full Code Here

    String id                             = webSocketData.getId();

    if (id != null) {

      final DOMNode node = (DOMNode) getDOMNode(id);

      try {

        DOMNode clonedNode = (DOMNode) node.cloneNode(false);
       
        // Child nodes of a template must stay in page tree
        if (!(clonedNode instanceof Template)) {
       
          moveChildNodes(node, clonedNode);
       
        }

        ShadowDocument hiddenDoc = getOrCreateHiddenDocument();
        clonedNode.setProperty(DOMNode.ownerDocument, hiddenDoc);

        // Change page (owner document) of all children recursively
        for (DOMNode child : DOMNode.getAllChildNodes(clonedNode)) {
          child.setProperty((DOMNode.ownerDocument), hiddenDoc);
        }
View Full Code Here

        && (!hiddenDoc.equals(node.getOwnerDocument()))
        ) {
       
        try {
       
          DOMNode clonedNode = (DOMNode) node.cloneNode(false);

          moveChildNodes(node, clonedNode);
          clonedNode.setProperty(DOMNode.ownerDocument, hiddenDoc);

          createRel.execute((DOMNode) node, clonedNode, Sync.class);
          createRel.execute(clonedNode, (DOMNode) node, Sync.class);
         
        } catch (Exception ex) {
View Full Code Here

TOP

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

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.