KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > contenttool > actions > ViewContentAction


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.applications.contenttool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.infoglue.cms.applications.common.VisualFormatter;
34 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
37 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
38 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
39 import org.infoglue.cms.controllers.kernel.impl.simple.EventController;
40 import org.infoglue.cms.controllers.kernel.impl.simple.InfoGlueSettingsController;
41 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
42 import org.infoglue.cms.controllers.kernel.impl.simple.RegistryController;
43 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryLanguageController;
44 import org.infoglue.cms.entities.content.Content;
45 import org.infoglue.cms.entities.content.ContentVO;
46 import org.infoglue.cms.entities.content.ContentVersion;
47 import org.infoglue.cms.entities.content.ContentVersionVO;
48 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
49 import org.infoglue.cms.entities.management.LanguageVO;
50 import org.infoglue.cms.entities.workflow.EventVO;
51 import org.infoglue.cms.exception.AccessConstraintException;
52 import org.infoglue.cms.exception.Bug;
53 import org.infoglue.cms.exception.ConstraintException;
54 import org.infoglue.cms.exception.SystemException;
55 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
56 import org.infoglue.cms.util.CmsPropertyHandler;
57 import org.infoglue.cms.util.sorters.ReflectionComparator;
58
59 import webwork.action.Action;
60
61 import com.opensymphony.module.propertyset.PropertySet;
62 import com.opensymphony.module.propertyset.PropertySetManager;
63
64 public class ViewContentAction extends InfoGlueAbstractAction
65 {
66     private final static Logger logger = Logger.getLogger(ViewContentAction.class.getName());
67
68     private static final long serialVersionUID = 1L;
69     
70     private Integer JavaDoc unrefreshedContentId = new Integer JavaDoc(0);
71     private Integer JavaDoc changeTypeId = new Integer JavaDoc(0);
72     private Integer JavaDoc repositoryId = null;
73     private List JavaDoc availableLanguages = null;
74     private ContentTypeDefinitionVO contentTypeDefinitionVO;
75     private String JavaDoc defaultFolderContentTypeName;
76     private Integer JavaDoc languageId = null;
77     private String JavaDoc stay = null;
78     private List JavaDoc referenceBeanList = new ArrayList JavaDoc();
79
80     private ContentVO contentVO;
81
82
83     public ViewContentAction()
84     {
85         this(new ContentVO());
86     }
87     
88     public ViewContentAction(ContentVO contentVO)
89     {
90         this.contentVO = contentVO;
91     }
92     
93     protected void initialize(Integer JavaDoc contentId) throws Exception JavaDoc
94     {
95         this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId);
96         this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentId);
97         this.availableLanguages = RepositoryLanguageController.getController().getAvailableLanguageVOListForRepositoryId(this.contentVO.getRepositoryId());
98         
99         if(this.repositoryId == null)
100             this.repositoryId = this.contentVO.getRepositoryId();
101         
102         if(this.contentVO.getRepositoryId() != null && !hasAccessTo("Repository.Read", "" + this.contentVO.getRepositoryId()))
103         {
104             AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
105             ceb.add(new AccessConstraintException("Content.contentId", "1000"));
106             ceb.throwIfNotEmpty();
107         }
108
109         if(this.getIsBranch().booleanValue())
110         {
111             this.defaultFolderContentTypeName = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("repository_" + this.getRepositoryId() + "_defaultFolderContentTypeName", "applicationProperties", null, false, false, false, false, null);
112         }
113         
114         this.referenceBeanList = RegistryController.getController().getReferencingObjectsForContent(contentId);
115     }
116
117     public String JavaDoc doExecute() throws Exception JavaDoc
118     {
119         try
120         {
121             ContentVO contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getContentId());
122             
123             if(contentVO.getRepositoryId() != null && !hasAccessTo("Repository.Read", "" + contentVO.getRepositoryId()))
124             {
125                 System.out.println("You had no access to Repository.Read and " + this.contentVO.getRepositoryId());
126                 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
127                 ceb.add(new AccessConstraintException("Content.contentId", "1000"));
128                 ceb.throwIfNotEmpty();
129             }
130
131             if((this.stay == null || !this.stay.equalsIgnoreCase("true")) && contentVO.getIsBranch().booleanValue() == false && contentVO.getContentTypeDefinitionId() != null && getShowContentVersionFirst().equalsIgnoreCase("true"))
132             {
133                 if(this.repositoryId == null)
134                     this.repositoryId = contentVO.getRepositoryId();
135                 
136                 //this.languageId = getMasterLanguageVO().getId();
137
this.languageId = getInitialLanguageVO().getId();
138                 return "viewVersion";
139             }
140             else
141             {
142                 this.initialize(getContentId());
143                 return "success";
144             }
145         }
146         catch(ConstraintException ce)
147         {
148             throw ce;
149         }
150         catch(Exception JavaDoc e)
151         {
152             e.printStackTrace();
153         }
154         
155         return Action.NONE;
156     }
157
158     public String JavaDoc doStandalone() throws Exception JavaDoc
159     {
160         this.initialize(getContentId());
161         return "standalone";
162     }
163         
164     public java.lang.Integer JavaDoc getContentId()
165     {
166         return this.contentVO.getContentId();
167     }
168         
169     public void setContentId(java.lang.Integer JavaDoc contentId)
170     {
171         this.contentVO.setContentId(contentId);
172     }
173     
174     public java.lang.Integer JavaDoc getRepositoryId()
175     {
176         return this.repositoryId;
177     }
178         
179     public void setRepositoryId(java.lang.Integer JavaDoc repositoryId)
180     {
181         this.repositoryId = repositoryId;
182     }
183     
184     public java.lang.Integer JavaDoc getUnrefreshedContentId()
185     {
186         return this.unrefreshedContentId;
187     }
188         
189     public void setUnrefreshedContentId(java.lang.Integer JavaDoc unrefreshedContentId)
190     {
191         this.unrefreshedContentId = unrefreshedContentId;
192     }
193
194     public java.lang.Integer JavaDoc getChangeTypeId()
195     {
196         return this.changeTypeId;
197     }
198
199     public void setChangeTypeId(java.lang.Integer JavaDoc changeTypeId)
200     {
201         this.changeTypeId = changeTypeId;
202     }
203
204     public java.lang.Integer JavaDoc getNewContentId()
205     {
206         return this.contentVO.getId();
207     }
208
209     public String JavaDoc getName()
210     {
211         return this.contentVO.getName();
212     }
213
214     public String JavaDoc getPublishDateTime()
215     {
216         return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm");
217     }
218         
219     public String JavaDoc getExpireDateTime()
220     {
221         return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm");
222     }
223
224     public long getPublishDateTimeAsLong()
225     {
226         return this.contentVO.getPublishDateTime().getTime();
227     }
228         
229     public long getExpireDateTimeAsLong()
230     {
231         return this.contentVO.getExpireDateTime().getTime();
232     }
233     
234     public Boolean JavaDoc getIsBranch()
235     {
236         return this.contentVO.getIsBranch();
237     }
238
239     public Integer JavaDoc getIsProtected()
240     {
241         return this.contentVO.getIsProtected();
242     }
243
244     public ContentTypeDefinitionVO getContentTypeDefinition()
245     {
246         return this.contentTypeDefinitionVO;
247     }
248
249     public List JavaDoc getAvailableLanguages()
250     {
251         return this.availableLanguages;
252     }
253     
254     
255     public ContentVersionVO getLatestContentVersionVO(Integer JavaDoc contentId, Integer JavaDoc languageId)
256     {
257         ContentVersionVO contentVersionVO = null;
258         try
259         {
260             contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId);
261         }
262         catch(Exception JavaDoc e)
263         {
264             logger.error("An error occurred when we tried to get the latest version for the content:" + e.getMessage(), e);
265         }
266         
267         return contentVersionVO;
268     }
269
270
271     
272     public EventVO getContentVersionEvent(Integer JavaDoc contentVersionId)
273     {
274         EventVO eventVO = null;
275         try
276         {
277             ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId);
278             List JavaDoc events = EventController.getEventVOListForEntity(ContentVersion.class.getName(), contentVersion.getId());
279             if(events != null && events.size() > 0)
280                 eventVO = (EventVO)events.get(0);
281         }
282         catch(Exception JavaDoc e)
283         {
284             logger.error("An error occurred when we tried to get any events for this version:" + e.getMessage(), e);
285         }
286         
287         return eventVO;
288     }
289
290     public EventVO getContentEvent(Integer JavaDoc contentId)
291     {
292         EventVO eventVO = null;
293         try
294         {
295             List JavaDoc events = EventController.getEventVOListForEntity(Content.class.getName(), contentId);
296             if(events != null && events.size() > 0)
297                 eventVO = (EventVO)events.get(0);
298         }
299         catch(Exception JavaDoc e)
300         {
301             logger.error("An error occurred when we tried to get any events for this version:" + e.getMessage(), e);
302         }
303         
304         return eventVO;
305     }
306
307     public Integer JavaDoc getMasterLanguageId()
308     {
309         try
310         {
311             return LanguageController.getController().getMasterLanguage(repositoryId).getLanguageId();
312         }
313         catch (Exception JavaDoc e)
314         {
315             logger.error("Unable to get master language for repository", e);
316         }
317         return null;
318     }
319
320     public ContentVO getContentVO()
321     {
322         return contentVO;
323     }
324     
325     /**
326      * This method fetches the list of ContentTypeDefinitions
327      */

