View Javadoc

1   /*
2    * $Id: MultipartElement.java 127 2004-11-06 10:15:26Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.filters.upload;
24  
25  /**
26   * Encapsulates an element of a multipart request.
27   *
28   * @author  Jose M. Palomar
29   * @version $Revision: 127 $
30   */
31  public final class MultipartElement {
32  
33      // Constants
34      /**
35       * Element type text.
36       */
37      public static final int TEXT = 0;
38  
39      /**
40       * Element type file.
41       */
42      public static final int FILE = 1;
43  
44      // Fields
45      /**
46       * Name of element.
47       */
48      private final String name;
49  
50      /**
51       * File name of element.
52       */
53      private final String filename;
54  
55      /**
56       * Value of element.
57       */
58      private final Object value;
59  
60      /**
61       * Type of element.
62       */
63      private final int type;
64  
65      // Constructors
66      /**
67       * Creates a new <code>MultipartElement</code> of type TEXT using given name and
68       * value.
69       *
70       * @param name String name of element.
71       * @param value String value of element.
72       */
73      public MultipartElement(String name, String value) {
74          this.name = name;
75          this.filename = null;
76          this.value = value;
77          this.type = TEXT;
78      }
79  
80      /**
81       * Creates a new <code>MultipartElement</code> of type FILE using given name and
82       * value.
83       *
84       * @param name String name of element.
85       * @param filename String file name of element.
86       * @param value MultipartFile value of element.
87       */
88      public MultipartElement(String name, String filename, MultipartFile value) {
89          this.name = name;
90          this.filename = filename;
91          this.value = value;
92          this.type = FILE;
93      }
94  
95      // Methods
96      /**
97       * Returns name of element.
98       *
99       * @return String name of element.
100      */
101     public String getName() {
102         return name;
103     }
104 
105     /**
106      * Returns file name of element (FILE type only).
107      *
108      * @return String file name of element.
109      */
110     public String getFilename() {
111         return filename;
112     }
113 
114     /**
115      * Returns value of element.
116      *
117      * @return Object value of element.
118      */
119     public Object getValue() {
120         return value;
121     }
122 
123     /**
124      * Returns type of element. Type can be TEXT of FILE.
125      *
126      * @return int type of element.
127      */
128     public int getType() {
129         return type;
130     }
131 
132 }