KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > util > URL


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

18 package org.apache.axis2.util;
19
20 public class URL {
21     private String JavaDoc protocol;
22     private String JavaDoc host;
23     private int port = -1;
24     private String JavaDoc fileName;
25     
26     public URL(String JavaDoc url){
27         int start = 0;
28         int end = 0;
29         end = url.indexOf("://");
30         if(end > 0){
31             protocol = url.substring(0,end);
32             start = end + 3;
33         }
34         
35         end = url.indexOf('/',start);
36         if(end > 0){
37             String JavaDoc hostAndPort = url.substring(start,end);
38             fileName = url.substring(end);
39             int index = hostAndPort.indexOf(':');
40             if(index>0){
41                 host = hostAndPort.substring(0,index);
42                 port = Integer.parseInt(hostAndPort.substring(index+1));
43             }else{
44                 host = hostAndPort;
45             }
46         }else{
47             host = url;
48         }
49          
50         
51     }
52     /**
53      * @return
54      */

55     public String JavaDoc getFileName() {
56         return fileName;
57     }
58
59     /**
60      * @return
61      */

62     public String JavaDoc getHost() {
63         return host;
64     }
65
66     /**
67      * @return
68      */

69     public int getPort() {
70         return port;
71     }
72
73     /**
74      * @return
75      */

76     public String JavaDoc getProtocol() {
77         return protocol;
78     }
79
80 }
81
Popular Tags