01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.repository.commonimpl;
17:
18: import org.outerj.daisy.repository.CollectionManager;
19: import org.outerj.daisy.repository.DocumentCollection;
20: import org.outerj.daisy.repository.DocumentCollections;
21: import org.outerj.daisy.repository.RepositoryException;
22:
23: import java.util.regex.Pattern;
24: import java.util.regex.Matcher;
25:
26: public class CollectionManagerImpl implements CollectionManager {
27: private CommonCollectionManager delegate;
28: private AuthenticatedUser user;
29: private static final Pattern ALL_DIGITS = Pattern
30: .compile("^[0-9]+$");
31:
32: public CollectionManagerImpl(CommonCollectionManager delegate,
33: AuthenticatedUser user) {
34: this .delegate = delegate;
35: this .user = user;
36: }
37:
38: public DocumentCollection createCollection(String name)
39: throws RepositoryException {
40: return delegate.createCollection(name, user);
41: }
42:
43: public DocumentCollection getCollection(long collectionId,
44: boolean updateable) throws RepositoryException {
45: return delegate.getCollection(collectionId, updateable, user);
46: }
47:
48: public DocumentCollection getCollection(String collection,
49: boolean updateable) throws RepositoryException {
50: if (collection == null)
51: throw new IllegalArgumentException(
52: "collection param can not be null");
53: if (collection.length() == 0)
54: throw new IllegalArgumentException(
55: "collection param cannot be an empty string");
56:
57: Matcher allDigitsMatcher = ALL_DIGITS.matcher(collection);
58: if (allDigitsMatcher.matches()) {
59: long id = Long.parseLong(collection);
60: return getCollection(id, updateable);
61: } else {
62: return getCollectionByName(collection, updateable);
63: }
64: }
65:
66: public DocumentCollection getCollectionByName(String name,
67: boolean updateable) throws RepositoryException {
68: return delegate.getCollectionByName(name, updateable, user);
69: }
70:
71: public DocumentCollections getCollections(boolean updateable)
72: throws RepositoryException {
73: return delegate.getCollections(updateable, user);
74: }
75:
76: public void deleteCollection(long collectionId)
77: throws RepositoryException {
78: delegate.deleteCollection(collectionId, user);
79: }
80:
81: }
|