KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > form > core > UploadContentResourceForm


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.webapp.form.core;
17
18 import com.blandware.atleap.webapp.form.BaseForm;
19 import com.blandware.atleap.webapp.util.core.WebappConstants;
20 import org.apache.struts.action.ActionErrors;
21 import org.apache.struts.action.ActionMapping;
22 import org.apache.struts.action.ActionMessage;
23 import org.apache.struts.upload.FormFile;
24 import org.apache.struts.upload.MultipartRequestHandler;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 /**
29  * <p>Form bean for upload content resource
30  * </p>
31  * <p><a HREF="UploadContentResourceForm.java.htm"><i>View Source</i></a></p>
32  * <p/>
33  *
34  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
35  * @version $Revision: 1.9 $ $Date: 2006/03/19 16:16:38 $
36  * @struts.form name="uploadContentResourceForm"
37  */

38 public class UploadContentResourceForm extends BaseForm {
39
40     /**
41      * The file that the user has uploaded
42      */

43     protected transient FormFile file;
44
45     /**
46      * Retrieves a representation of the file the user has uploaded
47      *
48      * @return FormFile the uploaded file
49      */

50     public FormFile getFile() {
51         return file;
52     }
53
54     /**
55      * Sets a representation of the file the user has uploaded
56      *
57      * @param file the file to upload
58      */

59     public void setFile(FormFile file) {
60         this.file = file;
61     }
62
63     /**
64      * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
65      * validate method.
66      */

67     // Commented out to avoid: Unhandled Exception thrown: class java.lang.NullPointerException
68
public ActionErrors validate(ActionMapping mapping,
69                                  HttpServletRequest JavaDoc request) {
70         ActionErrors errors = null;
71         // has the maximum length been exceeded?
72
Boolean JavaDoc maxLengthExceeded =
73                 (Boolean JavaDoc) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
74         if ( (maxLengthExceeded != null) && (maxLengthExceeded.booleanValue()) ) {
75             errors = new ActionErrors();
76             errors.add("contentResourceMaxLengthExceeded",
77                     new ActionMessage("core.contentResource.errors.maxLengthExceeded"));
78             request.getSession().setAttribute(WebappConstants.ERROR_KEY, errors);
79         }
80         return errors;
81     }
82
83 }
Popular Tags