KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
31 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.EventController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.PublicationController;
37 import org.infoglue.cms.entities.content.ContentVO;
38 import org.infoglue.cms.entities.content.ContentVersion;
39 import org.infoglue.cms.entities.content.ContentVersionVO;
40 import org.infoglue.cms.entities.publishing.PublicationVO;
41 import org.infoglue.cms.entities.workflow.EventVO;
42 import org.infoglue.cms.exception.AccessConstraintException;
43 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
44
45 /**
46  *
47  * @author Stefan Sik
48  *
49  * Present a list of contentVersion under a given content, recursing down in the hierarcy
50  *
51  */

52
53 public class UnpublishContentVersionAction extends InfoGlueAbstractAction
54 {
55     private static final long serialVersionUID = 1L;
56     
57     private List JavaDoc contentVersionVOList = new ArrayList JavaDoc();
58     private List JavaDoc contentVOList = new ArrayList JavaDoc();
59     private Integer JavaDoc contentId;
60     private Integer JavaDoc repositoryId;
61
62     private List JavaDoc contentVersionId = new ArrayList JavaDoc();
63     private Integer JavaDoc stateId;
64     private Integer JavaDoc languageId;
65     private String JavaDoc versionComment;
66     private boolean overrideVersionModifyer = false;
67     private String JavaDoc attemptDirectPublishing = "false";
68
69     
70     public String JavaDoc doInput() throws Exception JavaDoc
71     {
72         if(this.contentId != null)
73         {
74             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(this.contentId);
75             this.repositoryId = contentVO.getRepositoryId();
76             
77             AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
78         
79             Integer JavaDoc protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId);
80             if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.SubmitToPublish", protectedContentId.toString()))
81                 ceb.add(new AccessConstraintException("Content.contentId", "1005"));
82             
83             ceb.throwIfNotEmpty();
84
85             contentVersionVOList = ContentVersionController.getContentVersionController().getContentVersionVOWithParentRecursive(contentId, ContentVersionVO.PUBLISHED_STATE, false);
86         }
87
88         return "input";
89     }
90
91     public String JavaDoc doInputChooseContents() throws Exception JavaDoc
92     {
93         if(this.contentId != null)
94         {
95             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(this.contentId);
96             this.repositoryId = contentVO.getRepositoryId();
97             
98             AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
99         
100             Integer JavaDoc protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId);
101             if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.SubmitToPublish", protectedContentId.toString()))
102                 ceb.add(new AccessConstraintException("Content.contentId", "1005"));
103             
104             ceb.throwIfNotEmpty();
105
106             contentVOList = ContentController.getContentController().getContentVOWithParentRecursive(contentId);
107         }
108
109         return "inputChooseContents";
110     }
111
112     /**
113      * This method gets called when calling this action.
114      * If the stateId is 2 which equals that the user tries to prepublish the page. If so we
115      * ask the user for a comment as this is to be regarded as a new version.
116      */

117        
118     public String JavaDoc doExecute() throws Exception JavaDoc
119     {
120         setContentVersionId( getRequest().getParameterValues("sel") );
121         Iterator JavaDoc it = getContentVersionId().iterator();
122         
123         List JavaDoc events = new ArrayList JavaDoc();
124         while(it.hasNext())
125         {
126             Integer JavaDoc contentVersionId = (Integer JavaDoc)it.next();
127             //ContentVersion contentVersion = ContentStateController.changeState((Integer) it.next(), ContentVersionVO.PUBLISH_STATE, getVersionComment(), this.getInfoGluePrincipal(), null, events);
128
ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(contentVersionId);
129             
130             EventVO eventVO = new EventVO();
131             eventVO.setDescription(this.versionComment);
132             eventVO.setEntityClass(ContentVersion.class.getName());
133             eventVO.setEntityId(contentVersionId);
134             eventVO.setName(contentVersionVO.getContentName() + "(" + contentVersionVO.getLanguageName() + ")");
135             eventVO.setTypeId(EventVO.UNPUBLISH_LATEST);
136             eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal());
137             events.add(eventVO);
138         }
139         
140         if(attemptDirectPublishing.equalsIgnoreCase("true"))
141         {
142             PublicationVO publicationVO = new PublicationVO();
143             publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName());
144             publicationVO.setDescription(getVersionComment());
145             //publicationVO.setPublisher(this.getInfoGluePrincipal().getName());
146
publicationVO.setRepositoryId(repositoryId);
147             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, this.overrideVersionModifyer, this.getInfoGluePrincipal());
148         }
149         
150         return "success";
151     }
152
153
154     /**
155      * This method will try to unpublish all liver versions of this content.
156      */

