1 23 24 package org.infoglue.cms.applications.structuretool.actions; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 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 45 46 public class MoveMultipleSiteNodeAction extends InfoGlueAbstractAction 47 { 48 49 private Integer originalSiteNodeId; 51 private Integer repositoryId; 52 private Integer siteNodeId; 53 private Integer parentSiteNodeId; 54 private List qualifyers = new ArrayList (); 55 private boolean errorsOccurred = false; 56 protected List repositories = null; 57 58 protected String qualifyerXML = null; 60 private Integer newParentSiteNodeId; 61 62 private Integer changeTypeId; 64 private Integer 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 siteNodeId) 82 { 83 this.siteNodeVO.setSiteNodeId(siteNodeId); 84 } 85 86 public Integer getSiteNodeId() 87 { 88 return siteNodeVO.getSiteNodeId(); 89 } 90 91 92 public String doInput() throws Exception 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 doExecute() throws Exception 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 siteNodes = parseSiteNodesFromXML(this.qualifyerXML); 125 Iterator 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 e) 134 { 135 this.errorsOccurred = true; 136 } 137 } 138 } 139 } 140 catch(Exception 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 parseSiteNodesFromXML(String qualifyerXML) 151 { 152 List siteNodes = new ArrayList (); 153 154 try 155 { 156 Document document = new DOMBuilder().getDocument(qualifyerXML); 157 158 String entity = document.getRootElement().attributeValue("entity"); 159 160 Map addedSiteNodes = new HashMap (); 161 162 List children = document.getRootElement().elements(); 163 Iterator i = children.iterator(); 164 while(i.hasNext()) 165 { 166 Element child = (Element)i.next(); 167 String id = child.getStringValue(); 168 String path = child.attributeValue("path"); 169 170 if(!addedSiteNodes.containsKey(id)) 171 { 172 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(new Integer (id)); 173 siteNodes.add(siteNodeVO); 174 addedSiteNodes.put(id, siteNodeVO); 175 } 176 } 177 } 178 catch(Exception e) 179 { 180 e.printStackTrace(); 181 } 182 183 return siteNodes; 184 } 185 186 187 public Integer getChangeTypeId() 188 { 189 return changeTypeId; 190 } 191 192 public void setChangeTypeId(Integer changeTypeId) 193 { 194 this.changeTypeId = changeTypeId; 195 } 196 197 public Integer getNewParentSiteNodeId() 198 { 199 return newParentSiteNodeId; 200 } 201 202 public void setNewParentSiteNodeId(Integer newParentSiteNodeId) 203 { 204 this.newParentSiteNodeId = newParentSiteNodeId; 205 } 206 207 public Integer getOriginalSiteNodeId() 208 { 209 return originalSiteNodeId; 210 } 211 212 public void setOriginalSiteNodeId(Integer originalSiteNodeId) 213 { 214 this.originalSiteNodeId = originalSiteNodeId; 215 } 216 217 public Integer getParentSiteNodeId() 218 { 219 return parentSiteNodeId; 220 } 221 222 public void setParentSiteNodeId(Integer parentSiteNodeId) 223 { 224 this.parentSiteNodeId = parentSiteNodeId; 225 } 226 227 public String getQualifyerXML() 228 { 229 return qualifyerXML; 230 } 231 232 public void setQualifyerXML(String qualifyerXML) 233 { 234 this.qualifyerXML = qualifyerXML; 235 } 236 237 public Integer getRepositoryId() 238 { 239 return repositoryId; 240 } 241 242 public void setRepositoryId(Integer repositoryId) 243 { 244 this.repositoryId = repositoryId; 245 } 246 247 public Integer getTopSiteNodeId() 248 { 249 return topSiteNodeId; 250 } 251 252 public void setTopSiteNodeId(Integer topSiteNodeId) 253 { 254 this.topSiteNodeId = topSiteNodeId; 255 } 256 257 public boolean isErrorsOccurred() 258 { 259 return errorsOccurred; 260 } 261 262 public List getQualifyers() 263 { 264 return qualifyers; 265 } 266 267 public List getRepositories() 268 { 269 return repositories; 270 } 271 272 public SiteNodeVO getSiteNodeVO() 273 { 274 return siteNodeVO; 275 } 276 } 277 | Popular Tags |