1 23 24 package org.infoglue.cms.applications.contenttool.wizards.actions; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 import org.infoglue.cms.applications.common.VisualFormatter; 30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 31 import org.infoglue.cms.applications.contenttool.actions.ViewContentTreeActionInterface; 32 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController; 37 import org.infoglue.cms.entities.content.ContentVO; 38 import org.infoglue.cms.entities.content.ContentVersionVO; 39 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 40 import org.infoglue.cms.entities.management.LanguageVO; 41 import org.infoglue.cms.entities.management.RepositoryVO; 42 import org.infoglue.cms.exception.AccessConstraintException; 43 import org.infoglue.cms.exception.Bug; 44 import org.infoglue.cms.exception.ConstraintException; 45 import org.infoglue.cms.exception.SystemException; 46 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 47 import org.infoglue.cms.util.ConstraintExceptionBuffer; 48 49 53 54 public class CreateContentWizardAction extends InfoGlueAbstractAction implements ViewContentTreeActionInterface 55 { 56 private static final long serialVersionUID = 1L; 57 58 private Integer contentId; 60 private String tree; 61 private String hideLeafs; 62 63 private String [] allowedContentTypeDefinitionId; 65 private List contentTypeDefinitionVOList = new ArrayList (); 66 67 public ContentTypeDefinitionVO contentTypeDefinitionVO; 69 public List availableLanguages = null; 70 private Integer languageId; 71 private Integer contentVersionId; 72 private Integer currentEditorId; 73 private String attributeName = ""; 74 private String textAreaId = ""; 75 private ContentVersionVO contentVersionVO; 76 public List attributes = null; 77 78 private Integer parentContentId; 80 private Integer contentTypeDefinitionId; 81 private Integer repositoryId; 82 private ConstraintExceptionBuffer ceb; 83 private ContentVO contentVO; 84 private ContentVO newContentVO; 85 86 protected void initialize(Integer contentVersionId, Integer contentId, Integer languageId) throws Exception 87 { 88 this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId); 89 this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentId); 91 this.availableLanguages = ContentController.getContentController().getRepositoryLanguages(contentId); 92 93 this.languageId = ((LanguageVO)this.availableLanguages.get(0)).getLanguageId(); 94 108 109 this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().validateAndUpdateContentType(this.contentTypeDefinitionVO); 110 this.attributes = ContentTypeDefinitionController.getController().getContentTypeAttributes(this.contentTypeDefinitionVO.getSchemaValue()); 111 } 112 113 119 120 public String doInput() throws Exception 121 { 122 if(parentContentId == null) 123 { 124 return "stateLocation"; 125 } 126 127 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 128 129 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(parentContentId); 130 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", protectedContentId.toString())) 131 ceb.add(new AccessConstraintException("Content.contentId", "1002")); 132 133 136 ceb.throwIfNotEmpty(); 137 138 if(allowedContentTypeDefinitionId == null) 139 { 140 this.contentTypeDefinitionVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList(); 141 } 142 else 143 { 144 for(int i=0; i < allowedContentTypeDefinitionId.length; i++) 145 { 146 String allowedContentTypeDefinitionIdString = allowedContentTypeDefinitionId[i]; 147 this.contentTypeDefinitionVOList.add(ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(new Integer (allowedContentTypeDefinitionIdString))); 148 } 149 } 150 151 return "input"; 152 } 153 154 public String doCreateContent() throws Exception 155 { 156 this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName()); 157 158 ceb = this.contentVO.validate(); 159 ceb.throwIfNotEmpty(); 160 161 newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO); 162 163 this.initialize(this.contentVersionId, newContentVO.getContentId(), this.languageId); 164 165 return "createContentSuccess"; 166 } 167 168 public String doExecute() throws Exception 169 { 170 this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName()); 171 172 ceb = this.contentVO.validate(); 173 ceb.throwIfNotEmpty(); 174 175 newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO); 176 177 return "success"; 178 } 179 180 public Integer getTopRepositoryId() throws ConstraintException, SystemException, Bug 181 { 182 List repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false); 183 184 Integer topRepositoryId = null; 185 186 if (repositoryId != null) 187 topRepositoryId = repositoryId; 188 189 if(repositories.size() > 0) 190 { 191 topRepositoryId = ((RepositoryVO)repositories.get(0)).getRepositoryId(); 192 } 193 194 return topRepositoryId; 195 } 196 197 public CreateContentWizardAction() 198 { 199 this(new ContentVO()); 200 } 201 202 public CreateContentWizardAction(ContentVO contentVO) 203 { 204 this.contentVO = contentVO; 205 this.ceb = new ConstraintExceptionBuffer(); 206 } 207 208 public void setContentId(Integer contentId) 209 { 210 this.contentId = contentId; 211 } 212 213 public Integer getContentId() 214 { 215 return this.contentId; 216 } 217 218 public void setHideLeafs(String hideLeafs) 219 { 220 this.hideLeafs = hideLeafs; 221 } 222 223 public String getHideLeafs() 224 { 225 return this.hideLeafs; 226 } 227 228 public String getTree() 229 { 230 return tree; 231 } 232 233 public void setTree(String tree) 234 { 235 this.tree = tree; 236 } 237 238 239 240 public void setParentContentId(Integer parentContentId) 241 { 242 this.parentContentId = parentContentId; 243 } 244 245 public Integer getParentContentId() 246 { 247 return this.parentContentId; 248 } 249 250 public void setRepositoryId(Integer repositoryId) 251 { 252 this.repositoryId = repositoryId; 253 } 254 255 258 259 public Integer getRepositoryId() 260 { 261 try 262 { 263 if(this.repositoryId == null) 264 { 265 this.repositoryId = (Integer )getHttpSession().getAttribute("repositoryId"); 266 267 if(this.repositoryId == null) 268 { 269 this.repositoryId = getTopRepositoryId(); 270 getHttpSession().setAttribute("repositoryId", this.repositoryId); 271 } 272 } 273 } 274 catch(Exception e) 275 { 276 } 277 278 return repositoryId; 279 } 280 281 public void setContentTypeDefinitionId(Integer contentTypeDefinitionId) 282 { 283 this.contentTypeDefinitionId = contentTypeDefinitionId; 284 } 285 286 public Integer getContentTypeDefinitionId() 287 { 288 return this.contentTypeDefinitionId; 289 } 290 291 public java.lang.String getName() 292 { 293 return this.contentVO.getName(); 294 } 295 296 public String getPublishDateTime() 297 { 298 return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm"); 299 } 300 301 public String getExpireDateTime() 302 { 303 return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm"); 304 } 305 306 public long getPublishDateTimeAsLong() 307 { 308 return this.contentVO.getPublishDateTime().getTime(); 309 } 310 311 public long getExpireDateTimeAsLong() 312 { 313 return this.contentVO.getExpireDateTime().getTime(); 314 } 315 316 public Boolean getIsBranch() 317 { 318 return this.contentVO.getIsBranch(); 319 } 320 321 public void setName(java.lang.String name) 322 { 323 this.contentVO.setName(name); 324 } 325 326 public void setPublishDateTime(String publishDateTime) 327 { 328 this.contentVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm")); 329 } 330 331 public void setExpireDateTime(String expireDateTime) 332 { 333 this.contentVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm")); 334 } 335 336 public void setIsBranch(Boolean isBranch) 337 { 338 this.contentVO.setIsBranch(isBranch); 339 } 340 341 public Integer getNewContentId() 342 { 343 return newContentVO.getContentId(); 344 } 345 346 347 public List getContentTypeDefinitions() throws Exception 348 { 349 return ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList(); 350 } 351 352 393 394 public String [] getAllowedContentTypeDefinitionId() 395 { 396 return allowedContentTypeDefinitionId; 397 } 398 399 public void setAllowedContentTypeDefinitionId(String [] strings) 400 { 401 allowedContentTypeDefinitionId = strings; 402 } 403 404 public java.lang.Integer getContentVersionId() 405 { 406 return this.contentVersionVO.getContentVersionId(); 407 } 408 409 public void setContentVersionId(java.lang.Integer contentVersionId) 410 { 411 this.contentVersionVO.setContentVersionId(contentVersionId); 412 } 413 public List getAttributes() 414 { 415 return attributes; 416 } 417 418 public List getAvailableLanguages() 419 { 420 return availableLanguages; 421 } 422 423 public ContentTypeDefinitionVO getContentTypeDefinitionVO() 424 { 425 return contentTypeDefinitionVO; 426 } 427 428 public ContentVersionVO getContentVersionVO() 429 { 430 return contentVersionVO; 431 } 432 433 public ContentVO getContentVO() 434 { 435 return contentVO; 436 } 437 438 public Integer getCurrentEditorId() 439 { 440 return currentEditorId; 441 } 442 443 public Integer getLanguageId() 444 { 445 return languageId; 446 } 447 448 public ContentVO getNewContentVO() 449 { 450 return newContentVO; 451 } 452 453 public String getTextAreaId() 454 { 455 return textAreaId; 456 } 457 458 public void setAttributes(List list) 459 { 460 attributes = list; 461 } 462 463 466 467 public List getContentTypeAttributes() 468 { 469 return this.attributes; 470 } 471 472 public void setAvailableLanguages(List list) 473 { 474 availableLanguages = list; 475 } 476 477 public void setContentTypeDefinitionVO(ContentTypeDefinitionVO definitionVO) 478 { 479 contentTypeDefinitionVO = definitionVO; 480 } 481 482 public void setContentVersionVO(ContentVersionVO versionVO) 483 { 484 contentVersionVO = versionVO; 485 } 486 487 public void setContentVO(ContentVO contentVO) 488 { 489 this.contentVO = contentVO; 490 } 491 492 public void setCurrentEditorId(Integer integer) 493 { 494 currentEditorId = integer; 495 } 496 497 public void setLanguageId(Integer integer) 498 { 499 languageId = integer; 500 } 501 502 public void setNewContentVO(ContentVO contentVO) 503 { 504 newContentVO = contentVO; 505 } 506 507 public void setTextAreaId(String string) 508 { 509 textAreaId = string; 510 } 511 512 } 513 | Popular Tags |