KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.log4j.Logger;
31 import org.infoglue.cms.applications.cmstool.actions.ViewCMSAbstractToolAction;
32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentStateController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.PublicationController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeStateController;
36 import org.infoglue.cms.entities.content.ContentVersion;
37 import org.infoglue.cms.entities.content.ContentVersionVO;
38 import org.infoglue.cms.entities.publishing.PublicationVO;
39 import org.infoglue.cms.entities.structure.SiteNodeVersion;
40 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
41
42
43 public class ChangeMultiContentStatePublishAction extends InfoGlueAbstractAction
44 {
45     private final static Logger logger = Logger.getLogger(ChangeMultiContentStatePublishAction.class.getName());
46
47     private static final long serialVersionUID = -6759369582248131484L;
48
49     private Integer JavaDoc contentId;
50     private List JavaDoc contentVersionId = new ArrayList JavaDoc();
51     private List JavaDoc siteNodeVersionId = new ArrayList JavaDoc();
52     private Integer JavaDoc stateId;
53     private Integer JavaDoc languageId;
54     private String JavaDoc versionComment;
55     private boolean overrideVersionModifyer = false;
56     private Integer JavaDoc repositoryId;
57     private String JavaDoc attemptDirectPublishing = "false";
58     private String JavaDoc returnAddress = null;
59             
60     /**
61      * This method gets called when calling this action.
62      * If the stateId is 2 which equals that the user tries to prepublish the page. If so we
63      * ask the user for a comment as this is to be regarded as a new version.
64      */

65        
66     public String JavaDoc doExecute() throws Exception JavaDoc
67     {
68         setSiteNodeVersionId( getRequest().getParameterValues("selSiteNodeVersions") );
69         Iterator JavaDoc it = siteNodeVersionId.iterator();
70
71         List JavaDoc events = new ArrayList JavaDoc();
72         while(it.hasNext())
73         {
74             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)it.next();
75             logger.info("Publishing:" + siteNodeVersionId);
76             SiteNodeVersion siteNodeVersion = SiteNodeStateController.getController().changeState(siteNodeVersionId, SiteNodeVersionVO.PUBLISH_STATE, getVersionComment(), overrideVersionModifyer, this.getInfoGluePrincipal(), null, events);
77         }
78
79         setContentVersionId( getRequest().getParameterValues("selContentVersions") );
80         Iterator JavaDoc contentVersionIdsIterator = contentVersionId.iterator();
81
82         while(contentVersionIdsIterator.hasNext())
83         {
84             Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdsIterator.next();
85             logger.info("Publishing:" + contentVersionId);
86             ContentVersion contentVersion = ContentStateController.changeState(contentVersionId, ContentVersionVO.PUBLISH_STATE, getVersionComment(), this.overrideVersionModifyer, this.getInfoGluePrincipal(), null, events);
87         }
88         
89         if(attemptDirectPublishing.equalsIgnoreCase("true"))
90         {
91             PublicationVO publicationVO = new PublicationVO();
92             publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName());
93             publicationVO.setDescription(getVersionComment());
94             publicationVO.setRepositoryId(repositoryId);
95             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, this.overrideVersionModifyer, this.getInfoGluePrincipal());
96         }
97         
98         if(returnAddress != null && !returnAddress.equals(""))
99         {
100             this.getResponse().sendRedirect(returnAddress);
101         
102             return NONE;
103         }
104         
105         return "success";
106     }
107         
108     public java.lang.Integer JavaDoc getContentId()
109     {
110         return this.contentId;
111     }
112         
113     public void setContentId(java.lang.Integer JavaDoc contentId)
114     {
115         this.contentId = contentId;
116     }
117
118     public java.lang.Integer JavaDoc getLanguageId()
119     {
120         return this.languageId;
121     }
122         
123     public void setLanguageId(java.lang.Integer JavaDoc languageId)
124     {
125         this.languageId = languageId;
126     }
127                     
128     public void setStateId(Integer JavaDoc stateId)
129     {
130         this.stateId = stateId;
131     }
132
133     public void setVersionComment(String JavaDoc versionComment)
134     {
135         this.versionComment = versionComment;
136     }
137     
138     public String JavaDoc getVersionComment()
139     {
140         return this.versionComment;
141     }
142     
143     public Integer JavaDoc getStateId()
144     {
145         return this.stateId;
146     }
147             
148     /**
149      * @return
150      */

151     public List JavaDoc getContentVersionId()
152     {
153         return contentVersionId;
154     }
155
156     /**
157      * @param list
158      */

159     private void setContentVersionId(String JavaDoc[] list)
160     {
161         if(list != null)
162         {
163             for(int i=0; i < list.length; i++)
164             {
165                 contentVersionId.add(new Integer JavaDoc(list[i]));
166             }
167         }
168     }
169
170     private void setSiteNodeVersionId(String JavaDoc[] list)
171     {
172         if(list != null)
173         {
174             for(int i=0; i < list.length; i++)
175             {
176                 siteNodeVersionId.add(new Integer JavaDoc(list[i]));
177             }
178         }
179     }
180     public Integer JavaDoc getRepositoryId()
181     {
182         return repositoryId;
183     }
184
185     public void setAttemptDirectPublishing(String JavaDoc attemptDirectPublishing)
186     {
187         this.attemptDirectPublishing = attemptDirectPublishing;
188     }
189     
190     public void setRepositoryId(Integer JavaDoc repositoryId)
191     {
192         this.repositoryId = repositoryId;
193     }
194
195     public List JavaDoc getSiteNodeVersionId()
196     {
197         return siteNodeVersionId;
198     }
199     
200     public boolean getOverrideVersionModifyer()
201     {
202         return overrideVersionModifyer;
203     }
204     
205     public void setOverrideVersionModifyer(boolean overrideVersionModifyer)
206     {
207         this.overrideVersionModifyer = overrideVersionModifyer;
208     }
209
210     public void setReturnAddress(String JavaDoc returnAddress)
211     {
212         this.returnAddress = returnAddress;
213     }
214 }
215
Popular Tags