KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.infoglue.cms.applications.common.VisualFormatter;
32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
33 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
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.entities.content.ContentVO;
37 import org.infoglue.cms.exception.AccessConstraintException;
38 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
39 import org.infoglue.cms.util.CmsPropertyHandler;
40 import org.infoglue.cms.util.ConstraintExceptionBuffer;
41 import org.infoglue.cms.util.sorters.ReflectionComparator;
42
43 import com.opensymphony.module.propertyset.PropertySet;
44 import com.opensymphony.module.propertyset.PropertySetManager;
45
46 /**
47  * This action represents the CreateContent Usecase.
48  */

49
50 public class CreateContentAction extends InfoGlueAbstractAction
51 {
52     private static final long serialVersionUID = 1L;
53     
54     private Integer JavaDoc parentContentId;
55     private Integer JavaDoc contentTypeDefinitionId;
56     private Integer JavaDoc repositoryId;
57     private ConstraintExceptionBuffer ceb;
58     private ContentVO contentVO;
59     private ContentVO newContentVO;
60     private String JavaDoc defaultFolderContentTypeName;
61     private String JavaDoc allowedContentTypeNames;
62     private String JavaDoc defaultContentTypeName;
63   
64     public CreateContentAction()
65     {
66         this(new ContentVO());
67     }
68     
69     public CreateContentAction(ContentVO contentVO)
70     {
71         this.contentVO = contentVO;
72         this.ceb = new ConstraintExceptionBuffer();
73     }
74
75     public void setParentContentId(Integer JavaDoc parentContentId)
76     {
77         this.parentContentId = parentContentId;
78     }
79
80     public Integer JavaDoc getParentContentId()
81     {
82         return this.parentContentId;
83     }
84
85     public void setRepositoryId(Integer JavaDoc repositoryId)
86     {
87         this.repositoryId = repositoryId;
88     }
89
90     public Integer JavaDoc getRepositoryId()
91     {
92         return this.repositoryId;
93     }
94
95     public void setContentTypeDefinitionId(Integer JavaDoc contentTypeDefinitionId)
96     {
97         this.contentTypeDefinitionId = contentTypeDefinitionId;
98     }
99
100     public Integer JavaDoc getContentTypeDefinitionId()
101     {
102         return this.contentTypeDefinitionId;
103     }
104     
105     public java.lang.String JavaDoc getName()
106     {
107         return this.contentVO.getName();
108     }
109
110     public String JavaDoc getPublishDateTime()
111     {
112         return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm");
113     }
114         
115     public String JavaDoc getExpireDateTime()
116     {
117         return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm");
118     }
119
120     public long getPublishDateTimeAsLong()
121     {
122         return this.contentVO.getPublishDateTime().getTime();
123     }
124         
125     public long getExpireDateTimeAsLong()
126     {
127         return this.contentVO.getExpireDateTime().getTime();
128     }
129     
130     public Boolean JavaDoc getIsBranch()
131     {
132         return this.contentVO.getIsBranch();
133     }
134             
135     public void setName(java.lang.String JavaDoc name)
136     {
137         this.contentVO.setName(name);
138     }
139         
140     public void setPublishDateTime(String JavaDoc publishDateTime)
141     {
142         this.contentVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm"));
143     }
144
145     public void setExpireDateTime(String JavaDoc expireDateTime)
146     {
147         this.contentVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm"));
148     }
149  
150     public void setIsBranch(Boolean JavaDoc isBranch)
151     {
152         this.contentVO.setIsBranch(isBranch);
153     }
154      
155     public Integer JavaDoc getContentId()
156     {
157         return newContentVO.getContentId();
158     }
159
160     public String JavaDoc getDefaultFolderContentTypeName()
161     {
162         return defaultFolderContentTypeName;
163     }
164
165     /**
166      * This method fetches the list of ContentTypeDefinitions
167      */

168     
169     public List JavaDoc getContentTypeDefinitions() throws Exception JavaDoc
170     {
171         List JavaDoc contentTypeVOList = null;
172         
173         String JavaDoc protectContentTypes = CmsPropertyHandler.getProtectContentTypes();
174         if(protectContentTypes != null && protectContentTypes.equalsIgnoreCase("true"))
175             contentTypeVOList = ContentTypeDefinitionController.getController().getAuthorizedContentTypeDefinitionVOList(this.getInfoGluePrincipal());
176         else
177             contentTypeVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
178         
179         Collections.sort(contentTypeVOList, new ReflectionComparator("name"));
180         
181         return contentTypeVOList;
182     }
183     
184       
185     public String JavaDoc doExecute() throws Exception JavaDoc
186     {
187         this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName());
188
189         ceb = this.contentVO.validate();
190         ceb.throwIfNotEmpty();
191                 
192         newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
193         //newContentVO = ContentController.create(parentContentId, contentTypeDefinitionId, repositoryId, contentVO);
194

195         if ( newContentVO.getIsBranch().booleanValue() )
196         {
197             Map JavaDoc args = new HashMap JavaDoc();
198             args.put("globalKey", "infoglue");
199             PropertySet ps = PropertySetManager.getInstance("jdbc", args);
200     
201             String JavaDoc allowedContentTypeNames = ps.getString("content_" + this.getParentContentId() + "_allowedContentTypeNames");
202             String JavaDoc defaultContentTypeName = ps.getString("content_" + this.getParentContentId() + "_defaultContentTypeName");
203             String JavaDoc initialLanguageId = ps.getString("content_" + this.getParentContentId() + "_initialLanguageId");
204             
205             if ( allowedContentTypeNames != null )
206             {
207                 ps.setString("content_" + this.getContentId() + "_allowedContentTypeNames", allowedContentTypeNames );
208             }
209             if ( defaultContentTypeName != null )
210             {
211             ps.setString("content_" + this.getContentId() + "_defaultContentTypeName", defaultContentTypeName );
212             }
213             if ( initialLanguageId != null )
214             {
215                 ps.setString("content_" + this.getContentId() + "_initialLanguageId", initialLanguageId );
216             }
217         }
218         return "success";
219     }
220     
221     public String JavaDoc doBindingView() throws Exception JavaDoc
222     {
223         doExecute();
224         return "bindingView";
225     }
226     
227     public String JavaDoc doTreeView() throws Exception JavaDoc
228     {
229         doExecute();
230         return "treeView";
231     }
232
233     public String JavaDoc doInput() throws Exception JavaDoc
234     {
235         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
236         
237         Integer JavaDoc protectedContentId = ContentControllerProxy.getController().getProtectedContentId(parentContentId);
238         if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", protectedContentId.toString()))
239             ceb.add(new AccessConstraintException("Content.contentId", "1002"));
240         
241         Map JavaDoc args = new HashMap JavaDoc();
242         args.put("globalKey", "infoglue");
243         PropertySet ps = PropertySetManager.getInstance("jdbc", args);
244
245         if(this.getIsBranch().booleanValue())
246         {
247             this.defaultFolderContentTypeName = ps.getString("repository_" + this.getRepositoryId() + "_defaultFolderContentTypeName");
248         }
249         else
250         {
251             this.defaultContentTypeName = ps.getString("content_" + this.parentContentId + "_defaultContentTypeName");
252         }
253         if ( ps.exists( "content_" + this.parentContentId + "_allowedContentTypeNames" ) )
254         {
255             this.allowedContentTypeNames = ps.getString("content_" + this.parentContentId + "_allowedContentTypeNames");
256         }
257         ceb.throwIfNotEmpty();
258         
259         return "input";
260     }
261         
262     public String JavaDoc getAllowedContentTypeNames()
263     {
264         return allowedContentTypeNames;
265     }
266     
267     public String JavaDoc getDefaultContentTypeName()
268     {
269         return defaultContentTypeName;
270     }
271 }
272
Popular Tags