KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > UploadFileForm


1 /*
2  * UploadFileForm.java
3  *
4  * Created on June 6, 2003, 9:01 AM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.controller;
8
9 import javax.servlet.http.*;
10 import org.apache.struts.action.*;
11 import org.apache.struts.upload.FormFile;
12 import java.io.*;
13 /**
14  *
15  * @author Vinod Batra
16  */

17 public class UploadFileForm extends ActionForm{
18     
19     /** Holds value of property userFile. */
20     private FormFile userFile;
21     
22     /** Creates a new instance of UploadFileForm */
23     public UploadFileForm() {
24     }
25     
26     public void reset()
27     {
28         userFile = null;
29     }
30     
31     public ActionErrors validate(ActionMapping mapping,
32     HttpServletRequest request)
33     {
34         ActionErrors errors = new ActionErrors();
35
36         if (userFile == null)
37         {
38             errors.add("userFile", new ActionError("file.name.enter"));
39         }
40         
41         return errors;
42     }
43     
44     /** Getter for property fileName.
45      * @return Value of property fileName.
46      *
47      */

48     public java.lang.String JavaDoc getFileName()
49     {
50         if (userFile != null)
51         {
52             return userFile.getFileName();
53         }
54         
55         return null;
56     }
57     
58     /** Getter for property userFile.
59      * @return Value of property userFile.
60      *
61      */

62     public FormFile getUserFile()
63     {
64         return this.userFile;
65     }
66     
67     /** Setter for property userFile.
68      * @param userFile New value of property userFile.
69      *
70      */

71     public void setUserFile(FormFile userFile)
72     {
73         this.userFile = userFile;
74     }
75     
76     public byte[] getFileBytes() throws FileNotFoundException, IOException
77     {
78         if (userFile != null)
79         {
80             return userFile.getFileData();
81         }
82         
83         return null;
84     }
85     
86     public InputStream getFileStream() throws FileNotFoundException, IOException
87     {
88         if (userFile != null)
89         {
90             return userFile.getInputStream();
91         }
92         
93         return null;
94     }
95     
96     public String JavaDoc getFileContentType()
97     {
98         if (userFile != null)
99         {
100             return userFile.getContentType();
101         }
102         
103         return null;
104     }
105     
106     public int getFileSize()
107     {
108         if (userFile != null)
109         {
110             return userFile.getFileSize();
111         }
112         
113         return 0;
114     }
115     
116 }
117
Popular Tags