public void getSecondHalf(StringBuffer sb, String tag) {
      if (tag != null) {
        final String tn = tag.toLowerCase();
        if ("zkhead".equals(tn) || HTMLs.isOrphanTag(tn)) return;

        sb.append("</").append(tag).append('>');
      }
    }
Example #2
0
  /**
   * Converts the header definitions (added by {@link #setRootAttribute}) to the attributes of the
   * root element. For HTML, the root element is the HTML element.
   *
   * @since 3.0.0
   */
  public String getRootAttributes(Page page) {
    if (_rootAttrs == null || _rootAttrs.isEmpty()) return "";

    final Evaluator eval = getEvaluator();
    final StringBuffer sb = new StringBuffer(256);
    for (Map.Entry<String, ExValue> me : _rootAttrs.entrySet()) {
      final String val = (String) me.getValue().getValue(eval, page);
      if (val != null) HTMLs.appendAttribute(sb, me.getKey(), val);
    }
    return sb.toString();
  }
    public void getFirstHalf(
        StringBuffer sb, String tag, Map<String, Object> props, Collection<Namespace> namespaces) {
      if (tag != null) sb.append('<').append(tag);

      NativeHelpers.getAttributes(sb, props, namespaces);

      if (tag != null) {
        final String tn = tag.toLowerCase();
        if ("zkhead".equals(tn) || HTMLs.isOrphanTag(tn)) sb.append('/');
        sb.append('>');
      }
    }
Example #4
0
  /**
   * Returns the HTML content representing a page.
   *
   * @param au whether it is caused by asynchronous update
   * @param exec the execution (never null)
   */
  public static final void outPageContent(Execution exec, Page page, Writer out, boolean au)
      throws IOException {
    final Desktop desktop = page.getDesktop();
    final PageCtrl pageCtrl = (PageCtrl) page;
    final Component owner = pageCtrl.getOwner();
    boolean contained = owner == null && exec.isIncluded();
    // a standalone page (i.e., no owner), and being included by
    // non-ZK page (e.g., JSP).
    //
    // Revisit Bug 2001707: OK to use exec.isIncluded() since
    // we use PageRenderer now (rather than Servlet's include)
    // TODO: test again

    // prepare style
    String style = page.getStyle();
    if (style == null || style.length() == 0) {
      style = null;
      String wd = null, hgh = null;
      if (owner instanceof HtmlBasedComponent) {
        final HtmlBasedComponent hbc = (HtmlBasedComponent) owner;
        wd = hbc.getWidth(); // null if not set
        hgh = hbc.getHeight(); // null if not set
      }

      if (wd != null || hgh != null || contained) {
        final StringBuffer sb = new StringBuffer(32);
        HTMLs.appendStyle(sb, "width", wd != null ? wd : "100%");
        HTMLs.appendStyle(sb, "height", hgh != null ? hgh : contained ? null : "100%");
        style = sb.toString();
      }
    }

    RenderContext rc = null, old = null;
    final boolean aupg = exec.isAsyncUpdate(page); // AU this page
    final boolean includedAndPart = owner != null && !aupg;
    // this page is included and rendered with its owner
    final boolean divRequired = !au || includedAndPart;
    final boolean standalone = !au && owner == null;
    if (standalone) {
      rc =
          new RenderContext(
              out, new StringWriter(), desktop.getWebApp().getConfiguration().isCrawlable(), false);
      setRenderContext(exec, rc);
    } else if (owner != null) {
      old = getRenderContext(exec); // store
      final boolean crawlable =
          old != null && old.temp != null && desktop.getWebApp().getConfiguration().isCrawlable();
      setRenderContext(exec, crawlable ? new RenderContext(old.temp, null, true, true) : null);
    }

    // generate div first
    if (divRequired) {
      outDivTemplateBegin(out, page.getUuid());
    }
    if (standalone) { // switch out
      // don't call outDivTemplateEnd yet since rc.temp will be generated before it
      out = new StringWriter();
    } else if (divRequired) {
      outDivTemplateEnd(page, out); // close it now since no rc.temp
    }

    if (includedAndPart) {
      out = new StringWriter();
    } else if (divRequired) {
      // generate JS second
      out.write("\n<script class=\"z-runonce\" type=\"text/javascript\">\n");
    }

    exec.setAttribute(ATTR_DESKTOP_JS_GENED, Boolean.TRUE);
    final int order = ComponentRedraws.beforeRedraw(false);
    final String extra;
    try {
      if (order < 0) {
        if (aupg) out.write('[');
        else {
          out.write(outSpecialJS(desktop));
          out.write(divRequired ? "zkmx(" : "zkx(");
        }
      } else if (order > 0) // not first child
      out.write(',');
      out.write("\n[0,'"); // 0: page
      out.write(page.getUuid());
      out.write("',{");

      final StringBuffer props = new StringBuffer(128);
      final String pgid = page.getId();
      if (pgid.length() > 0) appendProp(props, "id", pgid);
      if (owner != null) {
        appendProp(props, "ow", owner.getUuid());
      } else {
        appendProp(props, "dt", desktop.getId());
        appendProp(props, "cu", getContextURI(exec));
        appendProp(props, "uu", desktop.getUpdateURI(null));
        appendProp(props, "ru", desktop.getRequestPath());
      }
      final String pageWgtCls = pageCtrl.getWidgetClass();
      if (pageWgtCls != null) appendProp(props, "wc", pageWgtCls);
      if (style != null) appendProp(props, "style", style);
      if (!isClientROD(page)) appendProp(props, "z$rod", Boolean.FALSE);
      if (contained) appendProp(props, "ct", Boolean.TRUE);
      out.write(props.toString());
      out.write("},[");

      for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling())
        ((ComponentCtrl) root).redraw(out);

      out.write("]]");
    } finally {
      extra = ComponentRedraws.afterRedraw();
    }

    if (order < 0) {
      outEndJavaScriptFunc(exec, out, extra, aupg);
    }

    if (standalone) {
      setRenderContext(exec, null);

      StringBuffer sw = ((StringWriter) out).getBuffer();
      out = rc.temp;
      if (divRequired) outDivTemplateEnd(page, out);
      // close tag after temp, but before perm (so perm won't be destroyed)
      Files.write(out, ((StringWriter) rc.perm).getBuffer()); // perm

      // B65-ZK-1836
      Files.write(
          out, new StringBuffer(sw.toString().replaceAll("</(?i)(?=script>)", "<\\\\/"))); // js
    } else if (owner != null) { // restore
      setRenderContext(exec, old);
    }

    if (includedAndPart) {
      ((Includer) owner).setRenderingResult(((StringWriter) out).toString());
    } else if (divRequired) {
      out.write("\n</script>\n");
    }
  }