01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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;
23:
24: /**
25: * Various utility methods for URL manipulation.
26: *
27: * @version $Id: UrlUtil.java 238991 2004-05-22 11:34:50Z vmassol $
28: */
29: public class UrlUtil {
30: /**
31: * Returns the path part of the URL. This method is needed for
32: * JDK 1.2 support as <code>URL.getPath()</code> does not exist in
33: * JDK 1.2 (only for JDK 1.3+).
34: *
35: * @param theURL the URL from which to extract the path
36: * @return the path part of the URL
37: */
38: public static String getPath(URL theURL) {
39: String file = theURL.getFile();
40: String path = null;
41:
42: if (file != null) {
43: int q = file.lastIndexOf('?');
44:
45: if (q != -1) {
46: path = file.substring(0, q);
47: } else {
48: path = file;
49: }
50: }
51:
52: return path;
53: }
54:
55: /**
56: * Returns the query string of the URL. This method is needed for
57: * JDK 1.2 support as <code>URL.getQuery()</code> does not exist in
58: * JDK 1.2 (only for JDK 1.3+).
59: *
60: * @param theURL the URL from which to extract the query string
61: * @return the query string portion of the URL
62: */
63: public static String getQuery(URL theURL) {
64: String file = theURL.getFile();
65: String query = null;
66:
67: if (file != null) {
68: int q = file.lastIndexOf('?');
69:
70: if (q != -1) {
71: query = file.substring(q + 1);
72: } else {
73: query = "";
74: }
75: }
76:
77: return query;
78: }
79: }
|