Source Code Cross Referenced for Filedownload.java in  » Ajax » zk » org » zkoss » zul » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » zk » org.zkoss.zul 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Filedownload.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Mon Apr 16 09:29:44     2007, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zul;
020:
021:        import java.io.InputStream;
022:        import java.io.Reader;
023:
024:        import org.zkoss.util.media.Media;
025:        import org.zkoss.util.media.AMedia;
026:
027:        import org.zkoss.zk.ui.Desktop;
028:        import org.zkoss.zk.ui.Executions;
029:        import org.zkoss.zk.ui.sys.WebAppCtrl;
030:        import org.zkoss.zk.au.out.AuDownload;
031:
032:        /**
033:         * File download utilities.
034:         *
035:         * @author tomyeh
036:         * @see Fileupload
037:         */
038:        public class Filedownload {
039:            /** Open a download dialog to save the specified content at the client.
040:             */
041:            public static void save(Media media) {
042:                save(media, null);
043:            }
044:
045:            /** Open a download dialog to save the specified content at the client
046:             * with the suggested file name.
047:             *
048:             * @param media the media to download
049:             * @param flnm the suggested file name, e.g., myfile.pdf.
050:             * If null, {@link Media#getName} is assumed.
051:             */
052:            public static void save(Media media, String flnm) {
053:                final Desktop desktop = Executions.getCurrent().getDesktop();
054:                if (flnm == null)
055:                    flnm = media.getName();
056:
057:                final StringBuffer sb = new StringBuffer(32);
058:                if (flnm != null && flnm.length() != 0) {
059:                    sb.append('/');
060:                    sb.append(flnm);
061:                    if (flnm.lastIndexOf('.') < 0) {
062:                        final String format = media.getFormat();
063:                        if (format != null)
064:                            sb.append('.').append(format);
065:                    }
066:                }
067:                final String uri = desktop.getDownloadMediaURI(media, sb
068:                        .toString());
069:                ((WebAppCtrl) desktop.getWebApp()).getUiEngine().addResponse(
070:                        null, new AuDownload(uri));
071:            }
072:
073:            /** Open a download dialog to save the specified content at the client
074:             * with the suggested file name.
075:             *
076:             * @param content the content
077:             * @param contentType the content type (aka., mine type),
078:             * e.g., application/pdf
079:             * @param flnm the suggested file name, e.g., myfile.pdf.
080:             * If null, no suggested name is provided.
081:             */
082:            public static void save(byte[] content, String contentType,
083:                    String flnm) {
084:                save(new AMedia(flnm, null, contentType, content), flnm);
085:            }
086:
087:            /** Open a download dialog to save the specified content at the client
088:             * with the suggested file name.
089:             *
090:             * @param content the content
091:             * @param contentType the content type (aka., mine type),
092:             * e.g., application/pdf
093:             * @param flnm the suggested file name, e.g., myfile.pdf.
094:             * If null, no suggested name is provided.
095:             */
096:            public static void save(String content, String contentType,
097:                    String flnm) {
098:                save(new AMedia(flnm, null, contentType, content), flnm);
099:            }
100:
101:            /** Open a download dialog to save the specified content at the client
102:             * with the suggested file name.
103:             *
104:             * @param content the content
105:             * @param contentType the content type (aka., mine type),
106:             * e.g., application/pdf
107:             * @param flnm the suggested file name, e.g., myfile.pdf.
108:             * If null, no suggested name is provided.
109:             */
110:            public static void save(InputStream content, String contentType,
111:                    String flnm) {
112:                save(new AMedia(flnm, null, contentType, content), flnm);
113:            }
114:
115:            /** Open a download dialog to save the specified content at the client
116:             * with the suggested file name.
117:             *
118:             * @param content the content
119:             * @param contentType the content type (aka., mine type),
120:             * e.g., application/pdf
121:             * @param flnm the suggested file name, e.g., myfile.pdf.
122:             * If null, no suggested name is provided.
123:             */
124:            public static void save(Reader content, String contentType,
125:                    String flnm) {
126:                save(new AMedia(flnm, null, contentType, content), flnm);
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.