KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > contenttool > wizards > actions > CreateContentWizardAction


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.wizards.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.infoglue.cms.applications.common.VisualFormatter;
30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
31 import org.infoglue.cms.applications.contenttool.actions.ViewContentTreeActionInterface;
32 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
37 import org.infoglue.cms.entities.content.ContentVO;
38 import org.infoglue.cms.entities.content.ContentVersionVO;
39 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
40 import org.infoglue.cms.entities.management.LanguageVO;
41 import org.infoglue.cms.entities.management.RepositoryVO;
42 import org.infoglue.cms.exception.AccessConstraintException;
43 import org.infoglue.cms.exception.Bug;
44 import org.infoglue.cms.exception.ConstraintException;
45 import org.infoglue.cms.exception.SystemException;
46 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
47 import org.infoglue.cms.util.ConstraintExceptionBuffer;
48
49 /**
50  * This action represents the CreateContent with help of a wizard. It guides the user through creating a new content
51  * and allows a developer to control it's flow and basic parameters a bit so it steers the user to make correct descisions.
52  */

53
54 public class CreateContentWizardAction extends InfoGlueAbstractAction implements ViewContentTreeActionInterface
55 {
56     private static final long serialVersionUID = 1L;
57     
58     //Used by the tree only
59
private Integer JavaDoc contentId;
60     private String JavaDoc tree;
61     private String JavaDoc hideLeafs;
62     
63     //Used by the second screen only
64
private String JavaDoc[] allowedContentTypeDefinitionId;
65     private List JavaDoc contentTypeDefinitionVOList = new ArrayList JavaDoc();
66
67     //Used by the content version screen only
68
public ContentTypeDefinitionVO contentTypeDefinitionVO;
69     public List JavaDoc availableLanguages = null;
70     private Integer JavaDoc languageId;
71     private Integer JavaDoc contentVersionId;
72     private Integer JavaDoc currentEditorId;
73     private String JavaDoc attributeName = "";
74     private String JavaDoc textAreaId = "";
75     private ContentVersionVO contentVersionVO;
76     public List JavaDoc attributes = null;
77
78     //Common
79
private Integer JavaDoc parentContentId;
80     private Integer JavaDoc contentTypeDefinitionId;
81     private Integer JavaDoc repositoryId;
82     private ConstraintExceptionBuffer ceb;
83     private ContentVO contentVO;
84     private ContentVO newContentVO;
85
86     protected void initialize(Integer JavaDoc contentVersionId, Integer JavaDoc contentId, Integer JavaDoc languageId) throws Exception JavaDoc
87     {
88         this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId);
89         //this.contentVO = ContentController.getContentVOWithId(contentId);
90
this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentId);
91         this.availableLanguages = ContentController.getContentController().getRepositoryLanguages(contentId);
92         
93         this.languageId = ((LanguageVO)this.availableLanguages.get(0)).getLanguageId();
94         /*
95         if(contentVersionId == null)
96         {
97             //this.contentVersionVO = ContentVersionControllerProxy.getController().getACLatestActiveContentVersionVO(this.getInfoGluePrincipal(), contentId, languageId);
98             //this.contentVersionVO = ContentVersionController.getLatestActiveContentVersionVO(contentId, languageId);
99             this.contentVersionVO = ContentVersionController.getLatestActiveContentVersionVO(contentId, languageId);
100             if(this.contentVersionVO != null)
101                 contentVersionId = contentVersionVO.getContentVersionId();
102         }
103
104         if(contentVersionId != null)
105             this.contentVersionVO = ContentVersionControllerProxy.getController().getACContentVersionVOWithId(this.getInfoGluePrincipal(), contentVersionId);
106             //this.contentVersionVO = ContentVersionController.getContentVersionVOWithId(contentVersionId);
107         */

108         
109         this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().validateAndUpdateContentType(this.contentTypeDefinitionVO);
110         this.attributes = ContentTypeDefinitionController.getController().getContentTypeAttributes(this.contentTypeDefinitionVO.getSchemaValue());
111     }
112     
113     /**
114      * This method presents the user with the initial input screen for creating a content.
115      *
116      * @return
117      * @throws Exception
118      */

