KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > filemgr > EAFileMgrUploadBean


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.filemgr;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9
10 import org.apache.struts.action.*;
11 import org.apache.struts.upload.FormFile;
12
13 import com.raptus.owxv3.LoggingManager;
14 import com.raptus.owxv3.api.*;
15
16 /**
17  *
18  * <hr>
19  * <table width="100%" border="0">
20  * <tr>
21  * <td width="24%"><b>Filename</b></td><td width="76%">EAFileMgrUploadBean.java</td>
22  * </tr>
23  * <tr>
24  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Date</b></td><td width="76%">25th of September 2001</td>
28  * </tr>
29  * </table>
30  * <hr>
31  * <table width="100%" border="0">
32  * <tr>
33  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
34  * </tr>
35  * </table>
36  * <hr>
37  * <table width="100%" border="0">
38  * <tr>
39  * <td>This class is the form bean of the <code>EAFileMgrUploadAction</code> action.</td>
40  * </tr>
41  * </table>
42  * <hr>
43  *
44  */

45 public class EAFileMgrUploadBean extends OmniaWebBean
46 {
47     /**
48      *Represents the value of the radio button "existing category" or "new category"
49      */

50     protected int categorytype=FileMgrConstants.EXISTING_CATEGORY;
51
52     /**
53      *Represents the value of the allready existing category list
54      */

55     protected String JavaDoc catname="";
56
57     /**
58      *Represents the value of a new category name
59      */

60     protected String JavaDoc newcatname="";
61
62     /**
63      *Represents the file that is uploaded
64      */

65     protected FormFile uploadfile=null;
66     
67     /**
68      *Value indicating that the file should be overwritten or not
69      *
70      */

71     protected String JavaDoc overwrite=null;
72
73
74     /**
75      *this object will provide the list of existing categories
76      */

77     protected AllFileSelector fileSelector=null;
78
79
80     /**
81      *
82      */

83     protected int uploadFileCount=0;
84
85
86
87     /**
88      *Method for getting the categorytype: existing category or new category
89      */

90     public int getCategorytype() { return categorytype; }
91
92     /**
93      *Method for setting the categorytype: existing category or new category
94      */

95     public void setCategorytype(int c) { this.categorytype = c; }
96
97     /**
98      *Method for getting the selected category name from the category names list
99      */

100     public String JavaDoc getCatname() { return catname; }
101
102     /**
103      *Method for setting the selected category name from the category names list
104      */

105     public void setCatname(String JavaDoc name) { this.catname = name; }
106
107     /**
108      *Method for getting the new category name
109      */

110     public String JavaDoc getNewcatname() { return newcatname; }
111
112     /**
113      *Method for setting the new category name
114      */

115     public void setNewcatname(String JavaDoc name) { this.newcatname = name; }
116
117     /**
118      *Method for getting the file upload object
119      */

120     public FormFile getUploadfile() { return uploadfile; }
121
122     /**
123      *Method for setting the file upload object
124      */

125     public void setUploadfile(FormFile file) { this.uploadfile = file; }
126
127     /**
128      *Method for setting the value for overwrite
129      */

130     public void setOverwrite(String JavaDoc val) { this.overwrite=val; }
131     
132     /**
133      *Method for getting the value of overwrite
134      */

135     public String JavaDoc getOverwrite() { return this.overwrite; }
136
137     
138     /**
139      *Method for getting the FileSelector object
140      */

141     public AllFileSelector getFileSelector() { return fileSelector; }
142
143     /**
144      *Method for setting the FileSelector object, this should be called from the corresponding Action class
145      */

146     public void setFileSelector(AllFileSelector fs) { this.fileSelector=fs; }
147
148     /**
149      *Convenince method for determening the the newcatname or catname should be used
150      */

151     public String JavaDoc getCategoryName()
152     {
153         if(categorytype==FileMgrConstants.EXISTING_CATEGORY && ! catname.equals("0") ) return catname;
154
155         if(categorytype==FileMgrConstants.NEW_CATEGORY && ! newcatname.equals("")) return newcatname;
156
157         if(catname.equals("0") && ! newcatname.equals("")) return newcatname;
158
159         if(!catname.equals("0") && newcatname.equals("")) return newcatname;
160
161         return catname;
162     }
163
164
165     /**
166      *the reset method
167      */

168     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request)
169     {
170         super.reset(mapping, request);
171         this.categorytype=FileMgrConstants.EXISTING_CATEGORY;
172         this.catname="";
173         this.newcatname="";
174         this.uploadfile=null;
175
176     }
177
178
179     public void reset()
180     {
181         this.categorytype=FileMgrConstants.EXISTING_CATEGORY;
182         this.catname="";
183         this.newcatname="";
184         this.uploadfile=null;
185         this.overwrite=null;
186     }
187
188
189     /**
190      *The validate method is called when the form is getting submitted.
191      *We should check for 3 errors:
192      *<p>If the user didn't selected a category
193      *<p>If the user didn't entered a new category
194      *<p>If the user didn't selected a file from his hard disk
195      */

196
197     public ActionErrors validate(HttpServletRequest JavaDoc request)
198     {
199       ActionErrors ret=new ActionErrors();
200
201       if(catname.equals("0") && newcatname.equals(""))
202       {
203           if( categorytype==FileMgrConstants.EXISTING_CATEGORY && catname.equals("0") )
204           {
205               ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.upload.error.catnotselected"));
206
207           }
208
209
210           if(categorytype==FileMgrConstants.NEW_CATEGORY && newcatname.equals(""))
211           {
212               ret.add(ActionErrors.GLOBAL_ERROR,new ActionError("module.upload.error.emptynewcatname"));
213
214           }
215       }//end if
216

217       if(uploadfile!=null)
218           if(uploadfile.getFileName().equals(""))
219           {
220               LoggingManager.log("Invalid filename used for upload!", this);
221               ret.add( ActionErrors.GLOBAL_ERROR,new ActionError("module.upload.error.emptyfile") );
222           }
223       if(!ret.empty()) uploadfile=null;
224       return ret;
225
226     }
227
228     public void incUploadFileCount(){
229         uploadFileCount++;
230     }
231
232     public int getUploadFileCount(){
233         return uploadFileCount;
234     }
235
236 }
237
238 // eof
239
Popular Tags