KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.exolab.castor.jdo.Database;
34 import org.infoglue.cms.applications.contenttool.wizards.actions.CreateContentWizardInfoBean;
35 import org.infoglue.cms.entities.content.ContentVO;
36 import org.infoglue.cms.exception.Bug;
37 import org.infoglue.cms.exception.ConstraintException;
38 import org.infoglue.cms.exception.SystemException;
39 import org.infoglue.cms.security.InfoGluePrincipal;
40
41
42 /**
43  * @author Mattias Bogeblad
44  */

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

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

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

105     
106     public ContentVO getACContentVOWithId(InfoGluePrincipal infogluePrincipal, Integer JavaDoc contentId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
107     {
108         Map JavaDoc hashMap = new HashMap JavaDoc();
109         hashMap.put("contentId", contentId);
110         
111         intercept(hashMap, "Content.Read", infogluePrincipal);
112                 
113         return getContentVOWithId(contentId);
114     }
115     
116     /**
117      * This method returns a list of content-objects after checking that it is accessable by the given user
118      */

119         
120     public List JavaDoc getACContentVOList(InfoGluePrincipal infoGluePrincipal, HashMap JavaDoc argumentHashMap, Database db) throws SystemException, Bug
121     {
122         List JavaDoc contents = null;
123         
124         String JavaDoc method = (String JavaDoc)argumentHashMap.get("method");
125         logger.info("method:" + method);
126         
127         if(method.equalsIgnoreCase("selectContentListOnIdList"))
128         {
129             contents = new ArrayList JavaDoc();
130             List JavaDoc arguments = (List JavaDoc)argumentHashMap.get("arguments");
131             logger.info("Arguments:" + arguments.size());
132             Iterator JavaDoc argumentIterator = arguments.iterator();
133             while(argumentIterator.hasNext())
134             {
135                 HashMap JavaDoc argument = (HashMap JavaDoc)argumentIterator.next();
136                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)argument.get("contentId"));
137                 logger.info("Getting the content with Id:" + contentId);
138                 try
139                 {
140                     contents.add(this.getACContentVOWithId(infoGluePrincipal, contentId, db));
141                 }
142                 catch(Exception JavaDoc e)
143                 {
144                     //TODO - remove later
145
e.printStackTrace();
146                 }
147             }
148         }
149         else if(method.equalsIgnoreCase("selectListOnContentTypeName"))
150         {
151             List JavaDoc arguments = (List JavaDoc)argumentHashMap.get("arguments");
152             logger.info("Arguments:" + arguments.size());
153             contents = getContentVOListByContentTypeNames(arguments);
154             Iterator JavaDoc contentIterator = contents.iterator();
155             while(contentIterator.hasNext())
156             {
157                 ContentVO candidateContentVO = (ContentVO)contentIterator.next();
158                 
159                 Map JavaDoc hashMap = new HashMap JavaDoc();
160                 hashMap.put("contentId", candidateContentVO.getContentId());
161                 
162                 try
163                 {
164                     intercept(hashMap, "Content.Read", infoGluePrincipal);
165                 }
166                 catch(Exception JavaDoc e)
167                 {
168                     logger.info("Was not authorized to look at task...");
169                     contentIterator.remove();
170                 }
171             }
172         }
173         return contents;
174     }
175
176     
177     /**
178      * This method returns a list of content-objects after checking that it is accessable by the given user
179      */

180         
181     public List JavaDoc getACContentVOList(InfoGluePrincipal infoGluePrincipal, HashMap JavaDoc argumentHashMap) throws SystemException, Bug
182     {
183         List JavaDoc contents = null;
184         
185         String JavaDoc method = (String JavaDoc)argumentHashMap.get("method");
186         logger.info("method:" + method);
187         
188         if(method.equalsIgnoreCase("selectContentListOnIdList"))
189         {
190             contents = new ArrayList JavaDoc();
191             List JavaDoc arguments = (List JavaDoc)argumentHashMap.get("arguments");
192             logger.info("Arguments:" + arguments.size());
193             Iterator JavaDoc argumentIterator = arguments.iterator();
194             while(argumentIterator.hasNext())
195             {
196                 HashMap JavaDoc argument = (HashMap JavaDoc)argumentIterator.next();
197                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)argument.get("contentId"));
198                 logger.info("Getting the content with Id:" + contentId);
199                 try
200                 {
201                     contents.add(this.getACContentVOWithId(infoGluePrincipal, contentId));
202                 }
203                 catch(Exception JavaDoc e)
204                 {
205                     //TODO - remove later
206
e.printStackTrace();
207                 }
208             }
209         }
210         else if(method.equalsIgnoreCase("selectListOnContentTypeName"))
211         {
212             List JavaDoc arguments = (List JavaDoc)argumentHashMap.get("arguments");
213             logger.info("Arguments:" + arguments.size());
214             contents = getContentVOListByContentTypeNames(arguments);
215             Iterator JavaDoc contentIterator = contents.iterator();
216             while(contentIterator.hasNext())
217             {
218                 ContentVO candidateContentVO = (ContentVO)contentIterator.next();
219                 
220                 Map JavaDoc hashMap = new HashMap JavaDoc();
221                 hashMap.put("contentId", candidateContentVO.getContentId());
222                 
223                 try
224                 {
225                     intercept(hashMap, "Content.Read", infoGluePrincipal);
226                 }
227                 catch(Exception JavaDoc e)
228                 {
229                     logger.info("Was not authorized to look at task...");
230                     contentIterator.remove();
231                 }
232             }
233         }
234         return contents;
235     }
236     
237     /**
238      * This method finishes up what the create content wizard has resulted after first checking that the user has rights to complete the action.
239      */

