[zk工具类] zk工具类 ZkUtils 1.1版本

package org.sunflower.common.web.zk.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.WebApp;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Messagebox;

/**
 * ZkUtils集合了zk中常用的一些功能,方便开发中的使用
 *
 *
 * @author sunflower
 *
 *         时间:2010-7-9 上午09:40:26
 *
 *         Email:zhangxuehuaemail # gmail 点 com
 *
 */
public class ZkUtils {

 /**
  * 获取当前Execution
  *
  * @return
  */
 public static Execution exec() {
  return Executions.getCurrent();
 }

 /**
  * 获得当前桌面
  *
  * @return
  */
 public static Desktop desktop() {
  return exec().getDesktop();
 }

 /**
  * 返回当前桌面的webapp
  *
  * @return
  */
 public static WebApp webApp() {
  return desktop().getWebApp();
 }

 /**
  * 返回指定key的webapp作用域内的对象
  *
  * @param key
  * @return
  */
 public static Object webAppAttr(String key) {
  return webApp().getAttribute(key);
 }

 /**
  * 设置指定key的webapp作用域对象
  *
  * @param key
  * @param value
  */
 public static void setAppAttr(String key, Object value) {
  webApp().setAttribute(key, value);
 }

 /**
  * 获得给定路径的URL
  *
  * @param path
  * @return
  */
 public static URL getResource(String path) {
  return webApp().getResource(path);
 }

 /**
  * 获得跟定资源的二进制流
  *
  * <p>
  * Notice that, since 3.6.3, this method can retreive the resource starting
  * with "~./". If the path contains the wildcard ('*'), you can use
  * {@link Execution#locate} to convert it to a proper string first.
  */
 public static InputStream getResourceAsStream(String path) {
  return webApp().getResourceAsStream(path);
 }

 /**
  * 获得 path虚拟路径的实际路径 . 例如, the path "/index.html" returns the absolute file
  * path on the server's filesystem would be served by a request for
  * "http://host/contextPath/index.html", where contextPath is the context
  * path of this {@link WebApp}.
  *
  * <p>
  * Notice that ZK don't count on this method to retrieve resources. If you
  * want to change the mapping of URI to different resources, override
  * {@link org.zkoss.zk.ui.sys.UiFactory#getPageDefinition} instead.
  */
 public static  String getRealPath(String path) {
  return webApp().getRealPath(path);
 }

 /**
  * 返回指定文件的mime类型 Returns the MIME type of the specified file, or null if the
  * MIME type is not known. The MIME type is determined by the configuration
  * of the Web container.
  * <p>
  * Common MIME types are "text/html" and "image/gif".
  */
 public static  String getMimeType(String file) {
  return webApp().getMimeType(file);
 }

 /**
  * 获得当前请求的session
  *
  * @return
  */
 public static Session session() {
  return Sessions.getCurrent();
 }

 /**
  * 设置指定key的对象到session作用域
  *
  * @param name
  * @param value
  */
 public static void setSessionAttr(String key, Object value) {
  session().setAttribute(key, value);
 }

 /**
  * 获得从当前request的session中取出指定key的对象
  *
  * @param name
  * @return
  */
 public static Objec

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值