コード例 #1
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
 /** Returns the first line to be generated to the output, or null if no special first line. */
 public static final String outFirstLine(Execution exec, Page page) {
   if (exec.getAttribute(FIRST_LINE_GENED) == null && !exec.isAsyncUpdate(null)) {
     exec.setAttribute(FIRST_LINE_GENED, Boolean.TRUE);
     return trimAndLF(((PageCtrl) page).getFirstLine());
   }
   return "";
 }
コード例 #2
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
 /** Returns the doc type, or null if not available. It is null or <!DOCTYPE ...>. */
 public static final String outDocType(Execution exec, Page page) {
   if (exec.getAttribute(DOCTYPE_GENED) == null && !exec.isAsyncUpdate(null)) {
     exec.setAttribute(DOCTYPE_GENED, Boolean.TRUE);
     final String docType = ((PageCtrl) page).getDocType();
     return trimAndLF(docType != null ? docType : page.getDesktop().getDevice().getDocType());
   }
   return "";
 }
コード例 #3
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
  /**
   * Generates the unavailable message in HTML tags, if any.
   *
   * @param exec the execution (never null)
   */
  public static String outUnavailable(Execution exec) {
    if (exec.getAttribute(ATTR_UNAVAILABLE_GENED) == null && !exec.isAsyncUpdate(null)) {
      exec.setAttribute(ATTR_UNAVAILABLE_GENED, Boolean.TRUE);

      final Device device = exec.getDesktop().getDevice();
      String s = device.getUnavailableMessage();
      return s != null ? "<noscript>\n" + s + "\n</noscript>" : "";
    }
    return ""; // nothing to generate
  }
コード例 #4
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
  /**
   * Returns HTML tags to include all style sheets that are defined in all languages of the
   * specified device (never null).
   *
   * <p>In addition to style sheets defined in lang.xml and lang-addon.xml, it also include:
   *
   * <ol>
   *   <li>The style sheet specified in the theme-uri parameter.
   * </ol>
   *
   * <p>FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once.
   *
   * @param exec the execution (never null)
   * @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).
   */
  public static final String outLangStyleSheets(Execution exec, WebApp wapp, String deviceType) {
    if (exec.isAsyncUpdate(null) || exec.getAttribute(ATTR_LANG_CSS_GENED) != null)
      return ""; // nothing to generate
    exec.setAttribute(ATTR_LANG_CSS_GENED, Boolean.TRUE);

    final StringBuffer sb = new StringBuffer(512);
    for (StyleSheet ss : getStyleSheets(exec, wapp, deviceType)) append(sb, ss, exec, null);

    if (sb.length() > 0) sb.append('\n');
    return sb.toString();
  }
コード例 #5
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
  /**
   * 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");
    }
  }
コード例 #6
0
ファイル: HtmlPageRenders.java プロジェクト: KevinLong/zk
  /**
   * Returns HTML tags to include all JavaScript files and codes that are required when loading a
   * ZUML page (never null).
   *
   * <p>FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once.
   *
   * @param exec the execution (never null)
   * @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).
   */
  public static final String outLangJavaScripts(Execution exec, WebApp wapp, String deviceType) {
    if (exec.isAsyncUpdate(null) || exec.getAttribute(ATTR_LANG_JS_GENED) != null)
      return ""; // nothing to generate
    exec.setAttribute(ATTR_LANG_JS_GENED, Boolean.TRUE);

    final Desktop desktop = exec.getDesktop();
    if (wapp == null) wapp = desktop.getWebApp();
    if (deviceType == null) deviceType = desktop != null ? desktop.getDeviceType() : "ajax";

    final StringBuffer sb = new StringBuffer(1536);

    final Set<JavaScript> jses = new LinkedHashSet<JavaScript>(32);
    for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(deviceType))
      jses.addAll(langdef.getJavaScripts());
    for (JavaScript js : jses) append(sb, js);

    sb.append("\n<!-- ZK ").append(wapp.getVersion());
    if (WebApps.getFeature("ee")) sb.append(" EE");
    else if (WebApps.getFeature("pe")) sb.append(" PE");
    sb.append(' ').append(wapp.getBuild());
    Object o = wapp.getAttribute("org.zkoss.zk.ui.notice");
    if (o != null) sb.append(o);
    sb.append(" -->\n");

    int tmout = 0;
    final Boolean autoTimeout = getAutomaticTimeout(desktop);
    if (autoTimeout != null
        ? autoTimeout.booleanValue()
        : wapp.getConfiguration().isAutomaticTimeout(deviceType)) {
      if (desktop != null) {
        tmout = desktop.getSession().getMaxInactiveInterval();
      } else {
        Object req = exec.getNativeRequest();
        if (req instanceof HttpServletRequest) {
          final HttpSession hsess = ((HttpServletRequest) req).getSession(false);
          if (hsess != null) {
            final Session sess = SessionsCtrl.getSession(wapp, hsess);
            if (sess != null) {
              tmout = sess.getMaxInactiveInterval();
            } else {
              // try configuration first since HttpSession's timeout is set
              // when ZK Session is created (so it is not set yet)
              // Note: no need to setMaxInactiveInternval here since it will
              // be set later or not useful at the end
              tmout = wapp.getConfiguration().getSessionMaxInactiveInterval();
              if (tmout <= 0) // system default
              tmout = hsess.getMaxInactiveInterval();
            }
          } else tmout = wapp.getConfiguration().getSessionMaxInactiveInterval();
        }
      }
      if (tmout > 0) { // unit: seconds
        int extra = tmout / 8;
        tmout += extra > 60 ? 60 : extra < 5 ? 5 : extra;
        // Add extra seconds to ensure it is really timeout
      }
    }

    final boolean
        keepDesktop =
            exec.getAttribute(Attributes.NO_CACHE) == null
                && !"page".equals(ExecutionsCtrl.getPageRedrawControl(exec)),
        groupingAllowed = isGroupingAllowed(desktop);
    final String progressboxPos =
        org.zkoss.lang.Library.getProperty("org.zkoss.zul.progressbox.position", "");
    if (tmout > 0 || keepDesktop || progressboxPos.length() > 0 || !groupingAllowed) {
      sb.append("<script class=\"z-runonce\" type=\"text/javascript\">\nzkopt({");

      if (keepDesktop) sb.append("kd:1,");
      if (!groupingAllowed) sb.append("gd:1,");
      if (tmout > 0) sb.append("to:").append(tmout).append(',');
      if (progressboxPos.length() > 0) sb.append("ppos:'").append(progressboxPos).append('\'');

      if (sb.charAt(sb.length() - 1) == ',') sb.setLength(sb.length() - 1);
      sb.append("});\n</script>");
    }

    final Device device = Devices.getDevice(deviceType);
    String s = device.getEmbedded();
    if (s != null) sb.append(s).append('\n');
    return sb.toString();
  }