KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > form > UploadResourceForm


1 package org.nextime.ion.backoffice.form;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4
5 import org.apache.struts.action.ActionError;
6 import org.apache.struts.action.ActionErrors;
7 import org.apache.struts.action.ActionForm;
8 import org.apache.struts.action.ActionMapping;
9 import org.apache.struts.upload.FormFile;
10 import org.nextime.ion.backoffice.bean.Resources;
11
12 public class UploadResourceForm extends ActionForm {
13
14     private String JavaDoc name;
15     private FormFile file;
16
17     /**
18      * @see org.apache.struts.action.ActionForm#validate(ActionMapping, HttpServletRequest)
19      */

20     public ActionErrors validate(
21         ActionMapping arg0,
22         HttpServletRequest JavaDoc request) {
23         
24         // set resources directory
25
try {
26             request.setAttribute("resources",Resources.getResourceXmlBeans(servlet));
27         }
28         catch( Exception JavaDoc e ) {
29             e.printStackTrace();
30         }
31         
32         ActionErrors errors = new ActionErrors();
33         if (getName() == null) {
34             ActionError error =
35                 new ActionError("error.uploadResource.missingName");
36             errors.add("name", error);
37         } else {
38             if (getName().trim().equals("")) {
39                 ActionError error2 =
40                     new ActionError("error.uploadResource.missingName");
41                 errors.add("name", error2);
42             } else {
43                 if (getName().indexOf(".") != -1
44                     || getName().indexOf("/") != -1
45                     || getName().indexOf("\\") != -1
46                     || getName().indexOf("%") != -1
47                     || getName().indexOf("&") != -1) {
48                     ActionError error3 =
49                         new ActionError("error.uploadResource.badName");
50                     errors.add("name", error3);
51
52                 }
53             }
54         }
55         if (getFile().getFileSize() == 0) {
56             ActionError error =
57                 new ActionError("error.uploadResource.missingFile");
58             errors.add("file", error);
59         }
60         return errors;
61     }
62
63     /**
64      * @see org.apache.struts.action.ActionForm#reset(ActionMapping, HttpServletRequest)
65      */

66     public void reset(ActionMapping arg0, HttpServletRequest JavaDoc arg1) {
67         setName(null);
68         setFile(null);
69     }
70
71     /**
72      * Returns the file.
73      * @return File
74      */

75     public FormFile getFile() {
76         return file;
77     }
78
79     /**
80      * Returns the name.
81      * @return String
82      */

83     public String JavaDoc getName() {
84         return name;
85     }
86
87     /**
88      * Sets the file.
89      * @param file The file to set
90      */

91     public void setFile(FormFile file) {
92         this.file = file;
93     }
94
95     /**
96      * Sets the name.
97      * @param name The name to set
98      */

99     public void setName(String JavaDoc name) {
100         this.name = name;
101     }
102
103 }
104
Popular Tags