1 package org.apache.archiva.model;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 * RepositoryURL - Mutable (and protocol forgiving) URL object.
27 public class RepositoryURL
31 private String protocol;
37 private String username;
39 private String password;
43 public RepositoryURL( String url )
47 // .\ Parse the URL \.____________________________________________
51 pos = url.indexOf( ":/" );
54 throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
57 protocol = url.substring( 0, pos );
59 // Determine the post protocol position.
60 int postProtocolPos = protocol.length() + 1;
61 while ( url.charAt( postProtocolPos ) == '/' )
66 // Handle special case with file protocol (which has no host, port, username, or password)
67 if ( "file".equals( protocol ) )
69 path = "/" + url.substring( postProtocolPos );
74 // attempt to find the start of the 'path'
75 pos = url.indexOf( "/", postProtocolPos );
77 // no path specified - ex "http://localhost"
80 // set pos to end of string. (needed for 'middle section')
88 path = url.substring( pos );
91 // get the middle section ( username : password @ hostname : port )
92 String middle = url.substring( postProtocolPos, pos );
94 pos = middle.indexOf( '@' );
96 // we have an authentication section.
99 String authentication = middle.substring( 0, pos );
100 middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
102 pos = authentication.indexOf( ':' );
104 // we have a password.
107 username = authentication.substring( 0, pos );
108 password = authentication.substring( pos + 1 );
112 username = authentication;
116 pos = middle.indexOf( ':' );
118 // we have a defined port
121 host = middle.substring( 0, pos );
122 port = middle.substring( pos + 1 );
130 public String toString()
135 public String getUsername()
140 public String getPassword()
145 public String getHost()
150 public String getPath()
155 public String getPort()
160 public String getProtocol()
165 public String getUrl()