Пример #1
0
  /**
   * Generates and returns the ZK specific HTML tags such as stylesheet and JavaScript.
   *
   * <p>For each desktop, we have to generate a set of HTML tags to load ZK Client engine, style
   * sheets and so on. For ZUL pages, it is generated automatically by page.dsp. However, for ZHTML
   * pages, we have to generate these tags with special component such as org.zkoss.zhtml.Head, such
   * that the result HTML page is legal.
   *
   * @param exec the execution (never null)
   * @return the string holding the HTML tags, or null if already generated.
   * @param wapp the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to
   *     specify it if the execution is not associated with desktop (a fake execution, such as
   *     JSP/DSP).
   * @param deviceType the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is
   *     used. So you have to specify it if the execution is not associated with desktop (a fake
   *     execution).
   * @see #outHeaderZkTags
   */
  public static String outZkTags(Execution exec, WebApp wapp, String deviceType) {
    if (exec.getAttribute(ATTR_ZK_TAGS_GENERATED) != null) return null;
    exec.setAttribute(ATTR_ZK_TAGS_GENERATED, Boolean.TRUE);

    final StringBuffer sb =
        new StringBuffer(512)
            .append('\n')
            .append(outLangStyleSheets(exec, wapp, deviceType))
            .append(outLangJavaScripts(exec, wapp, deviceType));

    final Desktop desktop = exec.getDesktop();
    if (desktop != null && exec.getAttribute(ATTR_DESKTOP_JS_GENED) == null) {
      sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkdt('")
          .append(desktop.getId())
          .append("','")
          .append(getContextURI(exec))
          .append("','")
          .append(desktop.getUpdateURI(null))
          .append("','")
          .append(desktop.getRequestPath())
          .append("');")
          .append(outSpecialJS(desktop))
          .append("\n</script>\n");
    }

    return sb.toString();
  }
Пример #2
0
    // @Override
    public void render(Page page, Writer out) throws IOException {
      final Desktop desktop = _exec.getDesktop();

      out.write("<script type=\"text/javascript\">zkpb('");
      out.write(page.getUuid());
      out.write("','");
      out.write(desktop.getId());
      out.write("','");
      out.write(getContextURI());
      out.write("','");
      out.write(desktop.getUpdateURI(null));
      out.write("','");
      out.write(desktop.getRequestPath());
      out.write('\'');

      String style = page.getStyle();
      if (style != null && style.length() > 0) {
        out.write(",{style:'");
        out.write(style);
        out.write("'}");
      }

      out.write(");zkpe();</script>\n");

      for (Component root = page.getFirstRoot(); root != null; root = root.getNextSibling()) {
        // HtmlPageRenders.outStandalone(_exec, root, out);
      }
    }
Пример #3
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");
    }
  }