KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > util > UrlUtil


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.internal.util;
21
22 import java.net.URL JavaDoc;
23
24 /**
25  * Various utility methods for URL manipulation.
26  *
27  * @version $Id: UrlUtil.java,v 1.1 2004/05/22 11:34:48 vmassol Exp $
28  */

29 public class UrlUtil
30 {
31     /**
32      * Returns the path part of the URL. This method is needed for
33      * JDK 1.2 support as <code>URL.getPath()</code> does not exist in
34      * JDK 1.2 (only for JDK 1.3+).
35      *
36      * @param theURL the URL from which to extract the path
37      * @return the path part of the URL
38      */

39     public static String JavaDoc getPath(URL JavaDoc theURL)
40     {
41         String JavaDoc file = theURL.getFile();
42         String JavaDoc path = null;
43
44         if (file != null)
45         {
46             int q = file.lastIndexOf('?');
47
48             if (q != -1)
49             {
50                 path = file.substring(0, q);
51             }
52             else
53             {
54                 path = file;
55             }
56         }
57
58         return path;
59     }
60
61     /**
62      * Returns the query string of the URL. This method is needed for
63      * JDK 1.2 support as <code>URL.getQuery()</code> does not exist in
64      * JDK 1.2 (only for JDK 1.3+).
65      *
66      * @param theURL the URL from which to extract the query string
67      * @return the query string portion of the URL
68      */

69     public static String JavaDoc getQuery(URL JavaDoc theURL)
70     {
71         String JavaDoc file = theURL.getFile();
72         String JavaDoc query = null;
73
74         if (file != null)
75         {
76             int q = file.lastIndexOf('?');
77
78             if (q != -1)
79             {
80                 query = file.substring(q + 1);
81             }
82             else
83             {
84                 query = "";
85             }
86         }
87
88         return query;
89     }
90 }
91
Popular Tags