Package org.structr.web.entity.dom

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


    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    String sourceId                       = webSocketData.getId();
    Map<String, Object> properties        = webSocketData.getNodeData();
    String targetId                       = (String) properties.get("targetId");
    final String syncMode                 = (String) properties.get("syncMode");
    final DOMNode sourceNode              = (DOMNode) getNode(sourceId);
    final DOMNode targetNode              = (DOMNode) getNode(targetId);
    final App app                         = StructrApp.getInstance(securityContext);

    if ((sourceNode != null) && (targetNode != null)) {

      try {
View Full Code Here


    }

    if (parentNode instanceof DOMNode) {

      DOMNode parentDOMNode = getDOMNode(parentId);
      if (parentDOMNode == null) {

        getWebSocket().send(MessageBuilder.status().code(422).message("Parent node is no DOM node").build(), true);

        return;
View Full Code Here

        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot add node without parentId").build(), true);   
        return;
      }

      // check if parent node with given ID exists
      DOMNode parentNode = getDOMNode(parentId);
      if (parentNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);   
        return;
      }

      // check for ref ID before creating any nodes
      if (refId == null) {
   
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot add node without refId").build(), true);   
        return;
      }

      // check if ref node with given ID exists
      DOMNode refNode = getDOMNode(refId);
      if (refNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("Reference node not found").build(), true);   
        return;
      }
     
      Document document = getPage(pageId);
      if (document != null) {

        String tagName  = (String) nodeData.get("tagName");
        DOMNode newNode = null;
       
        try {

          if (tagName != null && !tagName.isEmpty()) {
View Full Code Here

    // iterate over existing nodes and try to find deleted ones
    for (final Iterator<Map.Entry<String, DOMNode>> it = hashMappedExistingNodes.entrySet().iterator(); it.hasNext();) {

      final Map.Entry<String, DOMNode> existingNodeEntry = it.next();
      final DOMNode existingNode                     = existingNodeEntry.getValue();
      final String existingHash                      = existingNode.getIdHash();

      // check for deleted nodes ignoring Page nodes
      if (!hashMappedNewNodes.containsKey(existingHash) && !(existingNode instanceof Page)) {

        changeSet.add(new DeleteOperation(hashMappedExistingNodes, existingNode));
      }
    }

    // iterate over new nodes and try to find new ones
    for (final Iterator<Map.Entry<String, DOMNode>> it = indexMappedNewNodes.entrySet().iterator(); it.hasNext();) {

      final Map.Entry<String, DOMNode> newNodeEntry = it.next();
      final DOMNode newNode                     = newNodeEntry.getValue();

      // if newNode is a content element, do not rely on local hash property
      String newHash = newNode.getProperty(DOMNode.dataHashProperty);
      if (newHash == null) {
        newHash = newNode.getIdHash();
      }

      // check for deleted nodes ignoring Page nodes
      if (!hashMappedExistingNodes.containsKey(newHash) && !(newNode instanceof Page)) {

        final DOMNode newParent  = newNode.getProperty(DOMNode.parent);

        changeSet.add(new CreateOperation(hashMappedExistingNodes, getHashOrNull(newParent), getSiblingHashes(newNode), newNode, depthMappedNewNodes.get(newNode)));
      }
    }

    // compare all new nodes with all existing nodes
    for (final Map.Entry<String, DOMNode> newNodeEntry : indexMappedNewNodes.entrySet()) {

      final String newTreeIndex = newNodeEntry.getKey();
      final DOMNode newNode     = newNodeEntry.getValue();

      for (final Map.Entry<String, DOMNode> existingNodeEntry : indexMappedExistingNodes.entrySet()) {

        final String existingTreeIndex = existingNodeEntry.getKey();
        final DOMNode existingNode     = existingNodeEntry.getValue();
        DOMNode newParent              = null;
        int equalityBitmask            = 0;

        if (newTreeIndex.equals(existingTreeIndex)) {
          equalityBitmask |= 1;
        }
View Full Code Here

  }

  private static List<String> getSiblingHashes(final DOMNode node) {

    final List<String> siblingHashes = new LinkedList<>();
    DOMNode nextSibling = node.getProperty(DOMNode.nextSibling);

    while (nextSibling != null) {

      siblingHashes.add(nextSibling.getIdHashOrProperty());
      nextSibling = nextSibling.getProperty(DOMNode.nextSibling);
    }

    return siblingHashes;
  }
View Full Code Here

  public void apply(final App app, final Page sourcePage, final Page newPage) throws FrameworkException {

    final InsertPosition insertPosition = findInsertPosition(sourcePage, parentHash, siblingHashes, newNode);
    if (insertPosition != null) {

      final DOMNode parent       = insertPosition.getParent();
      final DOMNode sibling      = insertPosition.getSibling();
      final Node originalSibling = originalNode.getNextSibling();
      final Node originalParent = originalNode.getParentNode();

      // do not modify synced nodes (nodes that are shared between multiple pages)
      if (parent.isSynced()) {
        return;
      }

      if (parent.equals(originalParent)) {

        if (sibling != null && sibling.equals(originalSibling)) {

          // nothing to be done
          return;
        }
View Full Code Here

  public void apply(final App app, final Page sourcePage, final Page newPage) throws FrameworkException {

    final InsertPosition insertPosition = findInsertPosition(sourcePage, parentHash, siblingHashes, newNode);
    if (insertPosition != null) {

      final DOMNode parent  = insertPosition.getParent();
      final DOMNode sibling = insertPosition.getSibling();

      if (parent != null && !parent.isSynced()) {

        sourcePage.adoptNode(newNode);
        parent.insertBefore(newNode, sibling);
View Full Code Here

    this.hashMappedExistingNodes = hashMappedExistingNodes;
  }

  protected InsertPosition findInsertPosition(final Page sourcePage, final String parentHash, final List<String> siblingHashes, final DOMNode newNode) {

    DOMNode newParent  = hashMappedExistingNodes.get(parentHash);
    DOMNode newSibling = null;

    // we need to check the whole list of siblings here because
    // when inserting the first element of a list of elements,
    // the "next sibling" element is not there yet, so we have
    // to use the one after
View Full Code Here

    final Page page      = getPage(pageId);
    final AbstractNode origNode  = getNode(id);
   
    try {
     
      DOMNode existingParent = null;
      if (parentId != null) {
        // Remove original node from existing parent to ensure correct position
        existingParent = (DOMNode) getNode(parentId);
      }

      // Create temporary parent node
      DOMNode parent = app.create(Div.class);

      // Expand source code to widget
      Widget.expandWidget(getWebSocket().getSecurityContext(), page, parent, baseUrl, nodeData);

      DOMNode newWidget = (DOMNode) parent.getChildNodes().item(0);
      moveSyncRels((DOMElement) origNode, (DOMElement) newWidget);

      if (existingParent != null) {
        existingParent.removeChild((DOMNode) origNode);

      }

      deleteRecursively((DOMNode) origNode);

      // Set uuid of original node to new widget node
      newWidget.setProperty(GraphObject.id, id);

      if (existingParent != null) {

        // Append new widget to existing parent
        existingParent.appendChild(newWidget);
View Full Code Here

        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot replace node without parentId").build(), true);   
        return;
      }

      // check if parent node with given ID exists
      DOMNode parentNode = getDOMNode(parentId);
      if (parentNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);   
        return;
      }

      // check for old ID before creating any nodes
      if (refId == null) {
   
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot insert node without refId").build(), true);
        return;
      }

      // check if old node with given ID exists
      DOMNode refNode = getDOMNode(refId);
      if (refNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("Reference node not found").build(), true);   
        return;
      }

      // check for new ID before creating any nodes
      if (newId == null) {
   
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot replace node without newId").build(), true);
        return;
      }

      // check if new node with given ID exists
      DOMNode newNode = getDOMNode(newId);
      if (newNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("New node not found").build(), true);   
        return;
      }
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.