1 23 24 package org.infoglue.cms.applications.contenttool.actions; 25 26 import java.util.Collections ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.infoglue.cms.applications.common.VisualFormatter; 32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 33 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 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.entities.content.ContentVO; 37 import org.infoglue.cms.exception.AccessConstraintException; 38 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 39 import org.infoglue.cms.util.CmsPropertyHandler; 40 import org.infoglue.cms.util.ConstraintExceptionBuffer; 41 import org.infoglue.cms.util.sorters.ReflectionComparator; 42 43 import com.opensymphony.module.propertyset.PropertySet; 44 import com.opensymphony.module.propertyset.PropertySetManager; 45 46 49 50 public class CreateContentAction extends InfoGlueAbstractAction 51 { 52 private static final long serialVersionUID = 1L; 53 54 private Integer parentContentId; 55 private Integer contentTypeDefinitionId; 56 private Integer repositoryId; 57 private ConstraintExceptionBuffer ceb; 58 private ContentVO contentVO; 59 private ContentVO newContentVO; 60 private String defaultFolderContentTypeName; 61 private String allowedContentTypeNames; 62 private String defaultContentTypeName; 63 64 public CreateContentAction() 65 { 66 this(new ContentVO()); 67 } 68 69 public CreateContentAction(ContentVO contentVO) 70 { 71 this.contentVO = contentVO; 72 this.ceb = new ConstraintExceptionBuffer(); 73 } 74 75 public void setParentContentId(Integer parentContentId) 76 { 77 this.parentContentId = parentContentId; 78 } 79 80 public Integer getParentContentId() 81 { 82 return this.parentContentId; 83 } 84 85 public void setRepositoryId(Integer repositoryId) 86 { 87 this.repositoryId = repositoryId; 88 } 89 90 public Integer getRepositoryId() 91 { 92 return this.repositoryId; 93 } 94 95 public void setContentTypeDefinitionId(Integer contentTypeDefinitionId) 96 { 97 this.contentTypeDefinitionId = contentTypeDefinitionId; 98 } 99 100 public Integer getContentTypeDefinitionId() 101 { 102 return this.contentTypeDefinitionId; 103 } 104 105 public java.lang.String getName() 106 { 107 return this.contentVO.getName(); 108 } 109 110 public String getPublishDateTime() 111 { 112 return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm"); 113 } 114 115 public String getExpireDateTime() 116 { 117 return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm"); 118 } 119 120 public long getPublishDateTimeAsLong() 121 { 122 return this.contentVO.getPublishDateTime().getTime(); 123 } 124 125 public long getExpireDateTimeAsLong() 126 { 127 return this.contentVO.getExpireDateTime().getTime(); 128 } 129 130 public Boolean getIsBranch() 131 { 132 return this.contentVO.getIsBranch(); 133 } 134 135 public void setName(java.lang.String name) 136 { 137 this.contentVO.setName(name); 138 } 139 140 public void setPublishDateTime(String publishDateTime) 141 { 142 this.contentVO.setPublishDateTime(new VisualFormatter().parseDate(publishDateTime, "yyyy-MM-dd HH:mm")); 143 } 144 145 public void setExpireDateTime(String expireDateTime) 146 { 147 this.contentVO.setExpireDateTime(new VisualFormatter().parseDate(expireDateTime, "yyyy-MM-dd HH:mm")); 148 } 149 150 public void setIsBranch(Boolean isBranch) 151 { 152 this.contentVO.setIsBranch(isBranch); 153 } 154 155 public Integer getContentId() 156 { 157 return newContentVO.getContentId(); 158 } 159 160 public String getDefaultFolderContentTypeName() 161 { 162 return defaultFolderContentTypeName; 163 } 164 165 168 169 public List getContentTypeDefinitions() throws Exception 170 { 171 List contentTypeVOList = null; 172 173 String protectContentTypes = CmsPropertyHandler.getProtectContentTypes(); 174 if(protectContentTypes != null && protectContentTypes.equalsIgnoreCase("true")) 175 contentTypeVOList = ContentTypeDefinitionController.getController().getAuthorizedContentTypeDefinitionVOList(this.getInfoGluePrincipal()); 176 else 177 contentTypeVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList(); 178 179 Collections.sort(contentTypeVOList, new ReflectionComparator("name")); 180 181 return contentTypeVOList; 182 } 183 184 185 public String doExecute() throws Exception 186 { 187 this.contentVO.setCreatorName(this.getInfoGluePrincipal().getName()); 188 189 ceb = this.contentVO.validate(); 190 ceb.throwIfNotEmpty(); 191 192 newContentVO = ContentControllerProxy.getController().acCreate(this.getInfoGluePrincipal(), parentContentId, contentTypeDefinitionId, repositoryId, contentVO); 193 195 if ( newContentVO.getIsBranch().booleanValue() ) 196 { 197 Map args = new HashMap (); 198 args.put("globalKey", "infoglue"); 199 PropertySet ps = PropertySetManager.getInstance("jdbc", args); 200 201 String allowedContentTypeNames = ps.getString("content_" + this.getParentContentId() + "_allowedContentTypeNames"); 202 String defaultContentTypeName = ps.getString("content_" + this.getParentContentId() + "_defaultContentTypeName"); 203 String initialLanguageId = ps.getString("content_" + this.getParentContentId() + "_initialLanguageId"); 204 205 if ( allowedContentTypeNames != null ) 206 { 207 ps.setString("content_" + this.getContentId() + "_allowedContentTypeNames", allowedContentTypeNames ); 208 } 209 if ( defaultContentTypeName != null ) 210 { 211 ps.setString("content_" + this.getContentId() + "_defaultContentTypeName", defaultContentTypeName ); 212 } 213 if ( initialLanguageId != null ) 214 { 215 ps.setString("content_" + this.getContentId() + "_initialLanguageId", initialLanguageId ); 216 } 217 } 218 return "success"; 219 } 220 221 public String doBindingView() throws Exception 222 { 223 doExecute(); 224 return "bindingView"; 225 } 226 227 public String doTreeView() throws Exception 228 { 229 doExecute(); 230 return "treeView"; 231 } 232 233 public String doInput() throws Exception 234 { 235 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 236 237 Integer protectedContentId = ContentControllerProxy.getController().getProtectedContentId(parentContentId); 238 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.Create", protectedContentId.toString())) 239 ceb.add(new AccessConstraintException("Content.contentId", "1002")); 240 241 Map args = new HashMap (); 242 args.put("globalKey", "infoglue"); 243 PropertySet ps = PropertySetManager.getInstance("jdbc", args); 244 245 if(this.getIsBranch().booleanValue()) 246 { 247 this.defaultFolderContentTypeName = ps.getString("repository_" + this.getRepositoryId() + "_defaultFolderContentTypeName"); 248 } 249 else 250 { 251 this.defaultContentTypeName = ps.getString("content_" + this.parentContentId + "_defaultContentTypeName"); 252 } 253 if ( ps.exists( "content_" + this.parentContentId + "_allowedContentTypeNames" ) ) 254 { 255 this.allowedContentTypeNames = ps.getString("content_" + this.parentContentId + "_allowedContentTypeNames"); 256 } 257 ceb.throwIfNotEmpty(); 258 259 return "input"; 260 } 261 262 public String getAllowedContentTypeNames() 263 { 264 return allowedContentTypeNames; 265 } 266 267 public String getDefaultContentTypeName() 268 { 269 return defaultContentTypeName; 270 } 271 } 272 | Popular Tags |