KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > deploy > UploadForm


1 /**
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * --------------------------------------------------------------------------
17  * $Id: UploadForm.java,v 1.3 2005/07/25 21:03:54 pasmith Exp $
18  * --------------------------------------------------------------------------
19  */

20
21 package org.objectweb.jonas.webapp.jonasadmin.deploy;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.struts.action.ActionErrors;
25 import org.apache.struts.action.ActionForm;
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  * This class is a placeholder for form values. In a multipart request, files are represented by
34  * set and get methods that use the class org.apache.struts.upload.FormFile, an interface with
35  * basic methods to retrieve file information. The actual structure of the FormFile is dependant
36  * on the underlying impelementation of multipart request handling. The default implementation
37  * that struts uses is org.apache.struts.upload.CommonsMultipartRequestHandler.
38  *
39  * @version $Rev$ $Date: 2005/07/25 21:03:54 $
40  */

41 public class UploadForm extends ActionForm {
42
43     /**
44      * The file that the user has uploaded
45      */

46     private FormFile uploadedFile;
47     
48     /**
49      * Is the current context a domain management action?
50      */

51     private boolean isDomain;
52     
53     /**
54      * Overwrite value
55      */

56     private boolean overwrite = false;
57     
58     /**
59      * Return if the action is a domain management operation.
60      * @return if the action is a domain management operation.
61      */

62     public boolean getIsDomain() {
63         return this.isDomain;
64     }
65     
66     /**
67      * Sets if the action is a domain management operation.
68      * @param isDomain if the action is a domain management operation.
69      */

70     public void setIsDomain(boolean isDomain) {
71         this.isDomain = isDomain;
72     }
73     
74      /**
75      * @return a representation of the file the user has uploaded
76      */

77     public FormFile getUploadedFile() {
78         return uploadedFile;
79     }
80
81     /**
82      * Set a representation of the file the user has uploaded
83      * @param uploadedFile the file uploaded
84      */

85     public void setUploadedFile(FormFile uploadedFile) {
86         this.uploadedFile = uploadedFile;
87     }
88     
89     
90     /**
91      * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
92      * validate method.
93      * @param mapping the mapping used to select this instance
94      * @param request the servlet request we are processing
95      * @return Errors if it fails
96      */

97     public ActionErrors validate(
98         ActionMapping mapping,
99         HttpServletRequest JavaDoc request) {
100
101         ActionErrors errors = null;
102         //has the maximum length been exceeded?
103
Boolean JavaDoc maxLengthExceeded =
104             (Boolean JavaDoc) request.getAttribute(
105                 MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
106
107         if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
108             errors = new ActionErrors();
109             errors.add(
110                 ActionMessages.GLOBAL_MESSAGE ,
111                 new ActionMessage("maxLengthExceeded"));
112             errors.add(
113                 ActionMessages.GLOBAL_MESSAGE ,
114                 new ActionMessage("maxLengthExplanation"));
115         }
116         return errors;
117
118     }
119
120     /**
121      * @return true if the file will be overwritten
122      */

123     public boolean isOverwrite() {
124         return overwrite;
125     }
126
127
128     /**
129      * Replace the existing file ?
130      * @param overwrite true/false
131      */

132     public void setOverwrite(boolean overwrite) {
133         this.overwrite = overwrite;
134     }
135 }
Popular Tags