Examples of AsyncBuffer


Examples of org.structr.web.common.AsyncBuffer

    if (isDeleted() || isHidden() || !displayForLocale(renderContext) || !displayForConditions(securityContext, renderContext)) {
      return;
    }

    // final variables
    final AsyncBuffer out    = renderContext.getBuffer();
    final EditMode editMode  = renderContext.getEditMode(securityContext.getUser(false));
    final boolean isVoid     = isVoidElement();
    final String _tag        = getProperty(DOMElement.tag);

    // non-final variables
    Result localResult                 = renderContext.getResult();
    boolean anyChildNodeCreatesNewLine = false;

    renderStructrAppLib(out, securityContext, renderContext, depth);

    if (depth > 0 && !avoidWhitespace()) {

      out.append(indent(depth));

    }

    if (StringUtils.isNotBlank(_tag)) {

      openingTag(securityContext, out, _tag, editMode, renderContext, depth);

      try {

        // in body?
        if (lowercaseBodyName.equals(this.getTagName())) {
          renderContext.setInBody(true);
        }

        // fetch children
        List<DOMChildren> rels = getChildRelationships();
        if (rels.isEmpty()) {

          migrateSyncRels();

          // No child relationships, maybe this node is in sync with another node
          //Sync syncRel = getIncomingRelationship(Sync.class);
          DOMElement _syncedNode = (DOMElement) getProperty(sharedComponent);
          if (_syncedNode != null) {
            rels.addAll(_syncedNode.getChildRelationships());
          }
        }

        for (final AbstractRelationship rel : rels) {

          final DOMNode subNode = (DOMNode) rel.getTargetNode();

          if (subNode instanceof DOMElement) {
            anyChildNodeCreatesNewLine = (anyChildNodeCreatesNewLine || !(subNode.avoidWhitespace()));
          }

          subNode.render(securityContext, renderContext, depth + 1);

        }

      } catch (Throwable t) {

        logger.log(Level.SEVERE, "Error while rendering node {0}: {1}", new java.lang.Object[]{getUuid(), t});

        out.append("Error while rendering node ").append(getUuid()).append(": ").append(t.getMessage());

        t.printStackTrace();

      }

      // render end tag, if needed (= if not singleton tags)
      if (StringUtils.isNotBlank(_tag) && (!isVoid)) {

        // only insert a newline + indentation before the closing tag if any child-element used a newline
        if (anyChildNodeCreatesNewLine) {

          out.append(indent(depth));

        }

        out.append("</").append(_tag).append(">");
      }

    }

    // Set result for this level again, if there was any
View Full Code Here

Examples of org.structr.web.common.AsyncBuffer

    }

    String id            = getUuid();
    EditMode edit        = renderContext.getEditMode(securityContext.getUser(false));
    boolean inBody       = renderContext.inBody();
    AsyncBuffer out       = renderContext.getBuffer();

    String _contentType = getProperty(contentType);

    // fetch content with variable replacement
    String _content = getPropertyWithVariableReplacement(securityContext, renderContext, Content.content);

    if (!(EditMode.RAW.equals(edit) || EditMode.WIDGET.equals(edit)) && (_contentType == null || ("text/plain".equals(_contentType)))) {

      _content = escapeForHtml(_content);

    }

    if (EditMode.CONTENT.equals(edit) && inBody && securityContext.isAllowed(this, Permission.write)) {

      if ("text/javascript".equals(_contentType)) {

        // Javascript will only be given some local vars
        // TODO: Is this neccessary?
        out.append("// data-structr-type='").append(getType()).append("'\n// data-structr-id='").append(id).append("'\n");

      } else if ("text/css".equals(_contentType)) {

        // CSS will only be given some local vars
        // TODO: Is this neccessary?
        out.append("/* data-structr-type='").append(getType()).append("'*/\n/* data-structr-id='").append(id).append("'*/\n");

      } else {

//        // In edit mode, add an artificial 'span' tag around content nodes within body to make them editable
//        buffer.append("<span data-structr-raw-value=\"").append(getProperty(Content.content))
//          //.append("\" data-structr-content-type=\"").append(StringUtils.defaultString(getProperty(Content.contentType), ""))
//          .append("\" data-structr-type=\"").append(getType())
//          .append("\" data-structr-id=\"").append(id).append("\">");

//        int l = buffer.length();
//        buffer.replace(l-1, l, " data-structr-raw-value=\""
//          .concat(getProperty(Content.content))
//          .concat("\" data-structr-type=\"").concat(getType())
//          .concat("\" data-structr-id=\"").concat(id).concat("\">"));
        String cleanedContent = StringUtils.remove(StringUtils.remove(org.apache.commons.lang3.StringUtils.replace(getProperty(Content.content), "\n", "\\\\n"), "<!--"), "-->");
        out.append("<!--data-structr-id=\"".concat(id)
          .concat("\" data-structr-raw-value=\"").concat(escapeForHtmlAttributes(cleanedContent)).concat("\"-->"));
          //.concat("\" data-structr-raw-value=\"").concat(getProperty(Content.content)).concat("\"-->"));

      }

    }

    // No contentType-specific rendering in DATA edit mode
    //if (!edit.equals(EditMode.DATA)) {

      // examine content type and apply converter

      if (_contentType != null) {

        Adapter<String, String> converter = contentConverters.get(_contentType);

        if (converter != null) {

          try {

            // apply adapter
            _content = converter.adapt(_content);
          } catch (FrameworkException fex) {

            logger.log(Level.WARNING, "Unable to convert content: {0}", fex.getMessage());

          }

        }

      }

      // replace newlines with <br /> for rendering
      if (((_contentType == null) || _contentType.equals("text/plain")) && (_content != null) && !_content.isEmpty()) {

        final DOMNode _parent = getProperty(Content.parent);
        if (_parent == null || !(_parent instanceof Textarea)) {

          _content = _content.replaceAll("[\\n]{1}", "<br>");
        }
      }
    //}

    if (_content != null) {

      //buffer.append(indent(depth, true)).append(_content);

      // insert whitespace to make element clickable
      if (EditMode.CONTENT.equals(edit) && _content.length() == 0) {
        _content = "--- empty ---";
      }

      out.append(_content);
    }

    if (EditMode.CONTENT.equals(edit) && inBody && !("text/javascript".equals(getProperty(contentType))) && !("text/css".equals(getProperty(contentType)))) {

//      buffer.append("</span>");
      out.append("<!---->");
    }

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.