jsdever     2002/11/16 19:11:28

  Modified:    httpclient/src/java/org/apache/commons/httpclient/methods
                        MultipartPostMethod.java
               httpclient/src/java/org/apache/commons/httpclient/methods/multipart
                        FilePart.java FilePartSource.java
  Log:
  Patch for allowing the changing of the filename in in a multipart file post.
  I.E.
  1.) file name gotten from alternate string in FilePart.
  2.) file name gotten from java.io.File object in FilePart.
  
  Contributed by: Mark R. Diggory
  
  Revision  Changes    Path
  1.4       +11 -3     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java
  
  Index: MultipartPostMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultipartPostMethod.java  5 Nov 2002 17:50:22 -0000       1.3
  +++ MultipartPostMethod.java  17 Nov 2002 03:11:27 -0000      1.4
  @@ -80,6 +80,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Matthew Albright</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jeff Dever</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Sutton</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Mark Diggory</a>
    *
    * @since 2.0
    */
  @@ -157,6 +158,13 @@
           parameters.add(param);
       }
   
  +    public void addParameter(String parameterName, String fileName, File 
parameterFile) 
  +    throws FileNotFoundException {
  +        log.trace("enter addParameter(String parameterName, String fileName, File 
parameterFile)");
  +        Part param = new FilePart(parameterName, fileName, parameterFile);
  +        parameters.add(param);
  +    }
  +        
       /**
        * Adds another part to this post.
        */
  
  
  
  1.6       +19 -3     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java
  
  Index: FilePart.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FilePart.java     10 Nov 2002 08:09:53 -0000      1.5
  +++ FilePart.java     17 Nov 2002 03:11:27 -0000      1.6
  @@ -81,6 +81,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jeff Dever</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Sutton</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michael Becke</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Mark Diggory</a>
    *   
    * @since 2.0 
    *
  @@ -108,6 +109,21 @@
       public FilePart(String name, File file) 
       throws FileNotFoundException {
           this( name, new FilePartSource( file ) );
  +    }
  +
  +     /**
  +     * FilePart Constructor.
  +     *
  +     * @param name
  +     * @param fileName
  +     * @param file the file to post
  +     *
  +     * @throws FileNotFoundException if the <i>file</i> is not a normal
  +     * file or if it is not readable.
  +     */
  +    public FilePart(String name, String fileName, File file) 
  +    throws FileNotFoundException {
  +        this( name, new FilePartSource( fileName, file ) );
       }
       
       /**
  
  
  
  1.2       +30 -4     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java
  
  Index: FilePartSource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilePartSource.java       10 Nov 2002 08:09:53 -0000      1.1
  +++ FilePartSource.java       17 Nov 2002 03:11:27 -0000      1.2
  @@ -72,6 +72,7 @@
    * A PartSource that reads from a File.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michael Becke</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Mark Diggory</a>
    *   
    * @since 2.0 
    */
  @@ -79,6 +80,8 @@
   
       private File file;
   
  +    private String fileName = null;
  +    
       /**
        * Constructor for FilePartSource.
        * 
  @@ -100,6 +103,26 @@
       }
   
       /**
  +     * Constructor for FilePartSource.
  +     * 
  +     * @exception FileNotFoundException if the file does not exist or 
  +     * cannot be read
  +     */
  +    public FilePartSource( String fileName, File file ) throws 
FileNotFoundException {
  +        
  +        if (! file.isFile()) {
  +            throw new FileNotFoundException("File is not a normal file.");
  +        }
  +    
  +        if (! file.canRead()) {
  +            throw new FileNotFoundException("File is not readable.");
  +        }
  +        
  +        this.file = file;
  +        this.fileName = fileName;
  +    }
  +    
  +    /**
        * @see org.apache.commons.httpclient.methods.multipart.PartSource#getLength()
        */
       public long getLength() {
  @@ -110,7 +133,10 @@
        * @see org.apache.commons.httpclient.methods.multipart.PartSource#getName()
        */
       public String getFileName() {
  -        return file.getName();
  +        if(fileName == null)
  +            return file.getName();
  +        else
  +            return fileName;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to