01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. 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,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.util;
21:
22: public class URL {
23: private int port = -1;
24: private String fileName;
25: private String host;
26: private String protocol;
27:
28: public URL(String url) {
29: int start = 0;
30: int end = 0;
31:
32: end = url.indexOf("://");
33:
34: if (end > 0) {
35: protocol = url.substring(0, end);
36: start = end + 3;
37: }
38:
39: end = url.indexOf('/', start);
40:
41: if (end > 0) {
42: String hostAndPort = url.substring(start, end);
43:
44: fileName = url.substring(end);
45:
46: int index = hostAndPort.indexOf(':');
47:
48: if (index > 0) {
49: host = hostAndPort.substring(0, index);
50: port = Integer.parseInt(hostAndPort
51: .substring(index + 1));
52: } else {
53: host = hostAndPort;
54: }
55: } else {
56: host = url;
57: }
58: }
59:
60: /**
61: * @return Returns String.
62: */
63: public String getFileName() {
64: return fileName;
65: }
66:
67: /**
68: * @return Returns String.
69: */
70: public String getHost() {
71: return host;
72: }
73:
74: /**
75: * @return Returns int.
76: */
77: public int getPort() {
78: return port;
79: }
80:
81: /**
82: * @return Returns String.
83: */
84: public String getProtocol() {
85: return protocol;
86: }
87: }
|