KickJava   Java API By Example, From Geeks To Geeks.

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


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.exolab.castor.jdo.Database;
33 import org.infoglue.cms.entities.structure.SiteNode;
34 import org.infoglue.cms.entities.structure.SiteNodeVO;
35 import org.infoglue.cms.entities.structure.SiteNodeVersion;
36 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
37 import org.infoglue.cms.exception.Bug;
38 import org.infoglue.cms.exception.ConstraintException;
39 import org.infoglue.cms.exception.SystemException;
40 import org.infoglue.cms.security.InfoGluePrincipal;
41
42
43 /**
44  * @author Mattias Bogeblad
45  */

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

97     /*
98     private void intercept(Map hashMap, String InterceptionPointName, InfoGluePrincipal infogluePrincipal, Database db) throws ConstraintException, SystemException, Bug, Exception
99     {
100         InterceptionPoint interceptionPoint = InterceptionPointController.getController().getInterceptionPointWithName(InterceptionPointName, db);
101         
102         if(interceptionPoint == null)
103             throw new SystemException("The InterceptionPoint " + InterceptionPointName + " was not found. The system will not work unless you restore it.");
104
105         List interceptors = InterceptionPointController.getController().getInterceptorsVOList(interceptionPoint.getInterceptionPointId(), db);
106         Iterator interceptorsIterator = interceptors.iterator();
107         while(interceptorsIterator.hasNext())
108         {
109             InterceptorVO interceptorVO = (InterceptorVO)interceptorsIterator.next();
110             logger.info("Adding interceptorVO:" + interceptorVO.getName());
111             try
112             {
113                 InfoGlueInterceptor infoGlueInterceptor = (InfoGlueInterceptor)Class.forName(interceptorVO.getClassName()).newInstance();
114                 infoGlueInterceptor.intercept(infogluePrincipal, interceptionPoint.getValueObject(), hashMap, db);
115             }
116             catch(ClassNotFoundException e)
117             {
118                 logger.warn("The interceptor " + interceptorVO.getClassName() + "was not found: " + e.getMessage(), e);
119             }
120         }
121     }
122     */

123     
124     /**
125      * This method returns a specific siteNodeVersion-object
126      */

127     
128     public SiteNodeVersionVO getACLatestActiveSiteNodeVersionVO(InfoGluePrincipal infogluePrincipal, Integer JavaDoc siteNodeId, Database db) throws ConstraintException, SystemException, Bug, Exception JavaDoc
129     {
130         SiteNodeVersionVO siteNodeVersionVO = getLatestActiveSiteNodeVersionVO(db, siteNodeId);
131         
132         if(siteNodeVersionVO != null)
133         {
134             Map JavaDoc hashMap = new HashMap JavaDoc();
135             hashMap.put("siteNodeVersionId", siteNodeVersionVO.getId());
136     
137             intercept(hashMap, "SiteNodeVersion.Read", infogluePrincipal, db);
138         }
139
140         return getLatestActiveSiteNodeVersionVO(db, siteNodeId);
141     }
142
143     
144     /**
145      * This method returns a specific siteNodeVersion-object
146      */

