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