240
241     public ContentVO acCreate(InfoGluePrincipal infogluePrincipal, CreateContentWizardInfoBean createContentWizardInfoBean) throws ConstraintException, SystemException, Bug, Exception JavaDoc
242     {
243         //Map hashMap = new HashMap();
244
//hashMap.put("contentId", parentContentId);
245

246         //intercept(hashMap, "Content.Create", infogluePrincipal);
247

248         return ContentController.getContentController().create(createContentWizardInfoBean);
249     }
250
251     /**
252      * This method creates a content after first checking that the user has rights to edit it.
253      */

254
255     public ContentVO acCreate(InfoGluePrincipal infogluePrincipal, Integer JavaDoc parentContentId, Integer JavaDoc contentTypeDefinitionId, Integer JavaDoc repositoryId, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
256     {
257         Map JavaDoc hashMap = new HashMap JavaDoc();
258         hashMap.put("contentId", parentContentId);
259         
260         intercept(hashMap, "Content.Create", infogluePrincipal);
261
262         return ContentController.getContentController().create(parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
263     }
264     
265     /**
266      * This method updates a content after first checking that the user has rights to edit it.
267      */

268
269     public ContentVO acUpdate(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer JavaDoc contentTypeDefinitionId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
270     {
271         Map JavaDoc hashMap = new HashMap JavaDoc();
272         hashMap.put("contentId", contentVO.getId());
273         
274         intercept(hashMap, "Content.Write", infogluePrincipal);
275
276         return update(contentVO, contentTypeDefinitionId);
277     }
278     
279     /**
280      * This method deletes a content after first checking that the user has rights to edit it.
281      */

282
283     public void acDelete(InfoGluePrincipal infogluePrincipal, ContentVO contentVO) throws ConstraintException, SystemException, Bug, Exception JavaDoc
284     {
285         Map JavaDoc hashMap = new HashMap JavaDoc();
286         hashMap.put("contentId", contentVO.getId());
287         
288         intercept(hashMap, "Content.Delete", infogluePrincipal);
289
290         delete(contentVO);
291     }
292     
293     
294     /**
295      * This method moves a content after first checking that the user has rights to edit it.
296      */

297
298     public void acMoveContent(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer JavaDoc newParentContentId) throws ConstraintException, SystemException, Bug, Exception JavaDoc
299     {
300         Map JavaDoc hashMap = new HashMap JavaDoc();
301         hashMap.put("contentId", contentVO.getId());
302         
303         intercept(hashMap, "Content.Move", infogluePrincipal);
304         
305         hashMap = new HashMap JavaDoc();
306         hashMap.put("contentId", newParentContentId);
307
308         intercept(hashMap, "Content.Create", infogluePrincipal);
309
310         moveContent(contentVO, newParentContentId);
311     }
312
313     /**
314      * This method moves a content after first checking that the user has rights to within a transaction.
315      */

316
317     public void acMoveContent(InfoGluePrincipal infogluePrincipal, ContentVO contentVO, Integer JavaDoc newParentContentId, Database db) throws ConstraintException, SystemException, Bug, Exception JavaDoc
318     {
319         Map JavaDoc hashMap = new HashMap JavaDoc();
320         hashMap.put("contentId", contentVO.getId());
321         
322         intercept(hashMap, "Content.Move", infogluePrincipal);
323         
324         hashMap = new HashMap JavaDoc();
325         hashMap.put("contentId", newParentContentId);
326
327         intercept(hashMap, "Content.Create", infogluePrincipal);
328
329         moveContent(contentVO, newParentContentId, db);
330     }
331
332     /**
333      * This method returns true if the if the content in question is protected.
334      */

335
336     public Integer JavaDoc getProtectedContentId(Integer JavaDoc contentId)
337     {
338         Integer JavaDoc protectedContentId = null;
339         boolean isContentProtected = false;
340     
341         try
342         {
343             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId);
344             if(contentVO.getIsProtected() != null)
345             {
346                 if(contentVO.getIsProtected().intValue() == NO.intValue())
347                     protectedContentId = null;
348                 else if(contentVO.getIsProtected().intValue() == YES.intValue())
349                     protectedContentId = contentVO.getId();
350                 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue())
351                 {
352                     ContentVO parentContentVO = ContentController.getParentContent(contentId);
353                     if(parentContentVO != null)
354                         protectedContentId = getProtectedContentId(parentContentVO.getId());
355                 }
356             }
357         }
358         catch(Exception JavaDoc e)
359         {
360             logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e);
361         }
362             
363         return protectedContentId;
364     }
365     
366     /**
367      * This method returns true if the if the content in question is protected.
368      */

369
370     public boolean getIsContentProtected(Integer JavaDoc contentId)
371     {
372         boolean isContentProtected = false;
373     
374         try
375         {
376             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId);
377             if(contentVO.getIsProtected() != null)
378             {
379                 if(contentVO.getIsProtected().intValue() == NO.intValue())
380                     isContentProtected = false;
381                 else if(contentVO.getIsProtected().intValue() == YES.intValue())
382                     isContentProtected = true;
383                 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue())
384                 {
385                     ContentVO parentContentVO = ContentController.getParentContent(contentId);
386                     if(parentContentVO != null)
387                         isContentProtected = getIsContentProtected(parentContentVO.getId());
388                 }
389             }
390
391         }
392         catch(Exception JavaDoc e)
393         {
394             logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e);
395         }
396             
397         return isContentProtected;
398     }
399     
400     /*
401     public static Content getContentWithId(Integer contentId, Database db) throws SystemException, Bug
402     {
403         return (Content) getObjectWithId(ContentImpl.class, contentId, db);
404     }
405     */

406 /*
407     public static List getContentVOList() throws SystemException, Bug
408     {
409         return getAllVOObjects(ContentImpl.class);
410     }
411 */

412  
413 }
414
Popular Tags