1. /*
  2. * $Header: /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: 1.2 $
  4. * $Date: 2004/02/22 18:08:45 $
  5. *
  6. * ====================================================================
  7. *
  8. * Copyright 2002-2004 The Apache Software Foundation
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * ====================================================================
  22. *
  23. * This software consists of voluntary contributions made by many
  24. * individuals on behalf of the Apache Software Foundation. For more
  25. * information on the Apache Software Foundation, please see
  26. * <http://www.apache.org/>.
  27. *
  28. * [Additional notices, if required by prior licensing conditions]
  29. *
  30. */
  31. package org.apache.commons.httpclient.contrib.methods.multipart;
  32. import java.io.File;
  33. import java.io.FileNotFoundException;
  34. import org.apache.commons.httpclient.methods.multipart.FilePart;
  35. import org.apache.commons.httpclient.methods.multipart.PartSource;
  36. /** A simple extension to {@link FilePart} that automatically determines the content type
  37. * of the file.
  38. *
  39. * @author <a href="mailto:adrian@intencha.com">Adrian Sutton</a>
  40. * @version $Revision $
  41. *
  42. * DISCLAIMER: HttpClient developers DO NOT actively support this component.
  43. * The component is provided as a reference material, which may be inappropriate
  44. * to be used without additional customization.
  45. */
  46. public class ContentTypeFilePart extends FilePart {
  47. /**
  48. * ContentTypeFilePart constructor.
  49. *
  50. * @param name the name of the part
  51. * @param partSource the source for this part
  52. * @param charset the charset encoding for this part.
  53. */
  54. public ContentTypeFilePart(String name, PartSource partSource, String charset) {
  55. super(name, partSource, ContentType.get(partSource.getFileName()), charset);
  56. }
  57. /**
  58. * ContentTypeFilePart constructor.
  59. *
  60. * @param name the name of the part
  61. * @param partSource the source for this part
  62. */
  63. public ContentTypeFilePart(String name, PartSource partSource) {
  64. this(name, partSource, null);
  65. }
  66. /**
  67. * ContentTypeFilePart constructor.
  68. *
  69. * @param name the name of the part
  70. * @param file the file to post
  71. * @throws FileNotFoundException if the file does not exist
  72. */
  73. public ContentTypeFilePart(String name, File file) throws FileNotFoundException {
  74. this(name, file, null);
  75. }
  76. /**
  77. * ContentTypeFilePart constructor.
  78. *
  79. * @param name the name of the part
  80. * @param file the file to post
  81. * @param charset the charset encoding for the file
  82. * @throws FileNotFoundException
  83. */
  84. public ContentTypeFilePart(String name, File file, String charset)
  85. throws FileNotFoundException {
  86. super(name, file, ContentType.get(file), charset);
  87. }
  88. /**
  89. * ContentTypeFilePart constructor.
  90. *
  91. * @param name the name of the part
  92. * @param fileName the file name
  93. * @param file the file to post
  94. * @throws FileNotFoundException if the file does not exist
  95. */
  96. public ContentTypeFilePart(String name, String fileName, File file)
  97. throws FileNotFoundException {
  98. super(name, fileName, file, ContentType.get(fileName), null);
  99. }
  100. /**
  101. * ContentTypeFilePart constructor.
  102. *
  103. * @param name the name of the part
  104. * @param fileName the file name
  105. * @param file the file to post
  106. * @param charset the charset encoding for the file
  107. * @throws FileNotFoundException if the file does not exist
  108. */
  109. public ContentTypeFilePart(String name, String fileName, File file,
  110. String charset) throws FileNotFoundException {
  111. super(name, fileName, file, ContentType.get(file), charset);
  112. }
  113. }