Esempio n. 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;
  }