KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > http > LightweightURL


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: LightweightURL.java,v 1.3 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.http;
21
22 import java.io.*;
23 import java.util.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27
28 /**
29  * A lightweight URL class
30  */

31 public class LightweightURL {
32     String JavaDoc url = null;
33     String JavaDoc base = null;
34     String JavaDoc param = null;
35
36     /**
37      * Create a lightweight url
38      *
39      * @param iurl a URL string
40      */

41     public LightweightURL(String JavaDoc iurl) {
42         url = iurl;
43     }
44
45     /**
46      * Return the whole URL string
47      * (ie. "http://foo.com?foo1=blah1&foo2=blah2")
48      */

49     public String JavaDoc getURLStr() {
50         if (url==null) return "";
51         return url;
52     }
53
54     /**
55      * Return the base part of the URL (everything up to the ?)
56      * (ie. "http://foo.com")
57      */

58     public String JavaDoc getBaseStr() {
59         if (url==null) return "";
60         if (base==null) {
61             int epos = url.indexOf("?");
62             if (epos>-1) base = url.substring(0,epos);
63             else base = url;
64         }
65         return base;
66     }
67
68     /**
69      * Return the whole URL string (from the ? to the end)
70      * (ie. "?foo1=blah1&foo2=blah2")
71      */

72     public String JavaDoc getParamStr() {
73         if (url==null) return "";
74         if (param==null) {
75             int spos = url.indexOf("?");
76             if (spos>-1) param = url.substring(spos);
77             else param = "";
78         }
79         return param;
80     }
81     
82     /**
83      * Return a String representation of the URL
84      */

85     public String JavaDoc toString() {
86         return url;
87     }
88 }
89
Popular Tags