KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > upload > MultipartElement


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

18
19 package org.apache.struts.upload;
20
21 import java.io.File JavaDoc;
22
23 /**
24  * This class represents an element in a multipart request.
25  * It has a few methods for determining * whether or not the element is a
26  * String or a file, and methods to retrieve the data of the aforementioned
27  * element. Text input elements have a <code>null</code> content type,
28  * files have a non-null content type.
29  *
30  *
31  * @deprecated Use the Commons FileUpload based multipart handler instead. This
32  * class will be removed after Struts 1.2.
33  */

34 public class MultipartElement
35 {
36     /**
37      * The content type of this element.
38      */

39     protected String JavaDoc contentType;
40
41     /**
42      * The element data.
43      * @deprecated This should never be used.
44      */

45     protected byte[] data;
46
47     /**
48      * The element's data represented in a (possibly temporary) file.
49      */

50     protected File JavaDoc file;
51
52     /**
53      * The element name.
54      */

55     protected String JavaDoc name;
56
57     /**
58      * The element's filename, null for text elements.
59      */

60     protected String JavaDoc fileName;
61
62
63     /**
64      * The element's text value, null for file elements
65      */

66     protected String JavaDoc value;
67
68
69     /**
70      * Whether or not this element is a file.
71      */

72     protected boolean isFile = false;
73
74     /**
75      * Constructor for a file element.
76      * @param name The form name of the element
77      * @param fileName The file name of the element if this element is a file
78      * @param contentType The content type of the element if a file
79      * @param file The (possibly temporary) file representing this element if
80      * it's a file
81      */

82     public MultipartElement(String JavaDoc name, String JavaDoc fileName,
83                             String JavaDoc contentType, File JavaDoc file)
84     {
85         this.name = name;
86         this.fileName = fileName;
87         this.contentType = contentType;
88         this.file = file;
89         this.isFile = true;
90     }
91
92     /**
93      * Constructor for a text element.
94      * @param name The name of the element
95      * @param value The value of the element
96      */

97     public MultipartElement(String JavaDoc name, String JavaDoc value)
98     {
99          this.name = name;
100          this.value = value;
101          this.isFile = false;
102     }
103
104     /**
105       * Retrieve the content type.
106       */

107     public String JavaDoc getContentType()
108     {
109          return contentType;
110     }
111
112     /**
113      * Get the File that holds the data for this element.
114      */

115     public File JavaDoc getFile()
116     {
117        return file;
118     }
119
120
121     /**
122      * Retrieve the name.
123      */

124     public String JavaDoc getName()
125     {
126        return name;
127     }
128
129     /**
130      * Retrieve the filename, can return <code>null</code>
131      * for text elements.
132      */

133     public String JavaDoc getFileName()
134     {
135       return fileName;
136     }
137
138
139     /**
140      * Returns the value of this multipart element.
141      * @return A String if the element is a text element, <code>null</code>
142      * otherwise
143      */

144     public String JavaDoc getValue()
145     {
146         return value;
147     }
148
149
150     /**
151      * Set the file that represents this element.
152      */

153     public void setFile(File JavaDoc file)
154     {
155         this.file = file;
156     }
157
158
159     /**
160      * Set the file name for this element.
161      */

162     public void setFileName(String JavaDoc fileName)
163     {
164         this.fileName = fileName;
165     }
166
167
168     /**
169      * Set the name for this element.
170      */

171     public void setName(String JavaDoc name)
172     {
173         this.name = name;
174     }
175
176
177     /**
178      * Set the content type.
179      */

180     public void setContentType(String JavaDoc contentType)
181     {
182          this.contentType = contentType;
183     }
184
185
186     /**
187      * Is this element a file.
188      */

189     public boolean isFile()
190     {
191         if (file == null)
192         {
193             return false;
194         }
195         return true;
196     }
197
198
199     public void setValue(String JavaDoc value)
200     {
201         this.value = value;
202     }
203
204 }
205
Popular Tags