KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.dom4j.Document;
33 import org.dom4j.Element;
34 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
37 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
38 import org.infoglue.cms.entities.content.ContentVO;
39 import org.infoglue.cms.util.ConstraintExceptionBuffer;
40 import org.infoglue.cms.util.dom.DOMBuilder;
41
42 /**
43  * This action represents the CreateContent Usecase.
44  */

45
46 public class MoveMultipleContentAction extends InfoGlueAbstractAction
47 {
48     private static final long serialVersionUID = 1L;
49     
50     //Initial params
51
private Integer JavaDoc originalContentId;
52     private Integer JavaDoc repositoryId;
53     private Integer JavaDoc contentId;
54     private Integer JavaDoc parentContentId;
55     private List JavaDoc qualifyers = new ArrayList JavaDoc();
56     private boolean errorsOccurred = false;
57     protected List JavaDoc repositories = null;
58     
59     //Move params
60
protected String JavaDoc qualifyerXML = null;
61     private Integer JavaDoc newParentContentId;
62     
63     //Tree params
64
private Integer JavaDoc changeTypeId;
65     private Integer JavaDoc topContentId;
66
67     private ConstraintExceptionBuffer ceb;
68     private ContentVO contentVO;
69   
70   
71     public MoveMultipleContentAction()
72     {
73         this(new ContentVO());
74     }
75     
76     public MoveMultipleContentAction(ContentVO contentVO)
77     {
78         this.contentVO = contentVO;
79         this.ceb = new ConstraintExceptionBuffer();
80     }
81
82     public void setContentId(Integer JavaDoc contentId)
83     {
84         this.contentVO.setContentId(contentId);
85     }
86
87     public void setNewParentContentId(Integer JavaDoc newParentContentId)
88     {
89         this.newParentContentId = newParentContentId;
90     }
91
92     public void setParentContentId(Integer JavaDoc parentContentId)
93     {
94         this.parentContentId = parentContentId;
95     }
96
97     public void setChangeTypeId(Integer JavaDoc changeTypeId)
98     {
99         this.changeTypeId = changeTypeId;
100     }
101
102     public void setRepositoryId(Integer JavaDoc repositoryId)
103     {
104         this.repositoryId = repositoryId;
105     }
106     
107     public Integer JavaDoc getRepositoryId()
108     {
109         return this.repositoryId;
110     }
111
112     public Integer JavaDoc getParentContentId()
113     {
114         return this.parentContentId;
115     }
116         
117     public Integer JavaDoc getContentId()
118     {
119         return contentVO.getContentId();
120     }
121
122     public Integer JavaDoc getNewParentContentId()
123     {
124         return this.newParentContentId;
125     }
126     
127     public Integer JavaDoc getUnrefreshedContentId()
128     {
129         return this.newParentContentId;
130     }
131
132     public Integer JavaDoc getChangeTypeId()
133     {
134         return this.changeTypeId;
135     }
136      
137     public String JavaDoc doInput() throws Exception JavaDoc
138     {
139         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
140
141         if(this.qualifyerXML != null && !this.qualifyerXML.equals(""))
142         {
143             this.qualifyers = parseContentsFromXML(this.qualifyerXML);
144         }
145         else
146         {
147             ContentVO contentVO = ContentController.getContentController().getContentVOWithId(getContentId());
148             this.qualifyers.add(contentVO);
149         }
150         
151         return "input";
152     }
153     
154     public String JavaDoc doExecute() throws Exception JavaDoc
155     {
156         if(this.newParentContentId == null)
157         {
158             this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
159             return "chooseDestination";
160         }
161         
162         ceb.throwIfNotEmpty();
163         
164         try
165         {
166             if(this.qualifyerXML != null && this.qualifyerXML.length() != 0)
167             {
168                 Document document = new DOMBuilder().getDocument(this.qualifyerXML);
169                 List JavaDoc contents = parseContentsFromXML(this.qualifyerXML);
170                 Iterator JavaDoc i = contents.iterator();
171                 while(i.hasNext())
172                 {
173                     ContentVO contentVO = (ContentVO)i.next();
174                     try
175                     {
176                         ContentControllerProxy.getController().acMoveContent(this.getInfoGluePrincipal(), contentVO, this.newParentContentId);
177                     }
178                     catch(Exception JavaDoc e)
179                     {
180                         this.errorsOccurred = true;
181                     }
182                 }
183             }
184         }
185         catch(Exception JavaDoc e)
186         {
187             e.printStackTrace();
188         }
189         
190         this.topContentId = ContentController.getContentController().getRootContentVO(this.repositoryId, this.getInfoGluePrincipal().getName()).getContentId();
191             
192         return "success";
193     }
194
195     
196     private List JavaDoc parseContentsFromXML(String JavaDoc qualifyerXML)
197     {
198         List JavaDoc contents = new ArrayList JavaDoc();
199         
200         try
201         {
202             Document document = new DOMBuilder().getDocument(qualifyerXML);
203             
204             String JavaDoc entity = document.getRootElement().attributeValue("entity");
205             
206             Map JavaDoc addedContents = new HashMap JavaDoc();
207             
208             List JavaDoc children = document.getRootElement().elements();
209             Iterator JavaDoc i = children.iterator();
210             while(i.hasNext())
211             {
212                 Element child = (Element)i.next();
213                 String JavaDoc id = child.getStringValue();
214                 String JavaDoc path = child.attributeValue("path");
215                 
216                 if(!addedContents.containsKey(id))
217                 {
218                     ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer JavaDoc(id));
219                     contents.add(contentVO);
220                     addedContents.put(id, contentVO);
221                 }
222             }
223         }
224         catch(Exception JavaDoc e)
225         {
226             e.printStackTrace();
227         }
228         
229         return contents;
230     }
231     
232     public String JavaDoc getErrorKey()
233     {
234         return "Content.parentContentId";
235     }
236     
237     public String JavaDoc getReturnAddress()
238     {
239         return "ViewContent.action?contentId=" + this.contentVO.getId() + "&repositoryId=" + this.repositoryId;
240     }
241     
242     public String JavaDoc getQualifyerXML()
243     {
244         return qualifyerXML;
245     }
246     
247     public void setQualifyerXML(String JavaDoc qualifyerXML)
248     {
249         this.qualifyerXML = qualifyerXML;
250     }
251     
252     public List JavaDoc getQualifyers()
253     {
254         return qualifyers;
255     }
256     
257     public Integer JavaDoc getOriginalContentId()
258     {
259         return originalContentId;
260     }
261     
262     public void setOriginalContentId(Integer JavaDoc originalContentId)
263     {
264         this.originalContentId = originalContentId;
265     }
266     
267     public Integer JavaDoc getTopContentId()
268     {
269         return topContentId;
270     }
271     
272     public boolean getErrorsOccurred()
273     {
274         return errorsOccurred;
275     }
276     
277     public List JavaDoc getRepositories()
278     {
279         return repositories;
280     }
281 }
282
Popular Tags