1 23 24 package org.infoglue.cms.applications.contenttool.actions; 25 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 import org.apache.log4j.Logger; 33 import org.infoglue.cms.applications.common.VisualFormatter; 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.ContentTypeDefinitionController; 38 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 39 import org.infoglue.cms.controllers.kernel.impl.simple.EventController; 40 import org.infoglue.cms.controllers.kernel.impl.simple.InfoGlueSettingsController; 41 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 42 import org.infoglue.cms.controllers.kernel.impl.simple.RegistryController; 43 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryLanguageController; 44 import org.infoglue.cms.entities.content.Content; 45 import org.infoglue.cms.entities.content.ContentVO; 46 import org.infoglue.cms.entities.content.ContentVersion; 47 import org.infoglue.cms.entities.content.ContentVersionVO; 48 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 49 import org.infoglue.cms.entities.management.LanguageVO; 50 import org.infoglue.cms.entities.workflow.EventVO; 51 import org.infoglue.cms.exception.AccessConstraintException; 52 import org.infoglue.cms.exception.Bug; 53 import org.infoglue.cms.exception.ConstraintException; 54 import org.infoglue.cms.exception.SystemException; 55 import org.infoglue.cms.util.AccessConstraintExceptionBuffer; 56 import org.infoglue.cms.util.CmsPropertyHandler; 57 import org.infoglue.cms.util.sorters.ReflectionComparator; 58 59 import webwork.action.Action; 60 61 import com.opensymphony.module.propertyset.PropertySet; 62 import com.opensymphony.module.propertyset.PropertySetManager; 63 64 public class ViewContentAction extends InfoGlueAbstractAction 65 { 66 private final static Logger logger = Logger.getLogger(ViewContentAction.class.getName()); 67 68 private static final long serialVersionUID = 1L; 69 70 private Integer unrefreshedContentId = new Integer (0); 71 private Integer changeTypeId = new Integer (0); 72 private Integer repositoryId = null; 73 private List availableLanguages = null; 74 private ContentTypeDefinitionVO contentTypeDefinitionVO; 75 private String defaultFolderContentTypeName; 76 private Integer languageId = null; 77 private String stay = null; 78 private List referenceBeanList = new ArrayList (); 79 80 private ContentVO contentVO; 81 82 83 public ViewContentAction() 84 { 85 this(new ContentVO()); 86 } 87 88 public ViewContentAction(ContentVO contentVO) 89 { 90 this.contentVO = contentVO; 91 } 92 93 protected void initialize(Integer contentId) throws Exception 94 { 95 this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId); 96 this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentId); 97 this.availableLanguages = RepositoryLanguageController.getController().getAvailableLanguageVOListForRepositoryId(this.contentVO.getRepositoryId()); 98 99 if(this.repositoryId == null) 100 this.repositoryId = this.contentVO.getRepositoryId(); 101 102 if(this.contentVO.getRepositoryId() != null && !hasAccessTo("Repository.Read", "" + this.contentVO.getRepositoryId())) 103 { 104 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 105 ceb.add(new AccessConstraintException("Content.contentId", "1000")); 106 ceb.throwIfNotEmpty(); 107 } 108 109 if(this.getIsBranch().booleanValue()) 110 { 111 this.defaultFolderContentTypeName = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("repository_" + this.getRepositoryId() + "_defaultFolderContentTypeName", "applicationProperties", null, false, false, false, false, null); 112 } 113 114 this.referenceBeanList = RegistryController.getController().getReferencingObjectsForContent(contentId); 115 } 116 117 public String doExecute() throws Exception 118 { 119 try 120 { 121 ContentVO contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), getContentId()); 122 123 if(contentVO.getRepositoryId() != null && !hasAccessTo("Repository.Read", "" + contentVO.getRepositoryId())) 124 { 125 System.out.println("You had no access to Repository.Read and " + this.contentVO.getRepositoryId()); 126 AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer(); 127 ceb.add(new AccessConstraintException("Content.contentId", "1000")); 128 ceb.throwIfNotEmpty(); 129 } 130 131 if((this.stay == null || !this.stay.equalsIgnoreCase("true")) && contentVO.getIsBranch().booleanValue() == false && contentVO.getContentTypeDefinitionId() != null && getShowContentVersionFirst().equalsIgnoreCase("true")) 132 { 133 if(this.repositoryId == null) 134 this.repositoryId = contentVO.getRepositoryId(); 135 136 this.languageId = getInitialLanguageVO().getId(); 138 return "viewVersion"; 139 } 140 else 141 { 142 this.initialize(getContentId()); 143 return "success"; 144 } 145 } 146 catch(ConstraintException ce) 147 { 148 throw ce; 149 } 150 catch(Exception e) 151 { 152 e.printStackTrace(); 153 } 154 155 return Action.NONE; 156 } 157 158 public String doStandalone() throws Exception 159 { 160 this.initialize(getContentId()); 161 return "standalone"; 162 } 163 164 public java.lang.Integer getContentId() 165 { 166 return this.contentVO.getContentId(); 167 } 168 169 public void setContentId(java.lang.Integer contentId) 170 { 171 this.contentVO.setContentId(contentId); 172 } 173 174 public java.lang.Integer getRepositoryId() 175 { 176 return this.repositoryId; 177 } 178 179 public void setRepositoryId(java.lang.Integer repositoryId) 180 { 181 this.repositoryId = repositoryId; 182 } 183 184 public java.lang.Integer getUnrefreshedContentId() 185 { 186 return this.unrefreshedContentId; 187 } 188 189 public void setUnrefreshedContentId(java.lang.Integer unrefreshedContentId) 190 { 191 this.unrefreshedContentId = unrefreshedContentId; 192 } 193 194 public java.lang.Integer getChangeTypeId() 195 { 196 return this.changeTypeId; 197 } 198 199 public void setChangeTypeId(java.lang.Integer changeTypeId) 200 { 201 this.changeTypeId = changeTypeId; 202 } 203 204 public java.lang.Integer getNewContentId() 205 { 206 return this.contentVO.getId(); 207 } 208 209 public String getName() 210 { 211 return this.contentVO.getName(); 212 } 213 214 public String getPublishDateTime() 215 { 216 return new VisualFormatter().formatDate(this.contentVO.getPublishDateTime(), "yyyy-MM-dd HH:mm"); 217 } 218 219 public String getExpireDateTime() 220 { 221 return new VisualFormatter().formatDate(this.contentVO.getExpireDateTime(), "yyyy-MM-dd HH:mm"); 222 } 223 224 public long getPublishDateTimeAsLong() 225 { 226 return this.contentVO.getPublishDateTime().getTime(); 227 } 228 229 public long getExpireDateTimeAsLong() 230 { 231 return this.contentVO.getExpireDateTime().getTime(); 232 } 233 234 public Boolean getIsBranch() 235 { 236 return this.contentVO.getIsBranch(); 237 } 238 239 public Integer getIsProtected() 240 { 241 return this.contentVO.getIsProtected(); 242 } 243 244 public ContentTypeDefinitionVO getContentTypeDefinition() 245 { 246 return this.contentTypeDefinitionVO; 247 } 248 249 public List getAvailableLanguages() 250 { 251 return this.availableLanguages; 252 } 253 254 255 public ContentVersionVO getLatestContentVersionVO(Integer contentId, Integer languageId) 256 { 257 ContentVersionVO contentVersionVO = null; 258 try 259 { 260 contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId); 261 } 262 catch(Exception e) 263 { 264 logger.error("An error occurred when we tried to get the latest version for the content:" + e.getMessage(), e); 265 } 266 267 return contentVersionVO; 268 } 269 270 271 272 public EventVO getContentVersionEvent(Integer contentVersionId) 273 { 274 EventVO eventVO = null; 275 try 276 { 277 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId); 278 List events = EventController.getEventVOListForEntity(ContentVersion.class.getName(), contentVersion.getId()); 279 if(events != null && events.size() > 0) 280 eventVO = (EventVO)events.get(0); 281 } 282 catch(Exception e) 283 { 284 logger.error("An error occurred when we tried to get any events for this version:" + e.getMessage(), e); 285 } 286 287 return eventVO; 288 } 289 290 public EventVO getContentEvent(Integer contentId) 291 { 292 EventVO eventVO = null; 293 try 294 { 295 List events = EventController.getEventVOListForEntity(Content.class.getName(), contentId); 296 if(events != null && events.size() > 0) 297 eventVO = (EventVO)events.get(0); 298 } 299 catch(Exception e) 300 { 301 logger.error("An error occurred when we tried to get any events for this version:" + e.getMessage(), e); 302 } 303 304 return eventVO; 305 } 306 307 public Integer getMasterLanguageId() 308 { 309 try 310 { 311 return LanguageController.getController().getMasterLanguage(repositoryId).getLanguageId(); 312 } 313 catch (Exception e) 314 { 315 logger.error("Unable to get master language for repository", e); 316 } 317 return null; 318 } 319 320 public ContentVO getContentVO() 321 { 322 return contentVO; 323 } 324 325 328 329 public List getContentTypeDefinitions() throws Exception 330 { 331 List contentTypeVOList = null; 332 333 String protectContentTypes = CmsPropertyHandler.getProtectContentTypes(); 334 if(protectContentTypes != null && protectContentTypes.equalsIgnoreCase("true")) 335 contentTypeVOList = ContentTypeDefinitionController.getController().getAuthorizedContentTypeDefinitionVOList(this.getInfoGluePrincipal()); 336 else 337 contentTypeVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList(); 338 339 Collections.sort(contentTypeVOList, new ReflectionComparator("name")); 340 341 return contentTypeVOList; 342 } 343 344 345 public List getContentPath() 346 { 347 ContentVO contentVO = this.contentVO; 348 List ret = new ArrayList (); 349 351 while (contentVO.getParentContentId() != null) 352 { 353 try { 354 contentVO = ContentControllerProxy.getController().getContentVOWithId(contentVO.getParentContentId()); 355 } catch (SystemException e) { 356 e.printStackTrace(); 358 } catch (Bug e) { 359 e.printStackTrace(); 361 } 362 ret.add(0, contentVO); 363 } 364 return ret; 365 } 366 367 public void setContentVO(ContentVO contentVO) 368 { 369 this.contentVO = contentVO; 370 } 371 372 public String getDefaultFolderContentTypeName() 373 { 374 return defaultFolderContentTypeName; 375 } 376 377 public String getShowContentVersionFirst() 378 { 379 return CmsPropertyHandler.getShowContentVersionFirst(); 380 } 381 382 public LanguageVO getMasterLanguageVO() throws Exception 383 { 384 return LanguageController.getController().getMasterLanguage(repositoryId); 385 } 386 387 public LanguageVO getInitialLanguageVO() throws Exception 388 { 389 String initialLanguageId = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("content_" + this.getContentId() + "_initialLanguageId", "applicationProperties", null, false, false, false, false, null); 390 ContentVO parentContentVO = ContentController.getContentController().getParentContent(this.getContentId()); 391 while((initialLanguageId == null || initialLanguageId.equalsIgnoreCase("-1")) && parentContentVO != null) 392 { 393 initialLanguageId = InfoGlueSettingsController.getInfoGlueSettingsController().getProperty("content_" + parentContentVO.getId() + "_initialLanguageId", "applicationProperties", null, false, false, false, false, null); 395 parentContentVO = ContentController.getContentController().getParentContent(parentContentVO.getId()); 396 } 397 398 if(initialLanguageId != null && !initialLanguageId.equals("") && !initialLanguageId.equals("-1")) 399 return LanguageController.getController().getLanguageVOWithId(new Integer (initialLanguageId)); 400 else 401 return LanguageController.getController().getMasterLanguage(repositoryId); 402 } 403 404 public Integer getLanguageId() 405 { 406 return languageId; 407 } 408 409 public String getStay() 410 { 411 return stay; 412 } 413 414 public void setStay(String stay) 415 { 416 this.stay = stay; 417 } 418 419 public List getReferenceBeanList() 420 { 421 return referenceBeanList; 422 } 423 } 424 | Popular Tags |