Example #1
0
  /**
   * Retuns the implicit object of the specified name, or null if not found.
   *
   * <p>Notice that it does check for the current scope ({@link
   * org.zkoss.zk.ui.ext.Scopes#getCurrent}). Rather, {@link org.zkoss.zk.ui.ext.Scopes#getImplicit}
   * depends on this method.
   *
   * @param page the page. If page is null and comp is not, comp.getPage() is assumed
   * @see org.zkoss.zk.ui.ext.Scopes#getImplicit
   * @since 5.0.0
   */
  public static Object getImplicit(Page page, Component comp, String name) {
    if (comp != null && page == null) page = getCurrentPage(comp);

    if ("log".equals(name)) return _zklog;
    if ("self".equals(name)) return comp != null ? comp : (Object) page;
    if ("spaceOwner".equals(name)) return comp != null ? comp.getSpaceOwner() : (Object) page;
    if ("page".equals(name)) return page;
    if ("desktop".equals(name)) return comp != null ? getDesktop(comp) : page.getDesktop();
    if ("session".equals(name))
      return comp != null ? getSession(comp) : page.getDesktop().getSession();
    if ("application".equals(name))
      return comp != null ? getWebApp(comp) : page.getDesktop().getWebApp();
    if ("componentScope".equals(name))
      return comp != null ? comp.getAttributes() : Collections.EMPTY_MAP;
    if ("spaceScope".equals(name)) {
      final Scope scope = comp != null ? (Scope) comp.getSpaceOwner() : (Scope) page;
      return scope != null ? scope.getAttributes() : Collections.EMPTY_MAP;
    }
    if ("pageScope".equals(name))
      return page != null ? page.getAttributes() : Collections.EMPTY_MAP;
    if ("desktopScope".equals(name)) {
      final Desktop dt = comp != null ? getDesktop(comp) : page.getDesktop();
      return dt != null ? dt.getAttributes() : Collections.EMPTY_MAP;
    }
    if ("sessionScope".equals(name)) {
      final Session sess = comp != null ? getSession(comp) : page.getDesktop().getSession();
      return sess != null ? sess.getAttributes() : Collections.EMPTY_MAP;
    }
    if ("applicationScope".equals(name)) {
      final WebApp app = comp != null ? getWebApp(comp) : page.getDesktop().getWebApp();
      return app != null ? app.getAttributes() : Collections.EMPTY_MAP;
    }
    if ("requestScope".equals(name)) return REQUEST_SCOPE_PROXY;
    if ("execution".equals(name)) return EXECUTION_PROXY;
    if ("arg".equals(name)) {
      final Execution exec = Executions.getCurrent();
      return exec != null ? exec.getArg() : null;
      // bug 2937096: composer.arg shall be statically wired
      // arg is a Map prepared by application developer, so can be wired statically
    }
    if ("param".equals(name)) {
      final Execution exec = Executions.getCurrent();
      return exec != null ? exec.getParameterMap() : null;
      // bug 2945974: composer.param shall be statically wired
      // Note that request parameter is prepared by servlet container, you shall not
      // copy the reference to this map; rather, you shall clone the key-value pair one-by-one.
    }
    // 20090314, Henri Chen: No way to suppport "event" with an event proxy because
    // org.zkoss.zk.Event is not an interface
    return null;
  }
Example #2
0
  /**
   * Returns the page of the give component, or the current page if the component is null or it
   * doesn't belong to any page. The current page is retrieved by {@link
   * ExecutionCtrl#getCurrentPage} or the current execution. This method returns null if no
   * execution or no current page at all.
   *
   * @param comp the component to retrieve the page. Ignored if null.
   * @since 6.0.0
   */
  public static Page getCurrentPage(Component comp) {
    if (comp != null) {
      Page page = comp.getPage();
      if (page != null) return page;
    }

    final Execution exec = Executions.getCurrent();
    return exec != null ? ((ExecutionCtrl) exec).getCurrentPage() : null;
  }
Example #3
0
 private static final Execution exec() {
   return Executions.getCurrent();
 }
Example #4
0
 private static Desktop getDesktop(Component comp) {
   final Desktop dt = comp.getDesktop();
   if (dt != null) return dt;
   final Execution exec = Executions.getCurrent();
   return exec != null ? exec.getDesktop() : null;
 }
Example #5
0
 protected Map<String, Object> req() {
   return Executions.getCurrent().getAttributes();
 }