1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.portal.cms;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.util.Map;
21
22 import javax.servlet.http.HttpServletResponse;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import nl.hippo.client.api.ClientException;
28 import nl.hippo.client.api.content.Document;
29 import nl.hippo.client.api.content.DocumentCollection;
30 import nl.hippo.client.api.content.DocumentMetadata;
31 import nl.hippo.client.api.content.DocumentPath;
32 import nl.hippo.client.api.content.FacetCollection;
33 import nl.hippo.client.api.content.Property;
34 import nl.hippo.client.api.service.WebdavService;
35 import nl.hippo.portal.util.PropertiesReplacer;
36
37 /***
38 * @version $Id: CMSServiceImpl.java 6849 2007-06-19 14:50:23Z ddam $
39 *
40 */
41 public class CMSServiceImpl implements CMSService
42 {
43 private static final Log log = LogFactory.getLog(CMSServiceImpl.class);
44
45 private String name;
46 private WebdavService webdavService;
47
48 public CMSServiceImpl(String name, WebdavService webdavService)
49 {
50 this.name = name;
51 this.webdavService = webdavService;
52 }
53
54 public Document get(String path)
55 {
56 return get(createRelativePath(path));
57 }
58
59 public Document get(DocumentPath path)
60 {
61 Document result = null;
62 try
63 {
64 result = webdavService.fetchDocument(path);
65 }
66 catch (ClientException e)
67 {
68 log.error(e);
69 }
70 return result;
71 }
72
73
74
75
76 public String getName()
77 {
78 return name;
79 }
80
81 public DocumentCollection search(String path, String daslQuery)
82 {
83 return search(createRelativePath(path), daslQuery, null, true);
84 }
85
86
87
88
89 public DocumentCollection search(String path, String daslQuery, boolean includeContent)
90 {
91 return search(createRelativePath(path), daslQuery, null, includeContent);
92 }
93
94
95
96
97 public DocumentCollection search(DocumentPath path, String daslQuery, boolean includeContent)
98 {
99 return search(path, daslQuery, null, includeContent);
100 }
101
102 public DocumentCollection search(DocumentPath path, String daslQuery)
103 {
104 return search(path, daslQuery, null, true);
105 }
106
107 public DocumentCollection search(String path, String daslQuery, Map daslParameters)
108 {
109 return search(createRelativePath(path), daslQuery, daslParameters, true);
110 }
111
112
113
114
115 public DocumentCollection search(String path, String daslQuery, Map daslParameters, boolean includeContent)
116 {
117 return search(createRelativePath(path), daslQuery, daslParameters, includeContent);
118 }
119
120 public DocumentCollection search(DocumentPath path, String daslQuery, Map daslParameters)
121 {
122 return search(path, daslQuery, daslParameters, true);
123 }
124
125
126
127
128 public DocumentCollection search(DocumentPath path, String daslQuery, Map daslParameters, boolean includeContent)
129 {
130 DocumentCollection result = null;
131 try
132 {
133 String processedQuery = processQuery(daslQuery, daslParameters);
134 result = webdavService.fetchCollection(path, processedQuery, includeContent);
135 }
136 catch (ClientException e)
137 {
138 log.error(e);
139 }
140 return result;
141 }
142
143
144 private String processQuery(String query, Map queryParameters) throws ClientException
145 {
146 String result = query;
147 if (queryParameters != null)
148 {
149 try
150 {
151 String queryString = PropertiesReplacer.replaceProperties(query, queryParameters);
152 result = queryString;
153 }
154 catch (IOException ioe)
155 {
156 throw new ClientException("Cannot parse/replace search dasl input parameters", ioe);
157 }
158 }
159 return result;
160 }
161
162 public DocumentPath createAbsolutePath(String path)
163 {
164 return webdavService.getBasePath().createAbsolutePath(path);
165 }
166
167 public DocumentPath createRelativePath(String path)
168 {
169 return webdavService.getBasePath().createRelativePath(path);
170 }
171
172
173
174
175 public Document getById(String documentId)
176 {
177 try
178 {
179 return webdavService.fetchDocumentById(documentId);
180 }
181 catch (ClientException e)
182 {
183 log.error(e);
184 }
185 return null;
186 }
187
188
189
190
191 public DocumentMetadata getMetaData(String path)
192 {
193 return getMetaData(createRelativePath(path));
194 }
195
196
197
198
199 public DocumentMetadata getMetaData(DocumentPath path)
200 {
201 try
202 {
203 return webdavService.fetchMetadata(path);
204 }
205 catch (ClientException e)
206 {
207 log.error(e);
208 }
209 return null;
210 }
211
212
213
214
215 public DocumentMetadata getMetaDataById(String documentId)
216 {
217 try
218 {
219 return webdavService.fetchMetadataById(documentId);
220 }
221 catch (ClientException e)
222 {
223 log.error(e);
224 }
225 return null;
226 }
227
228
229
230
231 public boolean isDocumentIdEnabled()
232 {
233 return webdavService.isDocumentIdEnabled();
234 }
235
236 public FacetCollection facetSearch(String path, InputStream dasl)
237 {
238 return facetSearch(createRelativePath(path), dasl);
239 }
240
241 public FacetCollection facetSearch(DocumentPath path, InputStream dasl)
242 {
243 try
244 {
245 return webdavService.fetchFacets(path, dasl);
246 }
247 catch (ClientException e)
248 {
249 log.error(e);
250 }
251 return null;
252 }
253
254 public FacetCollection facetSearch(String path, String dasl)
255 {
256 return facetSearch(createRelativePath(path), dasl);
257 }
258
259 public FacetCollection facetSearch(DocumentPath path, String dasl)
260 {
261 try
262 {
263 return webdavService.fetchFacets(path, dasl);
264 }
265 catch (ClientException e)
266 {
267 log.error(e);
268 }
269 return null;
270 }
271
272 public int put(String targetPath, InputStream putObject)
273 {
274 return put(createRelativePath(targetPath), putObject);
275 }
276
277 public int put(DocumentPath targetPath, InputStream putObject)
278 {
279 try
280 {
281 return webdavService.executePut(targetPath, putObject);
282 }
283 catch (ClientException e)
284 {
285 log.error(e);
286 }
287 return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
288 }
289
290 public int proppatch(String targetPath, Property[] propertiesToRemove, Property[] propertiesToAdd){
291 return proppatch(createAbsolutePath(targetPath), propertiesToRemove, propertiesToAdd);
292 }
293
294 public int proppatch(DocumentPath targetPath, Property[] propertiesToRemove, Property[] propertiesToAdd)
295 {
296 if (propertiesToRemove==null){
297 propertiesToRemove=new Property[0];
298 }
299 if (propertiesToAdd==null){
300 propertiesToAdd=new Property[0];
301 }
302 try
303 {
304 return webdavService.executePropPatch(targetPath, propertiesToRemove, propertiesToAdd);
305 }
306 catch (ClientException e)
307 {
308 log.error(e);
309 }
310 return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
311 }
312
313 public int delete(DocumentPath targetPath) {
314 try{
315 return webdavService.executeDelete(targetPath);
316 } catch(ClientException e)
317 {
318 log.error(e);
319 }
320
321 return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
322 }
323
324 public int makeCol(DocumentPath targetPath) {
325 try{
326 return webdavService.executeMkCol(targetPath);
327 } catch(ClientException e)
328 {
329 log.error(e);
330 }
331
332 return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
333 }
334
335
336
337 }