328     
329     public List JavaDoc getContentTypeDefinitions() throws Exception JavaDoc
330     {
331         List JavaDoc contentTypeVOList = null;
332         
333         String JavaDoc protectContentTypes = CmsPropertyHandler.getProtectContentTypes();
334         if(protectContentTypes != null && protectContentTypes.equalsIgnoreCase("true"))
335             contentTypeVOList = ContentTypeDefinitionController.getController().getAuthorizedContentTypeDefinitionVOList(this.getInfoGluePrincipal());
336         else
337             contentTypeVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
338         
339         Collections.sort(contentTypeVOList, new ReflectionComparator("name"));
340         
341         return contentTypeVOList;
342     }
343
344     
345     public List JavaDoc getContentPath()
346     {
347         ContentVO contentVO = this.contentVO;
348         List JavaDoc ret = new ArrayList JavaDoc();
349         // ret.add(0, contentVO);
350

351         while (contentVO.getParentContentId() != null)
352         {
353             try {
354                 contentVO = ContentControllerProxy.getController().getContentVOWithId(contentVO.getParentContentId());
355             } catch (SystemException e) {
356                 // TODO Auto-generated catch block
357
e.printStackTrace();
358             } catch (Bug e) {
359                 // TODO Auto-generated catch block
360
e.printStackTrace();
361             }
362             ret.add(0, contentVO);
363         }
364         return ret;
365     }
366
367     public void setContentVO(ContentVO contentVO)
368     {
369         this.contentVO = contentVO;
370     }
371         
372     public String JavaDoc getDefaultFolderContentTypeName()
373     {
374         return defaultFolderContentTypeName;
375     }
376     
377     public String JavaDoc getShowContentVersionFirst()
378     {
379         return CmsPropertyHandler.getShowContentVersionFirst();
380     }
381     
382     public LanguageVO getMasterLanguageVO() throws Exception JavaDoc
383     {
384         return LanguageController.getController().getMasterLanguage(repositoryId);
385     }
386
387     public LanguageVO getInitialLanguageVO() throws Exception JavaDoc
388     {
389         String JavaDoc initialLanguageId = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("content_" + this.getContentId() + "_initialLanguageId", "applicationProperties", null, false, false, false, false, null);
390         ContentVO parentContentVO = ContentController.getContentController().getParentContent(this.getContentId());
391         while((initialLanguageId == null || initialLanguageId.equalsIgnoreCase("-1")) && parentContentVO != null)
392         {
393             //initialLanguageId = ps.getString("content_" + parentContentVO.getId() + "_initialLanguageId");
394
initialLanguageId = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("content_" + parentContentVO.getId() + "_initialLanguageId", "applicationProperties", null, false, false, false, false, null);
395             parentContentVO = ContentController.getContentController().getParentContent(parentContentVO.getId());
396         }
397         
398         if(initialLanguageId != null && !initialLanguageId.equals("") && !initialLanguageId.equals("-1"))
399             return LanguageController.getController().getLanguageVOWithId(new Integer JavaDoc(initialLanguageId));
400         else
401             return LanguageController.getController().getMasterLanguage(repositoryId);
402     }
403
404     public Integer JavaDoc getLanguageId()
405     {
406         return languageId;
407     }
408     
409     public String JavaDoc getStay()
410     {
411         return stay;
412     }
413     
414     public void setStay(String JavaDoc stay)
415     {
416         this.stay = stay;
417     }
418     
419     public List JavaDoc getReferenceBeanList()
420     {
421         return referenceBeanList;
422     }
423 }
424
Popular Tags