commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marcs...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient URIUtil.java
Date Fri, 12 Apr 2002 21:15:52 GMT
marcsaeg    02/04/12 14:15:52

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        URIUtil.java
  Log:
  Added getPath() and getQueryString() to avoid dependencies on JDK 1.3.
  
  Revision  Changes    Path
  1.7       +58 -9     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java
  
  Index: URIUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- URIUtil.java	22 Feb 2002 19:21:11 -0000	1.6
  +++ URIUtil.java	12 Apr 2002 21:15:52 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v
1.6 2002/02/22 19:21:11 marcsaeg Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/02/22 19:21:11 $
  + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v
1.7 2002/04/12 21:15:52 marcsaeg Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/04/12 21:15:52 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -85,7 +85,7 @@
    * @author Remy Maucherat
    * @author Park, Sung-Gu
    * @author Rodney Waldhoff
  - * @version $Revision: 1.6 $ $Date: 2002/02/22 19:21:11 $
  + * @version $Revision: 1.7 $ $Date: 2002/04/12 21:15:52 $
    */
   
   public class URIUtil {
  @@ -538,15 +538,64 @@
   
   
       /**
  +     * Returns the path portion of the given URL.  If the URL contains an
  +     * empty path (e.g. http://www.serverl.com) this method returns "/".
  +     * This method exists
  +     * in URIUtil to provide support for JDK versions prior to 1.3 when
  +     * java.net.URI.getPath() was added.
  +     *
  +     * @param url - the URL
  +     * @return the path portion of the URL or "/" if the URL contains an empty path
  +     */
  +    public static final String getPath(String url){
  +        String path = null;
  +
  +        int startIndex = url.indexOf("//");
  +        if(startIndex >= 0){
  +            startIndex += 2;
  +        }
  +        startIndex = url.indexOf("/", startIndex);
  +
  +        if(startIndex >= 0){
  +            int endIndex = url.lastIndexOf("#");
  +            if(endIndex < 0){
  +                endIndex = url.lastIndexOf("?");
  +            }
  +
  +            if(endIndex < 0){
  +                path = url.substring(startIndex);
  +            }else{
  +                path = url.substring(startIndex, endIndex);
  +            }
  +
  +        }
  +
  +        if(path == null || path.length() == 0){
  +            path = "/";
  +        }
  +
  +        return path;
  +    }
  +
  +    /**
  +     * Returns the query string for the given URL.  If the URL does
  +     * not contain a query string this method turns null.
  +     * This method exists in URIUtil to provide support for JDK versions 
  +     * prior to 1.3 when java.net.URL.getQueryString() was added.
        *
  +     * @param url - the URL
  +     * @return the query string portion of the URL or null if the URL doesn't contain a
query string
        */
  -    public static final String getPath(String url) throws java.net.MalformedURLException
  +    public static final String getQueryString(String url)
       {
  -        String path = new java.net.URL(url).getPath();
  -        if(path.length() == 0){
  -            path = "/";
  +        String query = null;
  +
  +        int index = url.lastIndexOf("?");
  +        if(index >= 0){
  +            query = url.substring(index+1);
           }
  -        return path;
  +
  +        return query;
       }
   
       // ------------------------------- RFC 2396 Character Sets : Public Methods
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message