KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > icefaces > samples > showcase > components > fileUpload > InputFileBean


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.icefaces.samples.showcase.components.fileUpload;
35
36 import com.icesoft.faces.async.render.RenderManager;
37 import com.icesoft.faces.async.render.Renderable;
38 import com.icesoft.faces.component.inputfile.InputFile;
39 import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;
40 import com.icesoft.faces.webapp.xmlhttp.RenderingException;
41
42 import javax.faces.event.ActionEvent;
43 import java.io.File JavaDoc;
44 import java.util.EventObject JavaDoc;
45
46 /**
47  * <p>The InputFileBean class is the backing bean for the inputfile showcase
48  * demonstration. It is used to store the state of the uploaded file.</p>
49  *
50  * @since 0.3.0
51  */

52 public class InputFileBean implements Renderable {
53
54     private int percent = -1;
55     private File file = null;
56
57     /**
58      * Renderable Interface
59      */

60     private PersistentFacesState state;
61     private RenderManager renderManager;
62
63     private String JavaDoc fileName = "";
64     private String JavaDoc contentType = "";
65
66
67     public InputFileBean() {
68         state = PersistentFacesState.getInstance();
69     }
70
71     /**
72      * Sets the Render Manager.
73      *
74      * @param renderManager
75      */

76     public void setRenderManager(RenderManager renderManager) {
77
78         this.renderManager = renderManager;
79     }
80
81     /**
82      * Gets RenderManager, just try to satisfy WAS
83      *
84      * @return RenderManager null
85      */

86     public RenderManager getRenderManager() {
87         return null;
88     }
89
90     /**
91      * Get the PersistentFacesState.
92      *
93      * @return state the PersistantFacesState
94      */

95     public PersistentFacesState getState() {
96
97         return state;
98     }
99
100     /**
101      * Handles rendering exceptions for the progress bar.
102      *
103      * @param renderingException the exception that occured
104      */

105     public void renderingException(RenderingException renderingException) {
106         renderingException.printStackTrace();
107     }
108
109     public void setPercent(int percent) {
110         this.percent = percent;
111     }
112
113     public int getPercent() {
114         return percent;
115     }
116
117     public void setFile(File file) {
118         this.file = file;
119     }
120
121     public File getFile() {
122         return file;
123     }
124
125     public void action(ActionEvent event) {
126         InputFile inputFile = (InputFile) event.getSource();
127         fileName = inputFile.getFileInfo().getFileName();
128         contentType = inputFile.getFileInfo().getContentType();
129         this.percent = inputFile.getFileInfo().getPercent();
130         if (inputFile.getStatus() == InputFile.SAVED) {
131             setFile(inputFile.getFile());
132         }
133
134         if (inputFile.getStatus() == InputFile.INVALID) {
135             inputFile.getFileInfo().getException().printStackTrace();
136         }
137
138         if (inputFile.getStatus() == InputFile.SIZE_LIMIT_EXCEEDED) {
139             inputFile.getFileInfo().getException().printStackTrace();
140         }
141
142         if (inputFile.getStatus() == InputFile.UNKNOWN_SIZE) {
143             inputFile.getFileInfo().getException().printStackTrace();
144         }
145     }
146
147     public void progress(EventObject JavaDoc event) {
148         InputFile file = (InputFile) event.getSource();
149         this.percent = file.getFileInfo().getPercent();
150
151         if (renderManager != null) {
152            renderManager.requestRender(this);
153         }
154
155     }
156
157
158     public void setFileName(String JavaDoc fileName) {
159         this.fileName = fileName;
160     }
161
162     public String JavaDoc getFileName() {
163         return fileName;
164     }
165
166     public void setContentType(String JavaDoc contentType) {
167         this.contentType = contentType;
168     }
169
170     public String JavaDoc getContentType() {
171         return contentType;
172     }
173
174 }
175
Popular Tags