KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > ContentVersionControllerProxy


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.controllers.kernel.impl.simple;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.apache.log4j.Logger;
32 import org.infoglue.cms.entities.content.ContentVO;
33 import org.infoglue.cms.entities.content.ContentVersionVO;
34 import org.infoglue.cms.exception.Bug;
35 import org.infoglue.cms.exception.ConstraintException;
36 import org.infoglue.cms.exception.SystemException;
37 import org.infoglue.cms.security.InfoGluePrincipal;
38
39
40 /**
41  * @author Mattias Bogeblad
42  */

43
44 public class ContentVersionControllerProxy extends ContentVersionController
45 {
46     private final static Logger logger = Logger.getLogger(ContentVersionControllerProxy.class.getName());
47
48     protected static final Integer JavaDoc NO = new Integer JavaDoc(0);
49     protected static final Integer JavaDoc YES = new Integer JavaDoc(1);
50     protected static final Integer JavaDoc INHERITED = new Integer JavaDoc(2);
51
52     private static List JavaDoc interceptors = new ArrayList JavaDoc();
53
54     public static ContentVersionControllerProxy getController()
55     {
56         return new ContentVersionControllerProxy();
57     }
58     
59     /*
60     private void intercept(Map hashMap, String InterceptionPointName, InfoGluePrincipal infogluePrincipal) throws ConstraintException, SystemException, Bug, Exception
61     {
62         InterceptionPointVO interceptionPointVO = InterceptionPointController.getController().getInterceptionPointVOWithName(InterceptionPointName);
63         
64         if(interceptionPointVO == null)
65             throw new SystemException("The InterceptionPoint " + InterceptionPointName + " was not found. The system will not work unless you restore it.");
66
67         List interceptors = InterceptionPointController.getController().getInterceptorsVOList(interceptionPointVO.getInterceptionPointId());
68         Iterator interceptorsIterator = interceptors.iterator();
69         while(interceptorsIterator.hasNext())
70         {
71             InterceptorVO interceptorVO = (InterceptorVO)interceptorsIterator.next();
72             logger.info("Adding interceptorVO:" + interceptorVO.getName());
73             try
74             {
75                 InfoGlueInterceptor infoGlueInterceptor = (InfoGlueInterceptor)Class.forName(interceptorVO.getClassName()).newInstance();
76                 infoGlueInterceptor.intercept(infogluePrincipal, interceptionPointVO, hashMap);
77             }
78             catch(ClassNotFoundException e)
79             {
80                 logger.warn("The interceptor " + interceptorVO.getClassName() + "was not found: " + e.getMessage(), e);
81             }
82         }
83
84     }
85     */

86
87     /**
88      * This method returns a specific content-object after checking that it is accessable by the given user
89      */

90     
91     public ContentVersionVO getACContentVersionVOWithId(InfoGluePrincipal infogluePrincipal, Integer JavaDoc contentVersionId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
92     {
93         Map JavaDoc hashMap = new HashMap JavaDoc();
94         hashMap.put("contentVersionId", contentVersionId);
95         
96         intercept(hashMap, "ContentVersion.Read", infogluePrincipal);
97         
98         return getContentVersionVOWithId(contentVersionId);
99     }
100
101     /**
102      * This method returns a specific content-object after checking that it is accessable by the given user
103      */

104
105     public ContentVersionVO getACLatestActiveContentVersionVO(InfoGluePrincipal infogluePrincipal, Integer JavaDoc contentId, Integer JavaDoc languageId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
106     {
107         Map JavaDoc hashMap = new HashMap JavaDoc();
108         hashMap.put("contentId", contentId);
109         hashMap.put("languageId", languageId);
110     
111         intercept(hashMap, "ContentVersion.Read", infogluePrincipal);
112             
113         return ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
114     }
115
116     
117     
118     
119     /**
120      * This method creates a contentVersion after first checking that the user has rights to edit it.
121      */

122
123     public ContentVersionVO acCreate(InfoGluePrincipal infogluePrincipal, Integer JavaDoc contentId, Integer JavaDoc languageId, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
124     {
125         Map JavaDoc hashMap = new HashMap JavaDoc();
126         hashMap.put("contentId", contentId);
127         
128         intercept(hashMap, "Content.CreateVersion", infogluePrincipal);
129
130         return ContentVersionController.getContentVersionController().create(contentId, languageId, contentVersionVO, null);
131     }
132
133     /**
134      * This method updates a content after first checking that the user has rights to edit it.
135      */

136
137     public ContentVersionVO acUpdate(InfoGluePrincipal infogluePrincipal, Integer JavaDoc contentId, Integer JavaDoc languageId, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
138     {
139         logger.info("contentId:" + contentId);
140         logger.info("languageId:" + languageId);
141         logger.info("contentVersionId:" + contentVersionVO.getId());
142         
143         if(contentVersionVO.getId() != null)
144         {
145             Map JavaDoc hashMap = new HashMap JavaDoc();
146             hashMap.put("contentVersionId", contentVersionVO.getId());
147         
148             intercept(hashMap, "ContentVersion.Write", infogluePrincipal);
149         }
150         else
151         {
152             Map JavaDoc hashMap = new HashMap JavaDoc();
153             hashMap.put("contentId", contentId);
154
155             intercept(hashMap, "Content.CreateVersion", infogluePrincipal);
156         }
157         
158         return ContentVersionController.getContentVersionController().update(contentId, languageId, contentVersionVO);
159     }
160     
161     /**
162      * This method deletes a content after first checking that the user has rights to edit it.
163      */

164
165     public void acDelete(InfoGluePrincipal infogluePrincipal, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
166     {
167         Map JavaDoc hashMap = new HashMap JavaDoc();
168         hashMap.put("contentVersionId", contentVersionVO.getId());
169         
170         intercept(hashMap, "ContentVersion.Delete", infogluePrincipal);
171
172         ContentVersionController.getContentVersionController().delete(contentVersionVO);
173     }
174     
175     
176     /**
177      * This method returns true if the if the content in question is protected.
178      */

179
180     public boolean getIsContentProtected(Integer JavaDoc contentId, boolean inherit)
181     {
182         boolean isContentProtected = false;
183         
184         logger.info("getIsContentProtected contentId:" + contentId);
185         try
186         {
187             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId);
188             if(contentVO.getIsProtected() != null)
189             {
190                 if(contentVO.getIsProtected().intValue() == NO.intValue())
191                     isContentProtected = false;
192                 else if(contentVO.getIsProtected().intValue() == YES.intValue())
193                     isContentProtected = true;
194                 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue())
195                 {
196                     if(inherit)
197                     {
198                         ContentVO parentContentVO = ContentController.getParentContent(contentId);
199                         if(parentContentVO != null)
200                             isContentProtected = getIsContentProtected(parentContentVO.getId(), inherit);
201                     }
202                 }
203             }
204
205         }
206         catch(Exception JavaDoc e)
207         {
208             logger.warn("An error occurred trying to get if the content was protected:" + e.getMessage(), e);
209         }
210         
211         logger.info("isContentProtected:" + isContentProtected);
212         
213         return isContentProtected;
214     }
215  
216 }
217
Popular Tags