1 23 24 package org.infoglue.cms.applications.contenttool.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.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 45 46 public class MoveMultipleContentAction extends InfoGlueAbstractAction 47 { 48 private static final long serialVersionUID = 1L; 49 50 private Integer originalContentId; 52 private Integer repositoryId; 53 private Integer contentId; 54 private Integer parentContentId; 55 private List qualifyers = new ArrayList (); 56 private boolean errorsOccurred = false; 57 protected List repositories = null; 58 59 protected String qualifyerXML = null; 61 private Integer newParentContentId; 62 63 private Integer changeTypeId; 65 private Integer 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 contentId) 83 { 84 this.contentVO.setContentId(contentId); 85 } 86 87 public void setNewParentContentId(Integer newParentContentId) 88 { 89 this.newParentContentId = newParentContentId; 90 } 91 92 public void setParentContentId(Integer parentContentId) 93 { 94 this.parentContentId = parentContentId; 95 } 96 97 public void setChangeTypeId(Integer changeTypeId) 98 { 99 this.changeTypeId = changeTypeId; 100 } 101 102 public void setRepositoryId(Integer repositoryId) 103 { 104 this.repositoryId = repositoryId; 105 } 106 107 public Integer getRepositoryId() 108 { 109 return this.repositoryId; 110 } 111 112 public Integer getParentContentId() 113 { 114 return this.parentContentId; 115 } 116 117 public Integer getContentId() 118 { 119 return contentVO.getContentId(); 120 } 121 122 public Integer getNewParentContentId() 123 { 124 return this.newParentContentId; 125 } 126 127 public Integer getUnrefreshedContentId() 128 { 129 return this.newParentContentId; 130 } 131 132 public Integer getChangeTypeId() 133 { 134 return this.changeTypeId; 135 } 136 137 public String doInput() throws Exception 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 doExecute() throws Exception 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 contents = parseContentsFromXML(this.qualifyerXML); 170 Iterator 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 e) 179 { 180 this.errorsOccurred = true; 181 } 182 } 183 } 184 } 185 catch(Exception 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 parseContentsFromXML(String qualifyerXML) 197 { 198 List contents = new ArrayList (); 199 200 try 201 { 202 Document document = new DOMBuilder().getDocument(qualifyerXML); 203 204 String entity = document.getRootElement().attributeValue("entity"); 205 206 Map addedContents = new HashMap (); 207 208 List children = document.getRootElement().elements(); 209 Iterator i = children.iterator(); 210 while(i.hasNext()) 211 { 212 Element child = (Element)i.next(); 213 String id = child.getStringValue(); 214 String path = child.attributeValue("path"); 215 216 if(!addedContents.containsKey(id)) 217 { 218 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer (id)); 219 contents.add(contentVO); 220 addedContents.put(id, contentVO); 221 } 222 } 223 } 224 catch(Exception e) 225 { 226 e.printStackTrace(); 227 } 228 229 return contents; 230 } 231 232 public String getErrorKey() 233 { 234 return "Content.parentContentId"; 235 } 236 237 public String getReturnAddress() 238 { 239 return "ViewContent.action?contentId=" + this.contentVO.getId() + "&repositoryId=" + this.repositoryId; 240 } 241 242 public String getQualifyerXML() 243 { 244 return qualifyerXML; 245 } 246 247 public void setQualifyerXML(String qualifyerXML) 248 { 249 this.qualifyerXML = qualifyerXML; 250 } 251 252 public List getQualifyers() 253 { 254 return qualifyers; 255 } 256 257 public Integer getOriginalContentId() 258 { 259 return originalContentId; 260 } 261 262 public void setOriginalContentId(Integer originalContentId) 263 { 264 this.originalContentId = originalContentId; 265 } 266 267 public Integer getTopContentId() 268 { 269 return topContentId; 270 } 271 272 public boolean getErrorsOccurred() 273 { 274 return errorsOccurred; 275 } 276 277 public List getRepositories() 278 { 279 return repositories; 280 } 281 } 282 | Popular Tags |