157        
158     public String JavaDoc doUnpublishAll() throws Exception JavaDoc
159     {
160         String JavaDoc[] contentIds = getRequest().getParameterValues("sel");
161
162         List JavaDoc events = new ArrayList JavaDoc();
163
164         for(int i=0; i < contentIds.length; i++)
165         {
166             String JavaDoc contentIdString = contentIds[i];
167             List JavaDoc contentVersionsVOList = ContentVersionController.getContentVersionController().getPublishedActiveContentVersionVOList(new Integer JavaDoc(contentIdString));
168             
169             Iterator JavaDoc it = contentVersionsVOList.iterator();
170             
171             while(it.hasNext())
172             {
173                 ContentVersionVO contentVersionVO = (ContentVersionVO)it.next();
174                 
175                 EventVO eventVO = new EventVO();
176                 eventVO.setDescription(this.versionComment);
177                 eventVO.setEntityClass(ContentVersion.class.getName());
178                 eventVO.setEntityId(contentVersionVO.getContentVersionId());
179                 eventVO.setName(contentVersionVO.getContentName() + "(" + contentVersionVO.getLanguageName() + ")");
180                 eventVO.setTypeId(EventVO.UNPUBLISH_LATEST);
181                 eventVO = EventController.create(eventVO, this.repositoryId, this.getInfoGluePrincipal());
182                 events.add(eventVO);
183             }
184         }
185         
186         if(attemptDirectPublishing.equalsIgnoreCase("true"))
187         {
188             PublicationVO publicationVO = new PublicationVO();
189             publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName());
190             publicationVO.setDescription(getVersionComment());
191             //publicationVO.setPublisher(this.getInfoGluePrincipal().getName());
192
publicationVO.setRepositoryId(repositoryId);
193             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, this.overrideVersionModifyer, this.getInfoGluePrincipal());
194         }
195         
196         return "success";
197     }
198
199     public List JavaDoc getContentVersions()
200     {
201         return this.contentVersionVOList;
202     }
203     
204     public List JavaDoc getContents()
205     {
206         return contentVOList;
207     }
208
209     public Integer JavaDoc getContentId()
210     {
211         return contentId;
212     }
213
214     public void setContentId(Integer JavaDoc contentId)
215     {
216         this.contentId = contentId;
217     }
218
219     public Integer JavaDoc getRepositoryId()
220     {
221         return repositoryId;
222     }
223     
224     public java.lang.Integer JavaDoc getLanguageId()
225     {
226         return this.languageId;
227     }
228         
229     public void setLanguageId(Integer JavaDoc languageId)
230     {
231         this.languageId = languageId;
232     }
233                     
234     public void setStateId(Integer JavaDoc stateId)
235     {
236         this.stateId = stateId;
237     }
238
239     public void setVersionComment(String JavaDoc versionComment)
240     {
241         this.versionComment = versionComment;
242     }
243     
244     public String JavaDoc getVersionComment()
245     {
246         return this.versionComment;
247     }
248     
249     public Integer JavaDoc getStateId()
250     {
251         return this.stateId;
252     }
253             
254     /**
255      * @return
256      */

257     public List JavaDoc getContentVersionId()
258     {
259         return contentVersionId;
260     }
261
262     /**
263      * @param list
264      */

265     private void setContentVersionId(String JavaDoc[] list)
266     {
267         contentVersionId = new ArrayList JavaDoc();
268         for(int i=0; i < list.length; i++)
269         {
270             contentVersionId.add(new Integer JavaDoc(list[i]));
271         }
272     }
273
274     public void setAttemptDirectPublishing(String JavaDoc attemptDirectPublishing)
275     {
276         this.attemptDirectPublishing = attemptDirectPublishing;
277     }
278     
279     public void setRepositoryId(Integer JavaDoc repositoryId)
280     {
281         this.repositoryId = repositoryId;
282     }
283     
284     public boolean getOverrideVersionModifyer()
285     {
286         return overrideVersionModifyer;
287     }
288     
289     public void setOverrideVersionModifyer(boolean overrideVersionModifyer)
290     {
291         this.overrideVersionModifyer = overrideVersionModifyer;
292     }
293 }
294
Popular Tags