1 /***
2 *
3 * Copyright 2004 Hiram Chirino
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.activeio.net;
18
19 import java.net.URI;
20 import java.net.URISyntaxException;
21
22 /***
23 * The URISupport class provides a few static methods that provides a few usefull
24 * operations to manipulate URIs.
25 *
26 * @version $Revision$
27 */
28 public class URISupport {
29
30 static public URI changePort(URI bindAddr, int port) throws URISyntaxException {
31 return new URI(bindAddr.getScheme(), bindAddr.getUserInfo(), bindAddr.getHost(), port, bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
32 }
33 static public URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
34 return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
35 }
36 static public URI changeUserInfo(URI bindAddr, String userInfo) throws URISyntaxException {
37 return new URI(bindAddr.getScheme(), userInfo, bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
38 }
39 static public URI changeHost(URI bindAddr, String host) throws URISyntaxException {
40 return new URI(bindAddr.getScheme(), bindAddr.getUserInfo(), host, bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
41 }
42 static public URI changePath(URI bindAddr, String path) throws URISyntaxException {
43 return new URI(bindAddr.getScheme(), bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), path, bindAddr.getQuery(), bindAddr.getFragment());
44 }
45 static public URI changeQuery(URI bindAddr, String query) throws URISyntaxException {
46 return new URI(bindAddr.getScheme(), bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), query, bindAddr.getFragment());
47 }
48 static public URI changeFragment(URI bindAddr, String fragment) throws URISyntaxException {
49 return new URI(bindAddr.getScheme(), bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), fragment);
50 }
51
52 }