1 23 24 package org.infoglue.cms.applications.contenttool.actions; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.dom4j.Document; 31 import org.dom4j.Element; 32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.GroupPropertiesController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.RolePropertiesController; 37 import org.infoglue.cms.controllers.kernel.impl.simple.UserPropertiesController; 38 import org.infoglue.cms.entities.management.GroupProperties; 39 import org.infoglue.cms.entities.management.RoleProperties; 40 import org.infoglue.cms.entities.management.UserProperties; 41 import org.infoglue.cms.entities.structure.QualifyerVO; 42 import org.infoglue.cms.util.ConstraintExceptionBuffer; 43 import org.infoglue.cms.util.dom.DOMBuilder; 44 45 48 49 public abstract class ViewRelationEditorAction extends InfoGlueAbstractAction 50 { 51 protected Integer entityId = null; 53 protected String entityName = null; 54 protected String attributeName = null; 56 protected String updateAction = null; 57 58 protected Integer repositoryId = null; 59 protected ConstraintExceptionBuffer ceb = null; 60 protected String qualifyerXML = null; 61 protected String relationXML = null; 62 protected String tree = null; 63 protected List repositories = null; 64 protected String path = null; 65 protected List qualifyers = null; 66 protected String currentAction = null; 67 protected String changeRepositoryAction = null; 68 protected String currentEntity = null; 69 protected String currentEntityIdentifyer = null; 70 71 92 93 public void setEntityId(Integer entityId) 94 { 95 this.entityId = entityId; 96 } 97 98 public Integer getEntityId() 99 { 100 return this.entityId; 101 } 102 103 public String getAttributeName() 104 { 105 return attributeName; 106 } 107 108 public void setAttributeName(String attributeName) 109 { 110 this.attributeName = attributeName; 111 } 112 113 public void setRepositoryId(Integer repositoryId) 114 { 115 this.repositoryId = repositoryId; 116 } 117 118 public void setPath(String path) 119 { 120 this.path = path; 121 } 122 123 public Integer getRepositoryId() 124 { 125 return this.repositoryId; 126 } 127 128 public void setQualifyerXML(String qualifyerXML) 129 { 130 this.qualifyerXML = qualifyerXML; 131 } 132 133 public String getQualifyerXML() 134 { 135 return this.qualifyerXML; 136 } 137 138 public String getTree() 139 { 140 return this.tree; 141 } 142 143 public void setTree(String tree) 144 { 145 this.tree = tree; 146 } 147 148 public List getQualifyers() 149 { 150 return this.qualifyers; 151 } 152 153 public String getCurrentEntity() 154 { 155 return this.currentEntity; 156 } 157 158 public void setCurrentEntity(String currentEntity) 159 { 160 this.currentEntity = currentEntity; 161 } 162 163 public String getCurrentEntityIdentifyer() 164 { 165 return this.currentEntityIdentifyer; 166 } 167 168 public void setCurrentEntityIdentifyer(String currentEntityIdentifyer) 169 { 170 this.currentEntityIdentifyer = currentEntityIdentifyer; 171 } 172 173 public String getCurrentAction() 174 { 175 return this.currentAction; 176 } 177 178 public String getChangeRepositoryAction() 179 { 180 return this.changeRepositoryAction; 181 } 182 183 public List getRepositories() 184 { 185 return repositories; 186 } 187 188 public String getUpdateAction() 189 { 190 return updateAction; 191 } 192 193 public void setUpdateAction(String updateAction) 194 { 195 this.updateAction = updateAction; 196 } 197 198 public String getEntityName() 199 { 200 return entityName; 201 } 202 203 public void setEntityName(String entityName) 204 { 205 this.entityName = entityName; 206 } 207 208 public abstract String getQualifyerPath(String entityId); 209 210 211 215 216 protected void initialize() throws Exception 217 { 218 this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true); 219 220 if(this.repositoryId == null) 221 { 222 this.repositoryId = (Integer )getHttpSession().getAttribute("repositoryId"); 223 if(this.repositoryId == null) 224 this.repositoryId = RepositoryController.getController().getFirstRepositoryVO().getRepositoryId(); 225 } 226 227 this.relationXML = getXML(); 229 230 boolean isFormDefinitionValid = true; 231 try 232 { 233 if(this.relationXML != null && this.relationXML.length() != 0) 234 { 235 Document document = new DOMBuilder().getDocument(this.relationXML); 236 this.qualifyers = parseQualifyersFromXML(this.relationXML); 237 } 238 else 239 isFormDefinitionValid = false; 240 } 241 catch(Exception e) 242 { 243 isFormDefinitionValid = false; 244 } 245 } 246 247 250 251 public String doExecute() throws Exception 252 { 253 initialize(); 254 255 return "success"; 256 } 257 258 public String doChangeRepository() throws Exception 259 { 260 initialize(); 261 262 return "success"; 263 } 264 265 268 269 public String doUpdateQualifyer() throws Exception 270 { 271 updateAttributeValue(); 272 273 initialize(); 274 275 return "success"; 276 } 277 278 281 public String doUpdateQualifyerInEntityProperties() throws Exception 282 { 283 if(this.entityName.equalsIgnoreCase(UserProperties.class.getName())) 284 UserPropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML); 285 else if(this.entityName.equalsIgnoreCase(RoleProperties.class.getName())) 286 RolePropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML); 287 else if(this.entityName.equalsIgnoreCase(GroupProperties.class.getName())) 288 GroupPropertiesController.getController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML); 289 290 initialize(); 291 292 return "success"; 293 } 294 295 296 private List parseQualifyersFromXML(String qualifyerXML) 297 { 298 List qualifyers = new ArrayList (); 299 300 try 301 { 302 Document document = new DOMBuilder().getDocument(qualifyerXML); 303 304 String entity = document.getRootElement().attributeValue("entity"); 305 306 List children = document.getRootElement().elements(); 307 Iterator i = children.iterator(); 308 while(i.hasNext()) 309 { 310 Element child = (Element)i.next(); 311 String id = child.getStringValue(); 312 313 QualifyerVO qualifyerVO = new QualifyerVO(); 314 qualifyerVO.setName(this.getCurrentEntityIdentifyer()); 315 qualifyerVO.setValue(id); 316 qualifyerVO.setPath(this.getQualifyerPath(id)); 317 qualifyers.add(qualifyerVO); 319 } 320 } 321 catch(Exception e) 322 { 323 e.printStackTrace(); 324 } 325 326 return qualifyers; 327 } 328 329 332 333 public String getXML() 334 { 335 try 336 { 337 if(this.entityName.equalsIgnoreCase(UserProperties.class.getName())) 338 return UserPropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false); 339 if(this.entityName.equalsIgnoreCase(RoleProperties.class.getName())) 340 return RolePropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false); 341 else if(this.entityName.equalsIgnoreCase(GroupProperties.class.getName())) 342 return GroupPropertiesController.getController().getAttributeValue(getEntityId(), getAttributeName(), false); 343 else 344 return ContentVersionController.getContentVersionController().getAttributeValue(getEntityId(), getAttributeName(), false); 345 } 346 catch(Exception e) 347 { 348 e.printStackTrace(); 349 } 350 return ""; 351 } 352 353 356 357 public void updateAttributeValue() throws Exception 358 { 359 ContentVersionController.getContentVersionController().updateAttributeValue(getEntityId(), getAttributeName(), this.qualifyerXML, this.getInfoGluePrincipal()); 360 } 361 362 363 364 } 365 | Popular Tags |