147     
148     public SiteNodeVersionVO getACLatestActiveSiteNodeVersionVO(InfoGluePrincipal infogluePrincipal, Integer JavaDoc siteNodeId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
149     {
150         SiteNodeVersionVO siteNodeVersionVO = getLatestActiveSiteNodeVersionVO(siteNodeId);
151         
152         Map JavaDoc hashMap = new HashMap JavaDoc();
153         hashMap.put("siteNodeVersionId", siteNodeVersionVO.getId());
154
155         intercept(hashMap, "SiteNodeVersion.Read", infogluePrincipal);
156         
157         return getLatestActiveSiteNodeVersionVO(siteNodeId);
158     }
159
160     
161     /**
162      * This method creates a content after first checking that the user has rights to edit it.
163      */

164 /*
165     public ContentVO acCreate(InfoGluePrincipal infogluePrincipal, Integer parentContentId, Integer contentTypeDefinitionId, Integer repositoryId, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception
166     {
167         Map hashMap = new HashMap();
168         hashMap.put("contentId", parentContentId);
169         
170         intercept(hashMap, "Content.Create", infogluePrincipal);
171
172         return ContentController.getContentController().create(parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
173     }
174 */

175     
176     /**
177      * This method updates a content after first checking that the user has rights to edit it.
178      */

179
180     public SiteNodeVersionVO acUpdate(InfoGluePrincipal infogluePrincipal, SiteNodeVersionVO siteNodeVersionVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
181     {
182         Map JavaDoc hashMap = new HashMap JavaDoc();
183         hashMap.put("siteNodeVersionId", siteNodeVersionVO.getId());
184         
185         intercept(hashMap, "SiteNodeVersion.Write", infogluePrincipal);
186
187         return update(siteNodeVersionVO);
188     }
189     
190     /**
191      * This method updates a content after first checking that the user has rights to edit it.
192      */

193
194     public SiteNodeVersionVO acUpdate(InfoGluePrincipal infogluePrincipal, SiteNodeVersionVO siteNodeVersionVO, Database db) throws ConstraintException, SystemException, Bug, Exception JavaDoc
195     {
196         Map JavaDoc hashMap = new HashMap JavaDoc();
197         hashMap.put("siteNodeVersionId", siteNodeVersionVO.getId());
198         
199         intercept(hashMap, "SiteNodeVersion.Write", infogluePrincipal, db);
200
201         return update(siteNodeVersionVO, db);
202     }
203     
204     /**
205      * This method deletes a content after first checking that the user has rights to edit it.
206      */

207     /*
208     public void acDelete(InfoGluePrincipal infogluePrincipal, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception
209     {
210         Map hashMap = new HashMap();
211         hashMap.put("contentId", contentVO.getId());
212         
213         intercept(hashMap, "Content.Delete", infogluePrincipal);
214
215         delete(contentVO);
216     }
217     */

218     
219     /**
220      * This method moves a content after first checking that the user has rights to edit it.
221      */

222     /*
223     public void acMoveContent(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer newParentContentId) throws ConstraintException, SystemException, Bug, Exception
224     {
225         Map hashMap = new HashMap();
226         hashMap.put("contentId", contentVO.getId());
227         
228         intercept(hashMap, "Content.Move", infogluePrincipal);
229         
230         hashMap = new HashMap();
231         hashMap.put("contentId", newParentContentId);
232
233         intercept(hashMap, "Content.Create", infogluePrincipal);
234
235         moveContent(contentVO, newParentContentId);
236     }
237     */

238
239     /**
240      * This method returns true if the if the siteNode in question is protected.
241      */

242
243     public Integer JavaDoc getProtectedSiteNodeVersionId(Integer JavaDoc siteNodeVersionId)
244     {
245         logger.info("siteNodeVersionId:" + siteNodeVersionId);
246         Integer JavaDoc protectedSiteNodeVersionId = null;
247         
248         try
249         {
250             SiteNodeVersionVO siteNodeVersionVO = getSiteNodeVersionVOWithId(siteNodeVersionId);
251             logger.info("Is Protected: " + siteNodeVersionVO.getIsProtected());
252             if(siteNodeVersionVO != null)
253             {
254                 if(siteNodeVersionVO.getIsProtected() != null)
255                 {
256                     if(siteNodeVersionVO.getIsProtected().intValue() == NO.intValue())
257                         protectedSiteNodeVersionId = null;
258                     else if(siteNodeVersionVO.getIsProtected().intValue() == YES.intValue())
259                         protectedSiteNodeVersionId = siteNodeVersionVO.getId();
260                     else if(siteNodeVersionVO.getIsProtected().intValue() == INHERITED.intValue())
261                     {
262                         SiteNodeVO parentSiteNodeVO = SiteNodeController.getParentSiteNode(siteNodeVersionVO.getSiteNodeId());
263                         if(parentSiteNodeVO != null)
264                         {
265                             siteNodeVersionVO = getLatestSiteNodeVersionVO(parentSiteNodeVO.getSiteNodeId());
266                             protectedSiteNodeVersionId = getProtectedSiteNodeVersionId(siteNodeVersionVO.getSiteNodeVersionId());
267                         }
268                     }
269                 }
270             }
271         }
272         catch(Exception JavaDoc e)
273         {
274             logger.warn("An error occurred trying to get if the siteNodeVersion is protected:" + e.getMessage(), e);
275         }
276             
277         return protectedSiteNodeVersionId;
278     }
279     
280     /**
281      * This method returns true if the if the siteNode in question is protected within a transaction.
282      */

283
284     public Integer JavaDoc getProtectedSiteNodeVersionId(Integer JavaDoc siteNodeVersionId, Database db)
285     {
286         logger.info("siteNodeVersionId:" + siteNodeVersionId);
287         Integer JavaDoc protectedSiteNodeVersionId = null;
288         
289         try
290         {
291             SiteNodeVersion siteNodeVersion = getSiteNodeVersionWithId(siteNodeVersionId, db);
292             logger.info("Is Protected: " + siteNodeVersion.getIsProtected());
293             if(siteNodeVersion != null)
294             {
295                 if(siteNodeVersion.getIsProtected() != null)
296                 {
297                     if(siteNodeVersion.getIsProtected().intValue() == NO.intValue())
298                         protectedSiteNodeVersionId = null;
299                     else if(siteNodeVersion.getIsProtected().intValue() == YES.intValue())
300                         protectedSiteNodeVersionId = siteNodeVersion.getId();
301                     else if(siteNodeVersion.getIsProtected().intValue() == INHERITED.intValue())
302                     {
303                         SiteNode parentSiteNode = siteNodeVersion.getOwningSiteNode().getParentSiteNode();
304                         if(parentSiteNode != null)
305                         {
306                             siteNodeVersion = getLatestSiteNodeVersion(db, parentSiteNode.getSiteNodeId(), false);
307                             protectedSiteNodeVersionId = getProtectedSiteNodeVersionId(siteNodeVersion.getSiteNodeVersionId(), db);
308                         }
309                     }
310                 }
311             }
312         }
313         catch(Exception JavaDoc e)
314         {
315             logger.warn("An error occurred trying to get if the siteNodeVersion is protected:" + e.getMessage(), e);
316         }
317             
318         return protectedSiteNodeVersionId;
319     }
320     
321     /**
322      * This method returns true if the if the siteNode in question is protected.
323      */

324
325     public boolean getIsSiteNodeVersionProtected(Integer JavaDoc siteNodeVersionId)
326     {
327         logger.info("siteNodeVersionId:" + siteNodeVersionId);
328         boolean isSiteNodeVersionProtected = false;
329     
330         try
331         {
332             SiteNodeVersionVO siteNodeVersionVO = getSiteNodeVersionVOWithId(siteNodeVersionId);
333             logger.info("Is Protected: " + siteNodeVersionVO.getIsProtected());
334             if(siteNodeVersionVO != null)
335             {
336                 if(siteNodeVersionVO.getIsProtected() != null)
337                 {
338                     if(siteNodeVersionVO.getIsProtected().intValue() == NO.intValue())
339                         isSiteNodeVersionProtected = false;
340                     else if(siteNodeVersionVO.getIsProtected().intValue() == YES.intValue())
341                         isSiteNodeVersionProtected = true;
342                     else if(siteNodeVersionVO.getIsProtected().intValue() == INHERITED.intValue())
343                     {
344                         SiteNodeVO parentSiteNodeVO = SiteNodeController.getParentSiteNode(siteNodeVersionVO.getSiteNodeId());
345                         if(parentSiteNodeVO != null)
346                         {
347                             siteNodeVersionVO = getLatestSiteNodeVersionVO(parentSiteNodeVO.getSiteNodeId());
348                             isSiteNodeVersionProtected = getIsSiteNodeVersionProtected(siteNodeVersionVO.getSiteNodeVersionId());
349                         }
350                     }
351                 }
352             }
353         }
354         catch(Exception JavaDoc e)
355         {
356             logger.warn("An error occurred trying to get if the siteNodeVersion is protected:" + e.getMessage(), e);
357         }
358             
359         return isSiteNodeVersionProtected;
360     }
361
362     /**
363      * This method returns true if the if the siteNode in question is protected.
364      */

365
366     public boolean getIsSiteNodeVersionProtected(Integer JavaDoc siteNodeVersionId, Database db)
367     {
368         logger.info("siteNodeVersionId:" + siteNodeVersionId);
369         boolean isSiteNodeVersionProtected = false;
370     
371         try
372         {
373             SiteNodeVersion siteNodeVersion = getSiteNodeVersionWithId(siteNodeVersionId, db);
374             logger.info("Is Protected: " + siteNodeVersion.getIsProtected());
375             if(siteNodeVersion != null)
376             {
377                 if(siteNodeVersion.getIsProtected() != null)
378                 {
379                     if(siteNodeVersion.getIsProtected().intValue() == NO.intValue())
380                         isSiteNodeVersionProtected = false;
381                     else if(siteNodeVersion.getIsProtected().intValue() == YES.intValue())
382                         isSiteNodeVersionProtected = true;
383                     else if(siteNodeVersion.getIsProtected().intValue() == INHERITED.intValue())
384                     {
385                         SiteNode parentSiteNode = SiteNodeController.getParentSiteNode(siteNodeVersion.getValueObject().getSiteNodeId(), db);
386                         if(parentSiteNode != null)
387                         {
388                             siteNodeVersion = getLatestSiteNodeVersion(db, parentSiteNode.getSiteNodeId(), false);
389                             isSiteNodeVersionProtected = getIsSiteNodeVersionProtected(siteNodeVersion.getSiteNodeVersionId(), db);
390                         }
391                     }
392                 }
393             }
394         }
395         catch(Exception JavaDoc e)
396         {
397             logger.warn("An error occurred trying to get if the siteNodeVersion is protected:" + e.getMessage(), e);
398         }
399             
400         return isSiteNodeVersionProtected;
401     }
402
403 }
404
Popular Tags