119      
120     public String JavaDoc doInput() throws Exception JavaDoc
121     {
122         if(parentContentId == null)
123         {
124             return "stateLocation";
125         }
126         
127         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
128     
129         Integer JavaDoc protectedContentId = ContentControllerProxy.getController().getProtectedContentId(parentContentId);
130         if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", protectedContentId.toString()))
131             ceb.add(new AccessConstraintException("Content.contentId", "1002"));
132
133         //if(ContentControllerProxy.getController().getIsContentProtected(parentContentId) && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", parentContentId.toString()))
134
// ceb.add(new AccessConstraintException("Content.contentId", "1002"));
135

136         ceb.throwIfNotEmpty();
137
138         if(allowedContentTypeDefinitionId == null)
139         {
140             this.contentTypeDefinitionVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
141         }
142         else
143         {
144             for(int i=0; i < allowedContentTypeDefinitionId.length; i++)
145             {
146                 String JavaDoc allowedContentTypeDefinitionIdString = allowedContentTypeDefinitionId[i];
147                 this.contentTypeDefinitionVOList.add(ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(new Integer JavaDoc(allowedContentTypeDefinitionIdString)));
148             }
149         }
150     
151         return "input";
152     }
153
154     public String JavaDoc doCreateContent() throws Exception JavaDoc
155     {
156         this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName());
157
158         ceb = this.contentVO.validate();
159         ceb.throwIfNotEmpty();
160                 
161         newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
162         
163         this.initialize(this.contentVersionId, newContentVO.getContentId(), this.languageId);
164
165         return "createContentSuccess";
166     }
167
168     public String JavaDoc doExecute() throws Exception JavaDoc
169     {
170         this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName());
171
172         ceb = this.contentVO.validate();
173         ceb.throwIfNotEmpty();
174                 
175         newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
176         
177         return "success";
178     }
179     
180     public Integer JavaDoc getTopRepositoryId() throws ConstraintException, SystemException, Bug
181     {
182         List JavaDoc repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
183         
184         Integer JavaDoc topRepositoryId = null;
185
186         if (repositoryId != null)
187             topRepositoryId = repositoryId;
188
189         if(repositories.size() > 0)
190         {
191             topRepositoryId = ((RepositoryVO)repositories.get(0)).getRepositoryId();
192         }
193     
194         return topRepositoryId;
195     }
196   
197     public CreateContentWizardAction()
198     {
199         this(new ContentVO());
200     }
201     
202     public CreateContentWizardAction(ContentVO contentVO)
203     {
204         this.contentVO = contentVO;
205         this.ceb = new ConstraintExceptionBuffer();
206     }
207
208     public void setContentId(Integer JavaDoc contentId)
209     {
210         this.contentId = contentId;
211     }
212
213     public Integer JavaDoc getContentId()
214     {
215         return this.contentId;
216     }
217
218     public void setHideLeafs(String JavaDoc hideLeafs)
219     {
220         this.hideLeafs = hideLeafs;
221     }
222
223     public String JavaDoc getHideLeafs()
224     {
225         return this.hideLeafs;
226     }
227
228     public String JavaDoc getTree()
229     {
230         return tree;
231     }
232
233     public void setTree(String JavaDoc tree)
234     {
235         this.tree = tree;
236     }
237
238
239
240     public void setParentContentId(Integer JavaDoc parentContentId)
241     {
242         this.parentContentId = parentContentId;
243     }
244
245     public Integer JavaDoc getParentContentId()
246     {
247         return this.parentContentId;
248     }
249
250     public void setRepositoryId(Integer JavaDoc repositoryId)
251     {
252         this.repositoryId = repositoryId;
253     }
254
255     /**
256      * Returns the repositoryId either sent in or last used by the user or lastly the top one.
257      */

