org.zkoss.zul.Filedownload.java 源码
/* Filedownload.java Purpose: Description: History:
Mon Apr 16 09:29:44 2007, Created by tomyeh Copyright (C) 2007 Potix Corporation. All Rights Reserved. {{IS_RIGHT
This program is distributed under LGPL Version 2.1 in the hope that
it will be useful, but WITHOUT ANY WARRANTY.
}}IS_RIGHT
*/
package org.zkoss.zul; import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Reader;
import java.net.URL; import org.zkoss.util.media.AMedia;
import org.zkoss.util.media.Media;
import org.zkoss.zk.au.DeferredValue;
import org.zkoss.zk.au.out.AuDownload;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.sys.WebAppCtrl; /**
* File download utilities.
*
* @author tomyeh
* @see Fileupload
*/
public class Filedownload {
/** Open a download dialog to save the specified content at the client.
*/
public static void save(Media media) {
save(media, null);
} /** Open a download dialog to save the specified content at the client
* with the suggested file name.
*
* @param media the media to download
* @param flnm the suggested file name, e.g., myfile.pdf.
* If null, {@link Media#getName} is assumed.
*/
public static void save(Media media, String flnm) {
final Desktop desktop = Executions.getCurrent().getDesktop();
((WebAppCtrl) desktop.getWebApp()).getUiEngine().addResponse(new AuDownload(new DownloadURL(media, flnm))); //Bug 2114380
} /** Open a download dialog to save the specified content at the client
* with the suggested file name.
*
* @param content the content
* @param contentType the content type (a.k.a., MIME type),
* e.g., application/pdf
* @param flnm the suggested file name, e.g., myfile.pdf.
* If null, no suggested name is provided.
*/
public static void save(byte[] content, String contentType, String flnm) {
save(new AMedia(flnm, null, contentType, content), flnm);
} /** Open a download dialog to save the specified content at the client
* with the suggested file name.
*
* @param content the content
* @param contentType the content type (a.k.a., MIME type),
* e.g., application/pdf
* @param flnm the suggested file name, e.g., myfile.pdf.
* If null, no suggested name is provided.
*/
public static void save(String content, String contentType, String flnm) {
save(new AMedia(flnm, null, contentType, content), flnm);
} /** Open a download dialog to save the specified content at the client
* with the suggested file name.<br/>
* Note: You don't need to close the content (a InputStream), it will be closed automatically after download.
* @param content the content
* @param contentType the content type (a.k.a., MIME type),
* e.g., application/pdf
* @param flnm the suggested file name, e.g., myfile.pdf.
* If null, no suggested name is provided.
*/
public static void save(InputStream content, String contentType, String flnm) {
save(new AMedia(flnm, null, contentType, content), flnm);
} /** Open a download dialog to save the specified content at the client
* with the suggested file name.<br/>
* Note: You don't need to close the content (a Reader), it will be closed automatically after download.
* @param content the content
* @param contentType the content type (a.k.a., MIME type),
* e.g., application/pdf
* @param flnm the suggested file name, e.g., myfile.pdf.
* If null, no suggested name is provided.
*/
public static void save(Reader content, String contentType, String flnm) {
save(new AMedia(flnm, null, contentType, content), flnm);
} /** Open a download dialog to save the specified file at the client.
*
* @param file the file to download to the client
* @param contentType the content type, e.g., application/pdf.
* Unlike other save methods, it is optional. If null, the file name's
* extension is used to determine the content type.
* @exception FileNotFoundException if the file is not found.
* @since 3.0.8
*/
public static void save(File file, String contentType) throws FileNotFoundException {
save(new AMedia(file, contentType, null), file.getName());
} /** Open a download dialog to save the resource of the specified URL
* at the client.
* The path must be retrievable by use of {@link org.zkoss.zk.ui.WebApp#getResource}.
*
* @param url the URL to get the resource
* @param contentType the content type, e.g., application/pdf.
* Unlike other save methods, it is optional. If null, the path's
* extension is used to determine the content type.
* @exception FileNotFoundException if the resource is not found.
* @since 3.0.8
*/
public static void save(URL url, String contentType) throws FileNotFoundException {
String name = url.toExternalForm();
int j = name.lastIndexOf('/');
if (j >= 0 && j < name.length() - 1)
name = name.substring(j + 1);
save(new AMedia(url, contentType, null), name);
} /** Open a download dialog to save the resource of the specified path
* at the client.
*
* @param path the path of the resource.
* It must be retrievable by use of {@link org.zkoss.zk.ui.WebApp#getResource}.
* @param contentType the content type, e.g., application/pdf.
* Unlike other save methods, it is optional. If null, the path's
* extension is used to determine the content type.
* @exception FileNotFoundException if the resource is not found.
* @since 3.0.8
*/
public static void save(String path, String contentType) throws FileNotFoundException {
final URL url = Executions.getCurrent().getDesktop().getWebApp().getResource(path);
if (url == null)
throw new FileNotFoundException(path);
save(url, contentType);
} private static class DownloadURL implements DeferredValue {
private final Media _media;
private final String _path; private DownloadURL(Media media, String flnm) {
_media = media; if (flnm == null)
flnm = media.getName(); final StringBuffer sb = new StringBuffer(32);
if (flnm != null && flnm.length() != 0) {
sb.append('/');
sb.append(flnm);
if (flnm.lastIndexOf('.') < 0) {
final String format = media.getFormat();
if (format != null)
sb.append('.').append(format);
}
}
_path = sb.toString();
} public Object getValue() {
return Executions.getCurrent().getDesktop().getDownloadMediaURI(_media, _path);
}
}
}
org.zkoss.zul.Filedownload.java 源码的更多相关文章
- 如何阅读Java源码 阅读java的真实体会
刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比 ...
- Android反编译(一)之反编译JAVA源码
Android反编译(一) 之反编译JAVA源码 [目录] 1.工具 2.反编译步骤 3.实例 4.装X技巧 1.工具 1).dex反编译JAR工具 dex2jar http://code.go ...
- 如何阅读Java源码
刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动.源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比方吧, ...
- Java 源码学习线路————_先JDK工具包集合_再core包,也就是String、StringBuffer等_Java IO类库
http://www.iteye.com/topic/1113732 原则网址 Java源码初接触 如果你进行过一年左右的开发,喜欢用eclipse的debug功能.好了,你现在就有阅读源码的技术基础 ...
- Programming a Spider in Java 源码帖
Programming a Spider in Java 源码帖 Listing 1: Finding the bad links (CheckLinks.java) import java.awt. ...
- 解密随机数生成器(二)——从java源码看线性同余算法
Random Java中的Random类生成的是伪随机数,使用的是48-bit的种子,然后调用一个linear congruential formula线性同余方程(Donald Knuth的编程艺术 ...
- Java--Eclipse关联Java源码
打开Eclipse,Window->Preferences->Java 点Edit按钮后弹出: 点Source Attachment后弹出: 选择Java安装路径下的src.zip文件即可 ...
- 使用JDT.AST解析java源码
在做java源码的静态代码审计时,最基础的就是对java文件进行解析,从而获取到此java文件的相关信息: 在java文件中所存在的东西很多,很复杂,难以用相关的正则表达式去一一匹配.但是,eclip ...
- [收藏] Java源码阅读的真实体会
收藏自http://www.iteye.com/topic/1113732 刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动. 源码阅读,我 ...
随机推荐
- spring-boot整合shiro实现权限管理
1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...
- 2017 山东一轮集训 Day2 Shadow (三维凸包点在面上投影)
在三维坐标中,给定一个点光源,一个凸多面体,以及一个平面作为地面. 求该凸多面体在地面上阴影的面积. 这三个点共同确定了一个平面,这个平面就是地面.保证这三个点坐标互异且不共线.前三行每行三个实数,每 ...
- delphi+mysql做的图书管理系统,怎么把mysql数据库也一起打包进去?我用的是delphi的Express组件。
sqlconnection,sqlquery1这些组件,我连接数据库的时候是用对象编辑器里的属性进行连接的,在sqlconnection中指定了字符集utf8,有些人做的方法是利用代码连接的数据库,如 ...
- Javac编译找不到符号,报错
Javac编译找不到符号 报错 找不到符号 如果是两个.java有调用关系,需要同时编译 首先我检查了下代码,发现并没有问题,然后将A.java文件的内容复制到D.java中,发现程序能正常运行,而之 ...
- 汉诺塔IX
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=76447#problem/E 汉诺塔IX Time Limit:1000MS Me ...
- [CSP-S模拟测试]:赤壁情(DP)
前赤壁赋 壬戌之秋,七月既望,苏子与客泛舟游于赤壁之下.清风徐来,水波不兴.举酒属客,诵明月之诗,歌窈窕之章.少焉,月出于东山之上,徘徊于斗牛之间.白露横江,水光接天.纵一苇之所如,凌万顷之茫然.浩浩 ...
- svn没有权限检出项目
解决方法 鼠标右键,svn,setings
- 抓包工具fiddler下载配置(一):下载/安装&信任证书
简介 Fiddler一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fiddler的数据(指cookie,html,js,css等文件 ...
- ESET激活码,可用。
ESET Internet Security 12.1.31.0 Finalhttps://download.eset.com/com/eset/apps/home/eis/windows/v12/1 ...
- JVM系列(二) — Java垃圾收集介绍
这篇文章主要从以下几个方面介绍垃圾收集的相关知识 一.判断对象是否已死 二.主流垃圾收集算法 三.内存分配与回收策略 本章节主要从以下几个思考点着手介绍垃圾回收的相关知识:哪些内存需要回收?什么时候回 ...