View Javadoc

1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/Attic/UrlGetMethod.java,v 1.12.2.1 2004/02/22 18:21:15 olegk Exp $
3    * $Revision: 1.12.2.1 $
4    * $Date: 2004/02/22 18:21:15 $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-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  
32  package org.apache.commons.httpclient.methods;
33  
34  import org.apache.commons.httpclient.HttpUrlMethod;
35  import org.apache.commons.httpclient.util.URIUtil;
36  
37  import java.io.File;
38  import java.net.MalformedURLException;
39  
40  /***
41   * Implements the URL version of GetMethod.  It serves the
42   * same purpose as GetMethod but it takes  URL instead of
43   * a path.  
44   *
45   * @deprecated use GetMethod
46   *
47   * @author Marc A. Saegesser
48   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
49   */
50  public class UrlGetMethod extends GetMethod implements HttpUrlMethod {
51      // ----------------------------------------------------- Instance Variables
52      /*** The URL */
53      private String url;
54  
55      /***
56       * No-arg constructor.
57       */
58      public UrlGetMethod() {
59          super();
60      }
61  
62      /***
63       * Create an instance with the specified URL
64       * @param url The URL
65       * @throws MalformedURLException If the url isn't valid.
66       */
67      public UrlGetMethod(String url) throws MalformedURLException {
68          super(URIUtil.getPath(url));
69          setUrl(url);
70      }
71  
72      /***
73       * Create an instance with the specified URL and temporary directory.
74       * @param url The URL
75       * @param tempDir The temporary directory
76       * @throws MalformedURLException If the url isn't valid.
77       */
78      public UrlGetMethod(String url, String tempDir) throws MalformedURLException {
79          super(URIUtil.getPath(url), tempDir);
80          setUrl(url);
81      }
82  
83      /***
84       * Constructor.
85       * @param url the path of the request
86       * @param tempDir the directory in which to store temporary files
87       * @param tempFile the file (under tempDir) to buffer contents to
88       * @throws MalformedURLException If the url isn't valid.
89       */
90      public UrlGetMethod(String url, String tempDir, String tempFile) 
91          throws MalformedURLException {
92          super(URIUtil.getPath(url), tempDir, tempFile);
93          setUrl(url);
94      }
95  
96      /***
97       * Constructor.
98       * @param url the path of the request
99       * @param fileData the file to buffer contents to
100      * @throws MalformedURLException If the url isn't valid.
101      */
102     public UrlGetMethod(String url, File fileData) 
103         throws MalformedURLException {
104         super(URIUtil.getPath(url), fileData);
105         setUrl(url);
106     }
107 
108     /***
109      * Sets the URL.  Calls the underlying HttpMethod.setPath()
110      * with the url's path.  If the url contains a query string
111      * the underlying HttpMethod.setQueryString() is called.
112      *
113      * @param url - the URL for this request.
114      * @throws MalformedURLException If the url isn't valid.
115      */
116     public void setUrl(String url) throws MalformedURLException {
117         super.setPath(URIUtil.getPath(url));
118         this.url = url;
119         String query = URIUtil.getQuery(url);
120         if (query != null && query.length() > 0) {
121             super.setQueryString(query);
122         }
123     }
124 
125     /***
126      * Returns this request's URL.
127      * 
128      * @return the request's URL.
129      */
130     public String getUrl() {
131         return url;
132     }
133 }