remm        01/02/19 22:59:44

  Modified:    src/webdav/client/src/org/apache/webdav/lib/methods
                        PostMethod.java
  Log:
  - Support for POST (experimental and untested yet).
  
  Revision  Changes    Path
  1.3       +104 -7    
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PostMethod.java
  
  Index: PostMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PostMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PostMethod.java   2000/12/11 02:06:01     1.2
  +++ PostMethod.java   2001/02/20 06:59:43     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PostMethod.java,v
 1.2 2000/12/11 02:06:01 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/12/11 02:06:01 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/PostMethod.java,v
 1.3 2001/02/20 06:59:43 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/02/20 06:59:43 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   
   import java.io.*;
   import java.util.*;
  +import java.net.URLEncoder;
   import org.apache.webdav.lib.State;
   import org.apache.webdav.lib.Header;
   import org.apache.webdav.lib.WebdavStatus;
  @@ -76,9 +77,15 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
    */
   public class PostMethod
  -    extends WebdavMethodBase {
  +    extends GetMethod {
       
       
  +    // -------------------------------------------------------------- Constants
  +    
  +    
  +    protected static final String POST = "POST";
  +    
  +    
       // ----------------------------------------------------------- Constructors
       
       
  @@ -86,7 +93,8 @@
        * Method constructor.
        */
       public PostMethod() {
  -        name = "POST";
  +        super();
  +        name = POST;
       }
       
       
  @@ -95,20 +103,109 @@
        */
       public PostMethod(String path) {
           super(path);
  -        name = "POST";
  +        name = POST;
  +    }
  +    
  +    
  +    /**
  +     * Method constructor.
  +     */
  +    public PostMethod(String path, String tempDir) {
  +        super(path, tempDir);
  +        name = POST;
       }
       
       
  +    
  +    
  +    /**
  +     * Method constructor.
  +     */
  +    public PostMethod(String path, boolean useDisk, String tempDir) {
  +        super(path, useDisk, tempDir);
  +        name = POST;
  +    }
  +    
  +    
  +    /**
  +     * Method constructor.
  +     */
  +    public PostMethod(String path, boolean useDisk, String tempDir,
  +                      String tempFile) {
  +        super(path, useDisk, tempDir, tempFile);
  +        name = POST;
  +    }
  +    
  +    
  +    // ----------------------------------------------------- Instance Variables
  +    
  +    
  +    /**
  +     * Parameters hashtable.
  +     */
  +    Hashtable parameters = new Hashtable();
  +    
  +    
  +    // --------------------------------------------------------- Public Methods
  +    
  +    
  +    /**
  +     * Add parameter.
  +     */
  +    public void addParameter(String name, String value) {
  +        checkNotUsed();
  +        parameters.put(name, value);
  +    }
  +    
  +    
       // --------------------------------------------------- WebdavMethod Methods
       
       
  +    public void recycle() {
  +        super.recycle();
  +        parameters.clear();
  +    }
  +    
  +    
  +    /**
  +     * Generate additional headers needed by the request.
  +     *
  +     * @param host the host
  +     * @param state State token
  +     */
  +    public void generateHeaders(String host, State state) {
  +        
  +        super.generateHeaders(host, state);
  +        
  +        if (!parameters.isEmpty()) {
  +            setHeader("Content-Type", "application/x-www-form-urlencoded");
  +        }
  +        
  +    }
  +    
  +    
       /**
        * Generate the query body.
        * 
        * @return String query
        */
       public String generateQuery() {
  -        return null;
  +        if (!parameters.isEmpty()) {
  +            StringBuffer sb = new StringBuffer();
  +            Enumeration names = parameters.keys();
  +            while (names.hasMoreElements()) {
  +                String name = (String) names.nextElement();
  +                String value = (String) parameters.get(name);
  +                sb.append(URLEncoder.encode(name));
  +                sb.append("=");
  +                sb.append(URLEncoder.encode(value));
  +                if (names.hasMoreElements())
  +                    sb.append("&");
  +            }
  +            return sb.toString();
  +        } else {
  +            return null;
  +        }
       }
       
       
  
  
  

Reply via email to