Source Code Cross Referenced for InputFileBean.java in  » Content-Management-System » contineo » org » contineo » web » upload » 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 » Content Management System » contineo » org.contineo.web.upload 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.web.upload;
002:
003:        import com.icesoft.faces.async.render.RenderManager;
004:        import com.icesoft.faces.async.render.Renderable;
005:        import com.icesoft.faces.component.inputfile.InputFile;
006:        import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
007:        import com.icesoft.faces.webapp.xmlhttp.RenderingException;
008:
009:        import org.apache.commons.io.FileUtils;
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:
013:        import java.io.File;
014:        import java.io.FileInputStream;
015:        import java.io.IOException;
016:        import java.io.InputStream;
017:
018:        import java.util.EventObject;
019:
020:        import javax.faces.event.ActionEvent;
021:
022:        /**
023:         * <p>
024:         * The InputFileBean class is the backing bean for the inputfile showcase
025:         * demonstration. It is used to store the state of the uploaded file.
026:         * </p>
027:         *
028:         * @author Marco Meschieri
029:         * @version $Id: InputFileBean.java,v 1.4 2007/07/16 06:35:17 marco Exp $
030:         * @since 3.0
031:         */
032:        public class InputFileBean implements  Renderable {
033:            protected static Log log = LogFactory.getLog(InputFileBean.class);
034:            private int percent = -1;
035:            private String language;
036:            private File file = null;
037:            private String description;
038:            private String versionType;
039:            private PersistentFacesState state;
040:            private RenderManager renderManager;
041:            private String fileName = "";
042:            private String contentType = "";
043:
044:            public InputFileBean() {
045:                state = PersistentFacesState.getInstance();
046:            }
047:
048:            /**
049:             * Sets the Render Manager.
050:             *
051:             * @param renderManager
052:             */
053:            public void setRenderManager(RenderManager renderManager) {
054:                this .renderManager = renderManager;
055:            }
056:
057:            /**
058:             * Gets RenderManager, just try to satisfy WAS
059:             *
060:             * @return RenderManager null
061:             */
062:            public RenderManager getRenderManager() {
063:                return null;
064:            }
065:
066:            /**
067:             * Get the PersistentFacesState.
068:             *
069:             * @return state the PersistantFacesState
070:             */
071:            public PersistentFacesState getState() {
072:                return state;
073:            }
074:
075:            /**
076:             * Handles rendering exceptions for the progress bar.
077:             *
078:             * @param renderingException the exception that occured
079:             */
080:            public void renderingException(RenderingException renderingException) {
081:                renderingException.printStackTrace();
082:            }
083:
084:            public void setPercent(int percent) {
085:                this .percent = percent;
086:            }
087:
088:            public int getPercent() {
089:                return percent;
090:            }
091:
092:            public void setFile(File file) {
093:                try {
094:                    // If another file was uploaded, first delete the old file
095:                    if ((this .file != null) && this .file.exists()) {
096:                        FileUtils.forceDelete(this .file);
097:                    }
098:                } catch (IOException e) {
099:                    log.error("Unable to delete temp file " + this .file);
100:                }
101:
102:                this .file = file;
103:            }
104:
105:            public File getFile() {
106:                return file;
107:            }
108:
109:            public void action(ActionEvent event) {
110:                InputFile inputFile = (InputFile) event.getSource();
111:                fileName = inputFile.getFileInfo().getFileName();
112:                contentType = inputFile.getFileInfo().getContentType();
113:                this .percent = inputFile.getFileInfo().getPercent();
114:
115:                if (inputFile.getStatus() == InputFile.SAVED) {
116:                    setFile(inputFile.getFile());
117:                }
118:
119:                if (inputFile.getStatus() == InputFile.INVALID) {
120:                    inputFile.getFileInfo().getException().printStackTrace();
121:                }
122:
123:                if (inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED) {
124:                    inputFile.getFileInfo().getException().printStackTrace();
125:                }
126:
127:                if (inputFile.getStatus() == InputFile.UNKNOWN_SIZE) {
128:                    inputFile.getFileInfo().getException().printStackTrace();
129:                }
130:            }
131:
132:            public void progress(EventObject event) {
133:                InputFile file = (InputFile) event.getSource();
134:                this .percent = file.getFileInfo().getPercent();
135:
136:                if (renderManager != null) {
137:                    renderManager.requestRender(this );
138:                }
139:
140:                try {
141:                    if (state != null) {
142:                        state.render();
143:                    }
144:                } catch (RenderingException e) {
145:                }
146:            }
147:
148:            public void setFileName(String fileName) {
149:                this .fileName = fileName;
150:            }
151:
152:            public String getFileName() {
153:                return fileName;
154:            }
155:
156:            public void setContentType(String contentType) {
157:                this .contentType = contentType;
158:            }
159:
160:            public String getContentType() {
161:                return contentType;
162:            }
163:
164:            public boolean isReady() {
165:                return percent == 100;
166:            }
167:
168:            public void deleteFile() {
169:                if ((file != null) && file.exists()) {
170:                    try {
171:                        FileUtils.forceDelete(file);
172:                    } catch (IOException e) {
173:                        log.error("Unable to delete temp file "
174:                                + file.getPath());
175:                    }
176:                }
177:
178:                percent = 0;
179:            }
180:
181:            public String getLanguage() {
182:                return language;
183:            }
184:
185:            public void setLanguage(String language) {
186:                this .language = language;
187:            }
188:
189:            /**
190:             * Reads the uploaded file and stores it's content into a string bufferO
191:             *
192:             * @throws IOException
193:             */
194:            public StringBuffer getContent() throws IOException {
195:                byte[] buffer = new byte[1024];
196:                int read = 0;
197:                StringBuffer content = new StringBuffer();
198:                InputStream in = new FileInputStream(getFile());
199:
200:                while ((read = in.read(buffer, 0, 1024)) >= 0) {
201:                    content.append(new String(buffer, 0, read));
202:                }
203:
204:                return content;
205:            }
206:
207:            public String getDescription() {
208:                return description;
209:            }
210:
211:            public void setDescription(String description) {
212:                this .description = description;
213:            }
214:
215:            public void reset() {
216:                deleteFile();
217:                this .description = null;
218:                this .file = null;
219:                this .language = null;
220:                this .fileName = null;
221:            }
222:
223:            public String getVersionType() {
224:                return versionType;
225:            }
226:
227:            public void setVersionType(String versionType) {
228:                this.versionType = versionType;
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.