This project has retired. For details please refer to its
Attic page.
RepositoryUrlCache xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.bindings.spi.browser;
20
21 import java.io.Serializable;
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.concurrent.locks.ReentrantReadWriteLock;
25
26 import org.apache.chemistry.opencmis.commons.impl.Constants;
27 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
28
29
30
31
32 public class RepositoryUrlCache implements Serializable {
33
34 public static final String OBJECT_ID = "objectId";
35
36 private static final long serialVersionUID = 1L;
37
38 private final Map<String, String> repositoryUrls;
39 private final Map<String, String> rootUrls;
40
41 private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
42
43 public RepositoryUrlCache() {
44 repositoryUrls = new HashMap<String, String>();
45 rootUrls = new HashMap<String, String>();
46 }
47
48
49
50
51 public void addRepository(String repositoryId, String repositoryUrl, String rootUrl) {
52 if (repositoryId == null || repositoryUrl == null || rootUrl == null) {
53 throw new IllegalArgumentException("Repository Id or Repository URL or Root URL is not set!");
54 }
55
56 lock.writeLock().lock();
57 try {
58 repositoryUrls.put(repositoryId, repositoryUrl);
59 rootUrls.put(repositoryId, rootUrl);
60 } finally {
61 lock.writeLock().unlock();
62 }
63 }
64
65
66
67
68 public void removeRepository(String repositoryId) {
69 lock.writeLock().lock();
70 try {
71 repositoryUrls.remove(repositoryId);
72 rootUrls.remove(repositoryId);
73 } finally {
74 lock.writeLock().unlock();
75 }
76 }
77
78
79
80
81 public String getRepositoryBaseUrl(String repositoryId) {
82 lock.readLock().lock();
83 try {
84 return repositoryUrls.get(repositoryId);
85 } finally {
86 lock.readLock().unlock();
87 }
88 }
89
90
91
92
93 public String getRootUrl(String repositoryId) {
94 lock.readLock().lock();
95 try {
96 return rootUrls.get(repositoryId);
97 } finally {
98 lock.readLock().unlock();
99 }
100 }
101
102
103
104
105 public UrlBuilder getRepositoryUrl(String repositoryId) {
106 String base = getRepositoryBaseUrl(repositoryId);
107 if (base == null) {
108 return null;
109 }
110
111 return new UrlBuilder(base);
112 }
113
114
115
116
117 public UrlBuilder getRepositoryUrl(String repositoryId, String selector) {
118 UrlBuilder result = getRepositoryUrl(repositoryId);
119 if (result == null) {
120 return null;
121 }
122
123 result.addParameter(Constants.PARAM_SELECTOR, selector);
124
125 return result;
126 }
127
128
129
130
131 public UrlBuilder getObjectUrl(String repositoryId, String objectId) {
132 String root = getRootUrl(repositoryId);
133 if (root == null) {
134 return null;
135 }
136
137 UrlBuilder result = new UrlBuilder(root);
138 result.addParameter(OBJECT_ID, objectId);
139
140 return result;
141 }
142
143
144
145
146 public UrlBuilder getObjectUrl(String repositoryId, String objectId, String selector) {
147 UrlBuilder result = getObjectUrl(repositoryId, objectId);
148 if (result == null) {
149 return null;
150 }
151
152 result.addParameter(Constants.PARAM_SELECTOR, selector);
153
154 return result;
155 }
156
157
158
159
160 public UrlBuilder getPathUrl(String repositoryId, String path) {
161 String root = getRootUrl(repositoryId);
162 if (root == null) {
163 return null;
164 }
165
166 UrlBuilder result = new UrlBuilder(root);
167 result.addPath(path);
168
169 return result;
170 }
171
172
173
174
175 public UrlBuilder getPathUrl(String repositoryId, String path, String selector) {
176 UrlBuilder result = getPathUrl(repositoryId, path);
177 if (result == null) {
178 return null;
179 }
180
181 result.addParameter(Constants.PARAM_SELECTOR, selector);
182
183 return result;
184 }
185 }