This project has retired. For details please refer to its
Attic page.
RepositoryURL xref
1 package org.apache.archiva.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class RepositoryURL
28 {
29 private String url;
30
31 private String protocol;
32
33 private String host;
34
35 private String port;
36
37 private String username;
38
39 private String password;
40
41 private String path;
42
43 public RepositoryURL( String url )
44 {
45 this.url = url;
46
47
48
49 int pos;
50
51 pos = url.indexOf( ":/" );
52 if ( pos == ( -1 ) )
53 {
54 throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
55 }
56
57 protocol = url.substring( 0, pos );
58
59
60 int postProtocolPos = protocol.length() + 1;
61 while ( url.charAt( postProtocolPos ) == '/' )
62 {
63 postProtocolPos++;
64 }
65
66
67 if ( "file".equals( protocol ) )
68 {
69 path = "/" + url.substring( postProtocolPos );
70
71 return;
72 }
73
74
75 pos = url.indexOf( '/', postProtocolPos );
76
77
78 if ( pos == ( -1 ) )
79 {
80
81 pos = url.length();
82
83 path = "/";
84 }
85 else
86 {
87
88 path = url.substring( pos );
89 }
90
91
92 String middle = url.substring( postProtocolPos, pos );
93
94 pos = middle.indexOf( '@' );
95
96
97 if ( pos > 0 )
98 {
99 String authentication = middle.substring( 0, pos );
100 middle = middle.substring( pos + 1 );
101
102 pos = authentication.indexOf( ':' );
103
104
105 if ( pos > 0 )
106 {
107 username = authentication.substring( 0, pos );
108 password = authentication.substring( pos + 1 );
109 }
110 else
111 {
112 username = authentication;
113 }
114 }
115
116 pos = middle.indexOf( ':' );
117
118
119 if ( pos > 0 )
120 {
121 host = middle.substring( 0, pos );
122 port = middle.substring( pos + 1 );
123 }
124 else
125 {
126 host = middle;
127 }
128 }
129
130 @Override
131 public String toString()
132 {
133 return url;
134 }
135
136 public String getUsername()
137 {
138 return username;
139 }
140
141 public String getPassword()
142 {
143 return password;
144 }
145
146 public String getHost()
147 {
148 return host;
149 }
150
151 public String getPath()
152 {
153 return path;
154 }
155
156 public String getPort()
157 {
158 return port;
159 }
160
161 public String getProtocol()
162 {
163 return protocol;
164 }
165
166 public String getUrl()
167 {
168 return url;
169 }
170 }