KickJava   Java API By Example, From Geeks To Geeks.

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


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.structuretool.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.RepositoryController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
37 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeControllerProxy;
38 import org.infoglue.cms.entities.structure.SiteNodeVO;
39 import org.infoglue.cms.util.ConstraintExceptionBuffer;
40 import org.infoglue.cms.util.dom.DOMBuilder;
41
42 /**
43  * This action represents the CreateSiteNode Usecase.
44  */

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