KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > contrib > methods > multipart > ContentTypeFilePart


1 /*
2  * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/contrib/org/apache/commons/httpclient/contrib/methods/multipart/ContentTypeFilePart.java,v 1.2 2004/02/22 18:08:45 olegk Exp $
3  * $Revision: 480424 $
4  * $Date: 2006-11-29 05:56:49 +0000 (Wed, 29 Nov 2006) $
5  *
6  * ====================================================================
7  *
8  * Licensed to the Apache Software Foundation (ASF) under one or more
9  * contributor license agreements. See the NOTICE file distributed with
10  * this work for additional information regarding copyright ownership.
11  * The ASF licenses this file to You under the Apache License, Version 2.0
12  * (the "License"); you may not use this file except in compliance with
13  * the License. You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * ====================================================================
23  *
24  * This software consists of voluntary contributions made by many
25  * individuals on behalf of the Apache Software Foundation. For more
26  * information on the Apache Software Foundation, please see
27  * <http://www.apache.org/>.
28  *
29  * [Additional notices, if required by prior licensing conditions]
30  *
31  */

32
33 package org.apache.commons.httpclient.contrib.methods.multipart;
34
35 import java.io.File JavaDoc;
36 import java.io.FileNotFoundException JavaDoc;
37
38 import org.apache.commons.httpclient.methods.multipart.FilePart;
39 import org.apache.commons.httpclient.methods.multipart.PartSource;
40
41 /** A simple extension to {@link FilePart} that automatically determines the content type
42  * of the file.
43  *
44  * @author <a HREF="mailto:adrian@intencha.com">Adrian Sutton</a>
45  * @version $Revision $
46  *
47  * DISCLAIMER: HttpClient developers DO NOT actively support this component.
48  * The component is provided as a reference material, which may be inappropriate
49  * to be used without additional customization.
50  */

51 public class ContentTypeFilePart extends FilePart {
52
53     /**
54      * ContentTypeFilePart constructor.
55      *
56      * @param name the name of the part
57      * @param partSource the source for this part
58      * @param charset the charset encoding for this part.
59      */

60     public ContentTypeFilePart(String JavaDoc name, PartSource partSource, String JavaDoc charset) {
61         super(name, partSource, ContentType.get(partSource.getFileName()), charset);
62     }
63
64     /**
65      * ContentTypeFilePart constructor.
66      *
67      * @param name the name of the part
68      * @param partSource the source for this part
69      */

70     public ContentTypeFilePart(String JavaDoc name, PartSource partSource) {
71         this(name, partSource, null);
72     }
73
74     /**
75      * ContentTypeFilePart constructor.
76      *
77      * @param name the name of the part
78      * @param file the file to post
79      * @throws FileNotFoundException if the file does not exist
80      */

81     public ContentTypeFilePart(String JavaDoc name, File JavaDoc file) throws FileNotFoundException JavaDoc {
82         this(name, file, null);
83     }
84
85     /**
86      * ContentTypeFilePart constructor.
87      *
88      * @param name the name of the part
89      * @param file the file to post
90      * @param charset the charset encoding for the file
91      * @throws FileNotFoundException
92      */

93     public ContentTypeFilePart(String JavaDoc name, File JavaDoc file, String JavaDoc charset)
94         throws FileNotFoundException JavaDoc {
95         super(name, file, ContentType.get(file), charset);
96     }
97
98     /**
99      * ContentTypeFilePart constructor.
100      *
101      * @param name the name of the part
102      * @param fileName the file name
103      * @param file the file to post
104      * @throws FileNotFoundException if the file does not exist
105      */

106     public ContentTypeFilePart(String JavaDoc name, String JavaDoc fileName, File JavaDoc file)
107         throws FileNotFoundException JavaDoc {
108         super(name, fileName, file, ContentType.get(fileName), null);
109     }
110
111     /**
112      * ContentTypeFilePart constructor.
113      *
114      * @param name the name of the part
115      * @param fileName the file name
116      * @param file the file to post
117      * @param charset the charset encoding for the file
118      * @throws FileNotFoundException if the file does not exist
119      */

120     public ContentTypeFilePart(String JavaDoc name, String JavaDoc fileName, File JavaDoc file,
121         String JavaDoc charset) throws FileNotFoundException JavaDoc {
122         super(name, fileName, file, ContentType.get(file), charset);
123     }
124 }
125
Popular Tags