KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > structuretool > actions > ChangeMultiSiteNodeVersionStatePublishAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue SiteNode 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.structuretool.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.common.actions.InfoGlueAbstractAction;
32 import org.infoglue.cms.applications.mydesktoptool.actions.ViewMyDesktopToolStartPageAction;
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  * This class implements submit to publish on many sitenode versions at once.
44  *
45  * @author Mattias Bogeblad
46  */

47
48 public class ChangeMultiSiteNodeVersionStatePublishAction extends InfoGlueAbstractAction
49 {
50     private final static Logger logger = Logger.getLogger(ChangeMultiSiteNodeVersionStatePublishAction.class.getName());
51
52     private Integer JavaDoc siteNodeId;
53     private List JavaDoc siteNodeVersionId = new ArrayList JavaDoc();
54     private List JavaDoc contentVersionId = new ArrayList JavaDoc();
55     private Integer JavaDoc stateId;
56     private String JavaDoc versionComment;
57     private boolean overrideVersionModifyer = false;
58     private Integer JavaDoc repositoryId;
59     private String JavaDoc attemptDirectPublishing = "false";
60     private String JavaDoc returnAddress;
61                 
62     /**
63      * This method gets called when calling this action.
64      * If the stateId is 2 which equals that the user tries to prepublish the page. If so we
65      * ask the user for a comment as this is to be regarded as a new version.
66      */

67        
68     public String JavaDoc doExecute() throws Exception JavaDoc
69     {
70         setSiteNodeVersionId( getRequest().getParameterValues("selSiteNodeVersions") );
71         Iterator JavaDoc it = siteNodeVersionId.iterator();
72
73         List JavaDoc events = new ArrayList JavaDoc();
74         while(it.hasNext())
75         {
76             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)it.next();
77             logger.info("Publishing:" + siteNodeVersionId);
78             SiteNodeVersion siteNodeVersion = SiteNodeStateController.getController().changeState(siteNodeVersionId, SiteNodeVersionVO.PUBLISH_STATE, getVersionComment(), this.overrideVersionModifyer, this.getInfoGluePrincipal(), null, events);
79         }
80
81         setContentVersionId( getRequest().getParameterValues("selContentVersions") );
82         Iterator JavaDoc contentVersionIdsIterator = contentVersionId.iterator();
83
84         while(contentVersionIdsIterator.hasNext())
85         {
86             Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdsIterator.next();
87             logger.info("Publishing:" + contentVersionId);
88             ContentVersion contentVersion = ContentStateController.changeState(contentVersionId, ContentVersionVO.PUBLISH_STATE, getVersionComment(), this.overrideVersionModifyer, this.getInfoGluePrincipal(), null, events);
89         }
90
91         if(attemptDirectPublishing.equalsIgnoreCase("true"))
92         {
93             PublicationVO publicationVO = new PublicationVO();
94             publicationVO.setName("Direct publication by " + this.getInfoGluePrincipal().getName());
95             publicationVO.setDescription(getVersionComment());
96             publicationVO.setRepositoryId(repositoryId);
97             publicationVO = PublicationController.getController().createAndPublish(publicationVO, events, overrideVersionModifyer, this.getInfoGluePrincipal());
98         }
99
100         if(this.returnAddress != null && !this.returnAddress.equals(""))
101         {
102             this.returnAddress = this.getResponse().encodeURL(returnAddress);
103             this.getResponse().sendRedirect(returnAddress);
104     
105             return NONE;
106         }
107         else
108         {
109             return "success";
110         }
111     }
112         
113     public java.lang.Integer JavaDoc getSiteNodeId()
114     {
115         return this.siteNodeId;
116     }
117         
118     public void setSiteNodeId(java.lang.Integer JavaDoc siteNodeId)
119     {
120         this.siteNodeId = siteNodeId;
121     }
122                     
123     public void setStateId(Integer JavaDoc stateId)
124     {
125         this.stateId = stateId;
126     }
127
128     public void setVersionComment(String JavaDoc versionComment)
129     {
130         this.versionComment = versionComment;
131     }
132     
133     public String JavaDoc getVersionComment()
134     {
135         return this.versionComment;
136     }
137     
138     public Integer JavaDoc getStateId()
139     {
140         return this.stateId;
141     }
142
143     private void setSiteNodeVersionId(String JavaDoc[] list)
144     {
145         if(list != null)
146         {
147             for(int i=0; i < list.length; i++)
148             {
149                 siteNodeVersionId.add(new Integer JavaDoc(list[i]));
150             }
151         }
152     }
153
154     private void setContentVersionId(String JavaDoc[] list)
155     {
156         if(list != null)
157         {
158             for(int i=0; i < list.length; i++)
159             {
160                 contentVersionId.add(new Integer JavaDoc(list[i]));
161             }
162         }
163     }
164
165     
166     public Integer JavaDoc getRepositoryId()
167     {
168         return repositoryId;
169     }
170     
171     public void setRepositoryId(Integer JavaDoc repositoryId)
172     {
173         this.repositoryId = repositoryId;
174     }
175     
176     public void setAttemptDirectPublishing(String JavaDoc attemptDirectPublishing)
177     {
178         this.attemptDirectPublishing = attemptDirectPublishing;
179     }
180     
181     public boolean getOverrideVersionModifyer()
182     {
183         return overrideVersionModifyer;
184     }
185     
186     public void setOverrideVersionModifyer(boolean overrideVersionModifyer)
187     {
188         this.overrideVersionModifyer = overrideVersionModifyer;
189     }
190
191     public String JavaDoc getReturnAddress() {
192         return returnAddress;
193     }
194
195     public void setReturnAddress(String JavaDoc returnAddress) {
196         this.returnAddress = returnAddress;
197     }
198 }
199
Popular Tags