KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > serverimpl > LocalCommonRepository


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.serverimpl;
17
18 import org.outerj.daisy.repository.commonimpl.*;
19 import org.outerj.daisy.repository.commonimpl.comment.CommentStrategy;
20 import org.outerj.daisy.repository.commonimpl.variant.VariantStrategy;
21 import org.outerj.daisy.repository.commonimpl.acl.AclStrategy;
22 import org.outerj.daisy.repository.commonimpl.schema.SchemaStrategy;
23 import org.outerj.daisy.repository.commonimpl.user.UserManagementStrategy;
24 import org.outerj.daisy.repository.RepositoryException;
25 import org.outerj.daisy.repository.DocumentReadDeniedException;
26 import org.outerj.daisy.repository.AvailableVariants;
27 import org.outerj.daisy.repository.Document;
28 import org.outerj.daisy.repository.serverimpl.query.LocalQueryManager;
29 import org.outerj.daisy.repository.query.QueryManager;
30 import org.outerj.daisy.repository.acl.AclResultInfo;
31 import org.outerj.daisy.repository.acl.AclPermission;
32 import org.outerj.daisy.cache.DocumentCache;
33 import org.outerj.daisy.jdbcutil.JdbcHelper;
34 import org.apache.avalon.framework.logger.Logger;
35
36 import java.util.Map JavaDoc;
37
38 /**
39  * Extended version of CommonRepository that supports document caching.
40  */

41 public class LocalCommonRepository extends CommonRepository {
42     private DocumentCache cache;
43     private AuthenticatedUser systemUser;
44     private Logger logger;
45     private LocalRepositoryManager.Context context;
46     private JdbcHelper jdbcHelper;
47
48     public LocalCommonRepository(DocumentStrategy documentStrategy, SchemaStrategy schemaStrategy,
49             AclStrategy aclStrategy, UserManagementStrategy userManagementStrategy, VariantStrategy variantStrategy,
50             CollectionStrategy collectionStrategy, CommentStrategy commentStrategy,
51             LocalRepositoryManager.Context context, Logger logger, AuthenticatedUser systemUser, DocumentCache cache,
52             Map JavaDoc extensions, JdbcHelper jdbcHelper) {
53         super(documentStrategy, schemaStrategy, aclStrategy, userManagementStrategy, variantStrategy,
54                 collectionStrategy, commentStrategy, extensions, systemUser);
55
56         this.context = context;
57         this.logger = logger;
58         this.cache = cache;
59         this.systemUser = systemUser;
60         this.jdbcHelper = jdbcHelper;
61     }
62
63     public QueryManager getQueryManager(AuthenticatedUser user) {
64         return new LocalQueryManager(context, user, systemUser, logger, jdbcHelper);
65     }
66
67     public Document getDocument(long documentId, long branchId, long languageId, boolean updateable, AuthenticatedUser user) throws RepositoryException {
68         if (updateable)
69             return super.getDocument(documentId, branchId, languageId, updateable, user);
70         else {
71             Document document = cache.get(documentId, branchId, languageId);
72
73             if (document == null) {
74                 document = super.getDocument(documentId, branchId, languageId, updateable, systemUser);
75                 cache.put(documentId, branchId, languageId, (DocumentImpl)document);
76             }
77
78             AclResultInfo aclInfo = getAccessManager().getAclInfoOnLive(systemUser, user.getId(), user.getActiveRoleIds(), document);
79             if (!aclInfo.isAllowed(AclPermission.READ)) {
80                 if (aclInfo.isAllowed(AclPermission.READ_LIVE)) {
81                     return new ReadLiveOnlyDocument(((DocumentWrapper)document).getWrappedDocument(documentStrategy), documentStrategy);
82                 } else {
83                     throw new DocumentReadDeniedException(documentId, user.getLogin(), user.getId());
84                 }
85             }
86
87             return document;
88         }
89     }
90
91     public AvailableVariants getAvailableVariants(long documentId, AuthenticatedUser user) throws RepositoryException {
92         AvailableVariants availableVariants = cache.getAvailableVariants(documentId);
93         if (availableVariants == null) {
94             availableVariants = super.getAvailableVariants(documentId, user);
95             cache.put(documentId, availableVariants);
96         }
97         return availableVariants;
98     }
99 }
100
Popular Tags