01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * 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;
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 form = "forms[0]";
35:
36: /**
37: * @return
38: */
39: public FormFile getUploadFile() {
40: return uploadFile;
41: }
42:
43: /**
44: * @param file
45: */
46: public void setUploadFile(FormFile file) {
47: uploadFile = file;
48: }
49:
50: /* (non-Javadoc)
51: * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
52: */
53:
54: public ActionErrors validate(ActionMapping mapping,
55: HttpServletRequest request) {
56: ActionErrors errors = new ActionErrors();
57: if (uploadFile != null) {
58: if (uploadFile.getFileSize() > 1000000)
59: errors.add("uploadFile", new ActionError(
60: "upload_file_size_exceed"));
61: String fn = uploadFile.getFileName();
62: int i = 0;
63: for (; i < types.size(); i++) {
64: if (fn.endsWith((String) types.get(i)))
65: break;
66: }
67: if (i == types.size()) {
68: errors.add("uploadFile", new ActionError(
69: "upload_file_extend_noallow"));
70: }
71: }
72: return errors;
73: }
74:
75: public final static List types = Arrays.asList(new String[] {
76: "gif", "jpg", "bmp", "png", "swf" });
77:
78: /**
79: * @return
80: */
81: public String getForm() {
82: return form;
83: }
84:
85: /**
86: * @param string
87: */
88: public void setForm(String string) {
89: form = string;
90: }
91:
92: }
|