KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
27 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
28 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy;
29 import org.infoglue.cms.entities.content.ContentVersionVO;
30 import org.infoglue.cms.exception.ConstraintException;
31 import org.infoglue.cms.util.ConstraintExceptionBuffer;
32
33 /**
34   * This is the action-class for UpdateContentVersionVersion
35   *
36   * @author Mattias Bogeblad
37   */

38
39 public class UpdateContentVersionAction extends ViewContentVersionAction
40 {
41     private static final long serialVersionUID = 1L;
42     
43     public final static Logger logger = Logger.getLogger(UpdateContentVersionAction.class.getName());
44
45     private ContentVersionVO contentVersionVO;
46     private Integer JavaDoc contentId;
47     private Integer JavaDoc languageId;
48     private Integer JavaDoc contentVersionId;
49     private Integer JavaDoc currentEditorId;
50     private String JavaDoc attributeName;
51     private long oldModifiedDateTime = -1;
52     private boolean concurrentModification = false;
53     
54     private ConstraintExceptionBuffer ceb;
55     
56     public UpdateContentVersionAction()
57     {
58         this(new ContentVersionVO());
59     }
60     
61     public UpdateContentVersionAction(ContentVersionVO contentVersionVO)
62     {
63         this.contentVersionVO = contentVersionVO;
64         this.ceb = new ConstraintExceptionBuffer();
65     }
66     
67     public String JavaDoc doExecute() throws Exception JavaDoc
68     {
69         super.initialize(this.contentVersionId, this.contentId, this.languageId);
70         ceb.throwIfNotEmpty();
71
72         ContentVersionVO currentContentVersionVO = null;
73         if(this.contentVersionVO.getId() != null)
74         {
75             currentContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(this.contentVersionVO.getId());
76         }
77         
78         if(currentContentVersionVO != null)
79         {
80             logger.info("oldModifiedDateTime:" + oldModifiedDateTime);
81             logger.info("modifiedDateTime2:" + currentContentVersionVO.getModifiedDateTime().getTime());
82         }
83         
84         if(currentContentVersionVO == null || this.oldModifiedDateTime == currentContentVersionVO.getModifiedDateTime().getTime())
85         {
86             this.contentVersionVO.setVersionModifier(this.getInfoGluePrincipal().getName());
87             
88             try
89             {
90                 this.contentVersionVO = ContentVersionControllerProxy.getController().acUpdate(this.getInfoGluePrincipal(), this.contentId, this.languageId, this.contentVersionVO);
91                 this.oldModifiedDateTime = this.contentVersionVO.getModifiedDateTime().getTime();
92             }
93             catch(ConstraintException ce)
94             {
95                 super.contentVersionVO = this.contentVersionVO;
96                 throw ce;
97             }
98         }
99         else
100         {
101             this.contentVersionVO.setVersionModifier(this.getInfoGluePrincipal().getName());
102             super.contentVersionVO = this.contentVersionVO;
103             /*
104             ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
105             ceb.add(new ConstraintException("ContentVersion.concurrentModification", "3306"));
106             ceb.throwIfNotEmpty();
107             */

108             concurrentModification = true;
109         }
110         
111         return "success";
112     }
113
114     public String JavaDoc doStandalone() throws Exception JavaDoc
115     {
116         super.initialize(this.contentVersionId, this.contentId, this.languageId);
117         ceb.throwIfNotEmpty();
118         
119         this.contentVersionVO.setVersionModifier(this.getInfoGluePrincipal().getName());
120         this.contentVersionVO = ContentVersionControllerProxy.getController().acUpdate(this.getInfoGluePrincipal(), this.contentId, this.languageId, this.contentVersionVO);
121         
122         return "standalone";
123     }
124
125     public String JavaDoc doSaveAndExit() throws Exception JavaDoc
126     {
127         doExecute();
128                          
129         return "saveAndExit";
130     }
131
132     public String JavaDoc doSaveAndExitStandalone() throws Exception JavaDoc
133     {
134         doExecute();
135                          
136         return "saveAndExitStandalone";
137     }
138
139     public String JavaDoc doBackground() throws Exception JavaDoc
140     {
141         doExecute();
142                          
143         return "background";
144     }
145     
146     public void setContentVersionId(Integer JavaDoc contentVersionId)
147     {
148         this.contentVersionVO.setContentVersionId(contentVersionId);
149     }
150
151     public java.lang.Integer JavaDoc getContentVersionId()
152     {
153         return this.contentVersionVO.getContentVersionId();
154     }
155
156     public void setStateId(Integer JavaDoc stateId)
157     {
158         this.contentVersionVO.setStateId(stateId);
159     }
160
161     public java.lang.Integer JavaDoc getStateId()
162     {
163         return this.contentVersionVO.getStateId();
164     }
165
166     public void setContentId(Integer JavaDoc contentId)
167     {
168         this.contentId = contentId;
169     }
170
171     public java.lang.Integer JavaDoc getContentId()
172     {
173         return this.contentId;
174     }
175
176     public void setLanguageId(Integer JavaDoc languageId)
177     {
178         this.languageId = languageId;
179     }
180
181     public java.lang.Integer JavaDoc getLanguageId()
182     {
183         return this.languageId;
184     }
185         
186     public java.lang.String JavaDoc getVersionValue()
187     {
188         return this.contentVersionVO.getVersionValue();
189     }
190         
191     public void setVersionValue(java.lang.String JavaDoc versionValue)
192     {
193         this.contentVersionVO.setVersionValue(versionValue);
194     }
195     
196     public Integer JavaDoc getCurrentEditorId()
197     {
198         return currentEditorId;
199     }
200
201     public void setCurrentEditorId(Integer JavaDoc integer)
202     {
203         currentEditorId = integer;
204     }
205
206     public String JavaDoc getAttributeName()
207     {
208         return this.attributeName;
209     }
210
211     public String JavaDoc getVersionComment()
212     {
213         return this.contentVersionVO.getVersionComment();
214     }
215     
216     public void setAttributeName(String JavaDoc attributeName)
217     {
218         this.attributeName = attributeName;
219     }
220
221     public long getOldModifiedDateTime()
222     {
223         return oldModifiedDateTime;
224     }
225
226     public void setOldModifiedDateTime(long oldModifiedDateTime)
227     {
228         this.oldModifiedDateTime = oldModifiedDateTime;
229     }
230
231     public boolean getConcurrentModification()
232     {
233         return concurrentModification;
234     }
235
236 }
237
Popular Tags