1 package com.atlassian.plugins.rest.module;
2
3 import com.google.common.base.Preconditions;
4 import org.apache.commons.lang.StringUtils;
5
6 import java.util.Set;
7
8 public class RestApiContext
9 {
10 public static final String SLASH = "/";
11
12 public final static String LATEST = SLASH + "latest";
13
14 public final static String ANY_PATH_PATTERN = "/*";
15
16 private final String restContext;
17 private final String apiPath;
18 private final ApiVersion version;
19 private final Set<String> packages;
20
21 public RestApiContext(String restContext, String apiContext, ApiVersion version, Set<String> packages)
22 {
23 this.restContext = prependSlash(Preconditions.checkNotNull(restContext));
24 this.apiPath = prependSlash(Preconditions.checkNotNull(apiContext));
25 this.version = Preconditions.checkNotNull(version);
26 this.packages = Preconditions.checkNotNull(packages);
27 }
28
29
30
31
32 public String getRestContext()
33 {
34 return restContext;
35 }
36
37
38
39
40 public String getApiPath()
41 {
42 return apiPath;
43 }
44
45
46
47
48 public ApiVersion getVersion()
49 {
50 return version;
51 }
52
53 public String getPathToVersion()
54 {
55 return getPathToVersion(SLASH + version);
56 }
57
58 public String getPathToLatest()
59 {
60 return getPathToVersion(LATEST);
61 }
62
63 public String getPathToVersion(String version)
64 {
65 return restContext + apiPath + version;
66 }
67
68 private String prependSlash(String path)
69 {
70 return StringUtils.startsWith(path, SLASH) ? path : SLASH + path;
71 }
72
73 public Set<String> getPackages()
74 {
75 return packages;
76 }
77 }