258
259     public Integer JavaDoc getRepositoryId()
260     {
261         try
262         {
263             if(this.repositoryId == null)
264             {
265                 this.repositoryId = (Integer JavaDoc)getHttpSession().getAttribute("repositoryId");
266                     
267                 if(this.repositoryId == null)
268                 {
269                     this.repositoryId = getTopRepositoryId();
270                     getHttpSession().setAttribute("repositoryId", this.repositoryId);
271                 }
272             }
273         }
274         catch(Exception JavaDoc e)
275         {
276         }
277             
278         return repositoryId;
279     }
280
281     public void setContentTypeDefinitionId(Integer JavaDoc contentTypeDefinitionId)
282     {
283         this.contentTypeDefinitionId = contentTypeDefinitionId;
284     }
285
286     public Integer JavaDoc getContentTypeDefinitionId()
287     {
288         return this.contentTypeDefinitionId;
289     }
290     
291     public java.lang.String JavaDoc getName()
292     {
293         return this.contentVO.getName();
294     }
295
296     public String JavaDoc getPublishDateTime()
297     {
298         return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm");
299     }
300         
301     public String JavaDoc getExpireDateTime()
302     {
303         return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm");
304     }
305
306     public long getPublishDateTimeAsLong()
307     {
308         return this.contentVO.getPublishDateTime().getTime();
309     }
310         
311     public long getExpireDateTimeAsLong()
312     {
313         return this.contentVO.getExpireDateTime().getTime();
314     }
315     
316     public Boolean JavaDoc getIsBranch()
317     {
318         return this.contentVO.getIsBranch();
319     }
320             
321     public void setName(java.lang.String JavaDoc name)
322     {
323         this.contentVO.setName(name);
324     }
325         
326     public void setPublishDateTime(String JavaDoc publishDateTime)
327     {
328         this.contentVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm"));
329     }
330
331     public void setExpireDateTime(String JavaDoc expireDateTime)
332     {
333         this.contentVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm"));
334     }
335  
336     public void setIsBranch(Boolean JavaDoc isBranch)
337     {
338         this.contentVO.setIsBranch(isBranch);
339     }
340      
341     public Integer JavaDoc getNewContentId()
342     {
343         return newContentVO.getContentId();
344     }
345
346     
347     public List JavaDoc getContentTypeDefinitions() throws Exception JavaDoc
348     {
349         return ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
350     }
351      
352     /*
353
354     
355       
356     public String doExecute() throws Exception
357     {
358         this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName());
359
360         ceb = this.contentVO.validate();
361         ceb.throwIfNotEmpty();
362                 
363         newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
364         //newContentVO = ContentController.create(parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
365         
366         return "success";
367     }
368     
369     public String doBindingView() throws Exception
370     {
371         doExecute();
372         return "bindingView";
373     }
374     
375     public String doTreeView() throws Exception
376     {
377         doExecute();
378         return "treeView";
379     }
380
381     public String doInput() throws Exception
382     {
383         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
384         
385         if(ContentControllerProxy.getController().getIsContentProtected(parentContentId) && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", parentContentId.toString()))
386             ceb.add(new AccessConstraintException("Content.contentId", "1002"));
387
388         ceb.throwIfNotEmpty();
389         
390         return "input";
391     }
392     */

393     
394     public String JavaDoc[] getAllowedContentTypeDefinitionId()
395     {
396         return allowedContentTypeDefinitionId;
397     }
398
399     public void setAllowedContentTypeDefinitionId(String JavaDoc[] strings)
400     {
401         allowedContentTypeDefinitionId = strings;
402     }
403
404     public java.lang.Integer JavaDoc getContentVersionId()
405     {
406         return this.contentVersionVO.getContentVersionId();
407     }
408
409     public void setContentVersionId(java.lang.Integer JavaDoc contentVersionId)
410     {
411         this.contentVersionVO.setContentVersionId(contentVersionId);
412     }
413     public List JavaDoc getAttributes()
414     {
415         return attributes;
416     }
417
418     public List JavaDoc getAvailableLanguages()
419     {
420         return availableLanguages;
421     }
422
423     public ContentTypeDefinitionVO getContentTypeDefinitionVO()
424     {
425         return contentTypeDefinitionVO;
426     }
427
428     public ContentVersionVO getContentVersionVO()
429     {
430         return contentVersionVO;
431     }
432
433     public ContentVO getContentVO()
434     {
435         return contentVO;
436     }
437
438     public Integer JavaDoc getCurrentEditorId()
439     {
440         return currentEditorId;
441     }
442
443     public Integer JavaDoc getLanguageId()
444     {
445         return languageId;
446     }
447
448     public ContentVO getNewContentVO()
449     {
450         return newContentVO;
451     }
452
453     public String JavaDoc getTextAreaId()
454     {
455         return textAreaId;
456     }
457
458     public void setAttributes(List JavaDoc list)
459     {
460         attributes = list;
461     }
462
463     /**
464      * This method returns the attributes in the content type definition for generation.
465      */

466     
467     public List JavaDoc getContentTypeAttributes()
468     {
469         return this.attributes;
470     }
471     
472     public void setAvailableLanguages(List JavaDoc list)
473     {
474         availableLanguages = list;
475     }
476
477     public void setContentTypeDefinitionVO(ContentTypeDefinitionVO definitionVO)
478     {
479         contentTypeDefinitionVO = definitionVO;
480     }
481
482     public void setContentVersionVO(ContentVersionVO versionVO)
483     {
484         contentVersionVO = versionVO;
485     }
486
487     public void setContentVO(ContentVO contentVO)
488     {
489         this.contentVO = contentVO;
490     }
491
492     public void setCurrentEditorId(Integer JavaDoc integer)
493     {
494         currentEditorId = integer;
495     }
496
497     public void setLanguageId(Integer JavaDoc integer)
498     {
499         languageId = integer;
500     }
501
502     public void setNewContentVO(ContentVO contentVO)
503     {
504         newContentVO = contentVO;
505     }
506
507     public void setTextAreaId(String JavaDoc string)
508     {
509         textAreaId = string;
510     }
511
512 }
513
Popular Tags