bernard
authored
|
1
|
package pl.itcrowd.youtrack.api;
|
bernard
authored
|
2
3
4
|
import java.net.URI;
import java.net.URISyntaxException;
|
|
5
|
import java.util.Map;
|
bernard
authored
|
6
7
8
|
public class URIUtils {
|
bernard
authored
|
9
10
|
public static URI buildURI(URI base, String path)
{
|
|
11
|
return buildURI(base, path, (String) null);
|
bernard
authored
|
12
|
}
|
bernard
authored
|
13
|
|
bernard
authored
|
14
15
16
17
18
19
20
21
|
public static URI buildURI(URI base, String path, String query)
{
try {
return new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath().replaceAll("/+$", "") + path, query,
base.getFragment());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
|
bernard
authored
|
22
|
}
|
|
23
24
25
26
27
28
29
30
31
32
33
|
public static URI buildURI(URI base, String path, Map<String, Object> params)
{
final StringBuilder query = new StringBuilder();
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (null != entry.getValue()) {
query.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
}
return buildURI(base, path, query.length() > 0 ? query.substring(1) : query.toString());
}
|
bernard
authored
|
34
|
}
|