Package org.structr.web.entity.dom

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


        renderContext.setResourceProvider(config.getResourceProvider());

        final EditMode edit = renderContext.getEditMode(user);

        DOMNode rootElement = null;
        AbstractNode dataNode = null;

        String[] uriParts = PathHelper.getParts(path);
        if ((uriParts == null) || (uriParts.length == 0)) {

          // find a visible page
          rootElement = findIndexPage(securityContext);

          logger.log(Level.FINE, "No path supplied, trying to find index page");

        } else {

          if (rootElement == null) {

            rootElement = findPage(securityContext, request, path);

          } else {
            dontCache = true;
          }
        }

        if (rootElement == null) { // No page found

          // Look for a file
          File file = findFile(securityContext, request, path);
          if (file != null) {

            streamFile(securityContext, file, request, response, edit);
            return;

          }

          // store remaining path parts in request
          Matcher matcher = threadLocalUUIDMatcher.get();
          boolean requestUriContainsUuids = false;

          for (int i = 0; i < uriParts.length; i++) {

            request.setAttribute(uriParts[i], i);
            matcher.reset(uriParts[i]);

            // set to "true" if part matches UUID pattern
            requestUriContainsUuids |= matcher.matches();

          }

          if (!requestUriContainsUuids) {

            // Try to find a data node by name
            dataNode = findFirstNodeByName(securityContext, request, path);

          } else {

            dataNode = findNodeByUuid(securityContext, PathHelper.getName(path));

          }

          if (dataNode != null && !(dataNode instanceof Linkable)) {

            // Last path part matches a data node
            // Remove last path part and try again searching for a page
            // clear possible entry points
            request.removeAttribute(POSSIBLE_ENTRY_POINTS);

            rootElement = findPage(securityContext, request, StringUtils.substringBeforeLast(path, PathHelper.PATH_SEP));

            renderContext.setDetailsDataObject(dataNode);

            // Start rendering on data node
            if (rootElement == null && dataNode instanceof DOMNode) {

              rootElement = ((DOMNode) dataNode);

            }

          }

        }

        // Still nothing found, do error handling
        if (rootElement == null) {

          // Check if security context has set an 401 status
          if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {

            try {

              UiAuthenticator.writeUnauthorized(response);

            } catch (IllegalStateException ise) {
            }

          } else {

            rootElement = notFound(response, securityContext);

          }

        }

        if (rootElement == null) {
          return;
        }

        if (EditMode.WIDGET.equals(edit) || dontCache) {

          setNoCacheHeaders(response);

        }

        if (!securityContext.isVisible(rootElement)) {

          rootElement = notFound(response, securityContext);
          if (rootElement == null) {
            return;
          }

        }

        if (securityContext.isVisible(rootElement)) {

          if (!EditMode.WIDGET.equals(edit) && !dontCache && notModifiedSince(request, response, rootElement, dontCache)) {

            ServletOutputStream out = response.getOutputStream();
            out.flush();
            //response.flushBuffer();
            out.close();

          } else {

            // prepare response
            response.setCharacterEncoding("UTF-8");

            String contentType = rootElement.getProperty(Page.contentType);

            if (contentType == null) {
             
              // Default
              contentType = "text/html;charset=UTF-8";
            }
           
            if (contentType.equals("text/html")) {
              contentType = contentType.concat(";charset=UTF-8");
            }

            response.setContentType(contentType);

            response.setHeader("Strict-Transport-Security", "max-age=60");
            response.setHeader("X-Content-Type-Options", "nosniff");
            response.setHeader("X-Frame-Options", "SAMEORIGIN");
            response.setHeader("X-XSS-Protection", "1; mode=block");

            // async or not?
            boolean isAsync = HttpService.parseBoolean(Services.getBaseConfiguration().getProperty(HttpService.ASYNC), true);
            if (isAsync) {

              final AsyncContext async      = request.startAsync();
              final ServletOutputStream out = async.getResponse().getOutputStream();
              final AtomicBoolean finished  = new AtomicBoolean(false);
              final DOMNode rootNode        = rootElement;

              threadPool.submit(new Runnable() {

                @Override
                public void run() {

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

                    //final long start = System.currentTimeMillis();

                    // render
                    rootNode.render(securityContext, renderContext, 0);
                    finished.set(true);

                    //final long end = System.currentTimeMillis();
                    //System.out.println("Done in " + (end-start) + " ms");
View Full Code Here


        renderContext.setResourceProvider(config.getResourceProvider());

        final EditMode edit = renderContext.getEditMode(user);

        DOMNode rootElement = null;
        AbstractNode dataNode = null;

        String[] uriParts = PathHelper.getParts(path);
        if ((uriParts == null) || (uriParts.length == 0)) {

          // find a visible page
          rootElement = findIndexPage(securityContext);

          logger.log(Level.FINE, "No path supplied, trying to find index page");

        } else {

          if (rootElement == null) {

            rootElement = findPage(securityContext, request, path);

          } else {
            dontCache = true;
          }
        }

        if (rootElement == null) { // No page found

          // Look for a file
          File file = findFile(securityContext, request, path);
          if (file != null) {

            //streamFile(securityContext, file, request, response, edit);
            return;

          }

          // store remaining path parts in request
          Matcher matcher = threadLocalUUIDMatcher.get();
          boolean requestUriContainsUuids = false;

          for (int i = 0; i < uriParts.length; i++) {

            request.setAttribute(uriParts[i], i);
            matcher.reset(uriParts[i]);

            // set to "true" if part matches UUID pattern
            requestUriContainsUuids |= matcher.matches();

          }

          if (!requestUriContainsUuids) {

            // Try to find a data node by name
            dataNode = findFirstNodeByName(securityContext, request, path);

          } else {

            dataNode = findNodeByUuid(securityContext, PathHelper.getName(path));

          }

          if (dataNode != null && !(dataNode instanceof Linkable)) {

            // Last path part matches a data node
            // Remove last path part and try again searching for a page
            // clear possible entry points
            request.removeAttribute(POSSIBLE_ENTRY_POINTS);

            rootElement = findPage(securityContext, request, StringUtils.substringBeforeLast(path, PathHelper.PATH_SEP));

            renderContext.setDetailsDataObject(dataNode);

            // Start rendering on data node
            if (rootElement == null && dataNode instanceof DOMNode) {

              rootElement = ((DOMNode) dataNode);

            }

          }

        }

        // Still nothing found, do error handling
        if (rootElement == null) {

          // Check if security context has set an 401 status
          if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {

            try {

              UiAuthenticator.writeUnauthorized(response);

            } catch (IllegalStateException ise) {
            }

          } else {

            rootElement = notFound(response, securityContext);

          }

        }

        if (rootElement == null) {

          // no content
          response.setContentLength(0);
          response.getOutputStream().close();

          return;
        }

        if (EditMode.WIDGET.equals(edit) || dontCache) {

          setNoCacheHeaders(response);

        }

        if (!securityContext.isVisible(rootElement)) {

          rootElement = notFound(response, securityContext);
          if (rootElement == null) {
            return;
          }

        }

        if (securityContext.isVisible(rootElement)) {

          if (!EditMode.WIDGET.equals(edit) && !dontCache && notModifiedSince(request, response, rootElement, dontCache)) {

            response.getOutputStream().close();

          } else {

            // prepare response
            response.setCharacterEncoding("UTF-8");

            String contentType = rootElement.getProperty(Page.contentType);

            if (contentType == null) {
             
              // Default
              contentType = "text/html;charset=UTF-8";
View Full Code Here

      }
    }

    for (final DOMChildren children : root.getChildRelationships()) {

      final DOMNode child = children.getTargetNode();
      collectActiveElements(resultList, child, dataKeys, parentId, dataCentricDepth);
    }

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

      }

      DOMNode node = (DOMNode) getDOMNode(id);

      // append node to parent
      if (node != null) {

        parentDOMNode.appendChild(node);
View Full Code Here

      return;

    }

    // check if parent node with given ID exists
    DOMNode node = getDOMNode(id);

    if (node == null) {

      getWebSocket().send(MessageBuilder.status().code(404).message("Node not found").build(), true);
View Full Code Here

  }

  @Override
  public void processMessage(WebSocketMessage webSocketData) {

    DOMNode node = getDOMNode(webSocketData.getId());

    if (node == null) {

      return;
    }

    List<GraphObject> result = new LinkedList<>();
    DOMNode currentNode      = (DOMNode) node.getFirstChild();

    while (currentNode != null) {

      result.add(currentNode);

      currentNode = (DOMNode) currentNode.getNextSibling();

    }

    webSocketData.setView(PropertyView.Ui);
    webSocketData.setResult(result);
View Full Code Here

      return;

    }

    DOMNode refNode = getDOMNode(refId );

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

    }

    DOMNode node = getDOMNode(id);

    try {

      // append node to parent
      if (node != null) {
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
      final DOMNode parentNode = getDOMNode(parentId);
      if (parentNode == null) {
   
        getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);   
        return;
      }
     
      final Document document = getPage(pageId);
      if (document != null) {

        final String tagName = (String) nodeData.get("tagName");
       
        nodeData.remove("tagName");
       
        try {

          DOMNode newNode;

          if (tagName != null && "comment".equals(tagName)) {
           
            newNode = (DOMNode) document.createComment("#comment");
           
          } else if (tagName != null && "template".equals(tagName)) {
           
            newNode = (DOMNode) document.createTextNode("#template");
 
            try {
           
              newNode.setProperty(NodeInterface.type, Template.class.getSimpleName());
           
            } catch (FrameworkException fex) {

              logger.log(Level.WARNING, "Unable to set type of node {1} to Template: {3}", new Object[] { newNode.getUuid(), fex.getMessage() } );

            }
           
          } else if (tagName != null && !tagName.isEmpty()) {

            newNode = (DOMNode) document.createElement(tagName);

          } else {

            newNode = (DOMNode) document.createTextNode("#text");
          }

          // Instantiate node again to get correct class
          newNode = getDOMNode(newNode.getUuid());
         
          // append new node to parent
          if (newNode != null) {

            parentNode.appendChild(newNode);

            for (Entry entry : nodeData.entrySet()) {

              String key = (String) entry.getKey();
              Object val = entry.getValue();

              PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForDatabaseName(newNode.getClass(), key);
              if (propertyKey != null) {

                try {
                  Object convertedValue = val;

                  PropertyConverter inputConverter = propertyKey.inputConverter(SecurityContext.getSuperUserInstance());
                  if (inputConverter != null) {

                    convertedValue = inputConverter.convert(val);
                  }

                  //newNode.unlockReadOnlyPropertiesOnce();
                  newNode.setProperty(propertyKey, convertedValue);

                } catch (FrameworkException fex) {

                  logger.log(Level.WARNING, "Unable to set node property {0} of node {1} to {2}: {3}", new Object[] { propertyKey, newNode.getUuid(), val, fex.getMessage() } );

                }
              }

            }

            // create a child text node if content is given
            if (StringUtils.isNotBlank(childContent)) {

              DOMNode childNode = (DOMNode)document.createTextNode(childContent);

              newNode.appendChild(childNode);

            }
View Full Code Here

      // determine which of the nodes have incoming CONTAINS relationships and are not components
      for (GraphObject obj : resultList) {

        if (obj instanceof DOMNode) {

          DOMNode node = (DOMNode) obj;

          if (node.getProperty(DOMNode.ownerDocument) == null) {
            filteredResults.add(node);
          }

          for (final DOMNode child : DOMNode.getAllChildNodes(node)) {
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

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.