KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > forms > UploadForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.vfs.forms;
21
22 import javax.servlet.ServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.action.ActionMessages;
29 import org.apache.struts.upload.FormFile;
30 import org.apache.struts.upload.MultipartRequestHandler;
31
32 /**
33  *
34  */

35 public class UploadForm extends AbstractUploadForm {
36
37     private FormFile uploadFile;
38
39     /**
40      * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
41      * validate method.
42      */

43     public ActionErrors validate(
44         ActionMapping mapping,
45         HttpServletRequest JavaDoc request) {
46             
47         ActionErrors errors = null;
48         //has the maximum length been exceeded?
49
Boolean JavaDoc maxLengthExceeded =
50             (Boolean JavaDoc) request.getAttribute(
51                 MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
52                 
53         if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
54             errors = new ActionErrors();
55             errors.add(
56                 ActionMessages.GLOBAL_MESSAGE ,
57                 new ActionMessage("uploadFile.error.maxLengthExceeded"));
58         }
59         return errors;
60
61     }
62
63     /**
64      * @param uploadFile
65      */

66     public void setUploadFile(FormFile uploadFile) {
67         this.uploadFile = uploadFile;
68     }
69
70     /**
71      * @return FormFile
72      */

73     public FormFile getUploadFile() {
74         return uploadFile;
75     }
76
77     /* (non-Javadoc)
78      * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.ServletRequest)
79      */

80     public void reset(ActionMapping mapping, ServletRequest JavaDoc request) {
81         super.reset(mapping, request);
82         uploadFile = null;
83     }
84 }
85
Popular Tags