KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > formbean > UploadForm


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.formbean;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import java.util.*;
20
21 import org.apache.struts.action.ActionError;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionMapping;
24 import org.apache.struts.upload.FormFile;
25
26 /**
27  * @author Liudong
28  * @deprecated 该类已经废弃由UploadImageForm以及UploadFlashForm替代
29  * 上传日志附件表单
30  */

31 public class UploadForm extends DlogActionForm {
32     
33     FormFile uploadFile = null;
34     String JavaDoc form = "forms[0]";
35     /**
36      * @return
37      */

38     public FormFile getUploadFile() {
39         return uploadFile;
40     }
41
42     /**
43      * @param file
44      */

45     public void setUploadFile(FormFile file) {
46         uploadFile = file;
47     }
48
49     /* (non-Javadoc)
50      * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
51      */

52     
53     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
54         ActionErrors errors = new ActionErrors();
55         if(uploadFile!=null){
56             if(uploadFile.getFileSize()>1000000)
57                 errors.add("uploadFile",new ActionError("upload_file_size_exceed"));
58             String JavaDoc fn = uploadFile.getFileName();
59             int i=0;
60             for(;i<types.size();i++){
61                 if(fn.endsWith((String JavaDoc)types.get(i)))
62                     break;
63             }
64             if(i==types.size()){
65                 errors.add("uploadFile",new ActionError("upload_file_extend_noallow"));
66             }
67         }
68         return errors;
69     }
70     public final static List types = Arrays.asList(new String JavaDoc[]{"gif","jpg","bmp","png","swf"});
71     /**
72      * @return
73      */

74     public String JavaDoc getForm() {
75         return form;
76     }
77
78     /**
79      * @param string
80      */

81     public void setForm(String JavaDoc string) {
82         form = string;
83     }
84
85 }
86
Popular Tags