KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URLEncoder JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.infoglue.cms.applications.common.VisualFormatter;
31 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
33 import org.infoglue.cms.entities.content.ContentVO;
34 import org.infoglue.cms.util.ConstraintExceptionBuffer;
35
36 /**
37  * This action represents the create content step in the wizards.
38  */

39
40 public class CreateContentWizardInputContentAction extends InfoGlueAbstractAction
41 {
42     private List JavaDoc contentTypeDefinitionVOList = new ArrayList JavaDoc();
43     private String JavaDoc returnAddress;
44     private ContentVO contentVO;
45     private Integer JavaDoc contentTypeDefinitionId;
46     private ConstraintExceptionBuffer ceb;
47
48     private String JavaDoc[] allowedContentTypeIds = null;
49
50
51     public CreateContentWizardInputContentAction()
52     {
53         this(new ContentVO());
54     }
55     
56     public CreateContentWizardInputContentAction(ContentVO contentVO)
57     {
58         this.contentVO = contentVO;
59         this.ceb = new ConstraintExceptionBuffer();
60     }
61
62     private void initialiaze() throws Exception JavaDoc
63     {
64         if(allowedContentTypeIds == null)
65         {
66             this.contentTypeDefinitionVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
67         }
68         else
69         {
70             for(int i=0; i < allowedContentTypeIds.length; i++)
71             {
72                 String JavaDoc allowedContentTypeDefinitionIdString = allowedContentTypeIds[i];
73                 this.contentTypeDefinitionVOList.add(ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(new Integer JavaDoc(allowedContentTypeDefinitionIdString)));
74             }
75         }
76     }
77     
78     /**
79      * This method presents the user with the initial input screen for creating a content.
80      *
81      * @return
82      * @throws Exception
83      */

84      
85     public String JavaDoc doInput() throws Exception JavaDoc
86     {
87         initialiaze();
88         return "input";
89     }
90
91     /**
92      * This method validates the input and handles any deviations.
93      *
94      * @return
95      * @throws Exception
96      */

97      
98     public String JavaDoc doExecute() throws Exception JavaDoc
99     {
100         this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName());
101
102         ceb = this.contentVO.validate();
103     
104         if(!ceb.isEmpty())
105             initialiaze();
106     
107         ceb.throwIfNotEmpty();
108         
109         return "success";
110     }
111
112     /**
113      * This method fetches the list of ContentTypeDefinitions
114      */

115     
116     public List JavaDoc getContentTypeDefinitions() throws Exception JavaDoc
117     {
118         return this.contentTypeDefinitionVOList;
119     }
120
121     public java.lang.String JavaDoc getName()
122     {
123         return this.contentVO.getName();
124     }
125
126     public void setName(String JavaDoc name)
127     {
128         this.contentVO.setName(name);
129     }
130
131     public String JavaDoc getPublishDateTime()
132     {
133         return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm");
134     }
135
136     public void setPublishDateTime(String JavaDoc publishDateTime)
137     {
138         this.contentVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm"));
139     }
140         
141     public String JavaDoc getExpireDateTime()
142     {
143         return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm");
144     }
145
146     public void setExpireDateTime(String JavaDoc expireDateTime)
147     {
148         this.contentVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm"));
149     }
150
151     public long getPublishDateTimeAsLong()
152     {
153         return this.contentVO.getPublishDateTime().getTime();
154     }
155         
156     public long getExpireDateTimeAsLong()
157     {
158         return this.contentVO.getExpireDateTime().getTime();
159     }
160     
161     public Boolean JavaDoc getIsBranch()
162     {
163         return this.contentVO.getIsBranch();
164     }
165
166     public void setIsBranch(Boolean JavaDoc isBranch)
167     {
168         this.contentVO.setIsBranch(isBranch);
169     }
170             
171     public Integer JavaDoc getContentTypeDefinitionId()
172     {
173         return this.contentTypeDefinitionId;
174     }
175
176     public void setContentTypeDefinitionId(Integer JavaDoc contentTypeDefinitionId)
177     {
178         this.contentTypeDefinitionId = contentTypeDefinitionId;
179     }
180
181     public String JavaDoc getReturnAddress()
182     {
183         return returnAddress;
184     }
185
186     public void setReturnAddress(String JavaDoc string)
187     {
188         returnAddress = string;
189     }
190
191     public String JavaDoc getAllowedContentTypeIdsAsUrlEncodedString() throws Exception JavaDoc
192     {
193         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
194         
195         for(int i=0; i<allowedContentTypeIds.length; i++)
196         {
197             if(i > 0)
198                 sb.append("&");
199             
200             sb.append("allowedContentTypeIds=" + URLEncoder.encode(allowedContentTypeIds[i], "UTF-8"));
201         }
202
203         return sb.toString();
204     }
205
206     public String JavaDoc[] getAllowedContentTypeIds()
207     {
208         return allowedContentTypeIds;
209     }
210     
211     public void setAllowedContentTypeIds(String JavaDoc[] allowedContentTypeIds)
212     {
213         this.allowedContentTypeIds = allowedContentTypeIds;
214     }
215
216 }
217
Popular Tags