1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.apache.log4j.Logger; 32 import org.infoglue.cms.entities.content.ContentVO; 33 import org.infoglue.cms.entities.content.ContentVersionVO; 34 import org.infoglue.cms.exception.Bug; 35 import org.infoglue.cms.exception.ConstraintException; 36 import org.infoglue.cms.exception.SystemException; 37 import org.infoglue.cms.security.InfoGluePrincipal; 38 39 40 43 44 public class ContentVersionControllerProxy extends ContentVersionController 45 { 46 private final static Logger logger = Logger.getLogger(ContentVersionControllerProxy.class.getName()); 47 48 protected static final Integer NO = new Integer (0); 49 protected static final Integer YES = new Integer (1); 50 protected static final Integer INHERITED = new Integer (2); 51 52 private static List interceptors = new ArrayList (); 53 54 public static ContentVersionControllerProxy getController() 55 { 56 return new ContentVersionControllerProxy(); 57 } 58 59 86 87 90 91 public ContentVersionVO getACContentVersionVOWithId(InfoGluePrincipal infogluePrincipal, Integer contentVersionId) throws ConstraintException, SystemException, Bug, Exception 92 { 93 Map hashMap = new HashMap (); 94 hashMap.put("contentVersionId", contentVersionId); 95 96 intercept(hashMap, "ContentVersion.Read", infogluePrincipal); 97 98 return getContentVersionVOWithId(contentVersionId); 99 } 100 101 104 105 public ContentVersionVO getACLatestActiveContentVersionVO(InfoGluePrincipal infogluePrincipal, Integer contentId, Integer languageId) throws ConstraintException, SystemException, Bug, Exception 106 { 107 Map hashMap = new HashMap (); 108 hashMap.put("contentId", contentId); 109 hashMap.put("languageId", languageId); 110 111 intercept(hashMap, "ContentVersion.Read", infogluePrincipal); 112 113 return ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId); 114 } 115 116 117 118 119 122 123 public ContentVersionVO acCreate(InfoGluePrincipal infogluePrincipal, Integer contentId, Integer languageId, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception 124 { 125 Map hashMap = new HashMap (); 126 hashMap.put("contentId", contentId); 127 128 intercept(hashMap, "Content.CreateVersion", infogluePrincipal); 129 130 return ContentVersionController.getContentVersionController().create(contentId, languageId, contentVersionVO, null); 131 } 132 133 136 137 public ContentVersionVO acUpdate(InfoGluePrincipal infogluePrincipal, Integer contentId, Integer languageId, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception 138 { 139 logger.info("contentId:" + contentId); 140 logger.info("languageId:" + languageId); 141 logger.info("contentVersionId:" + contentVersionVO.getId()); 142 143 if(contentVersionVO.getId() != null) 144 { 145 Map hashMap = new HashMap (); 146 hashMap.put("contentVersionId", contentVersionVO.getId()); 147 148 intercept(hashMap, "ContentVersion.Write", infogluePrincipal); 149 } 150 else 151 { 152 Map hashMap = new HashMap (); 153 hashMap.put("contentId", contentId); 154 155 intercept(hashMap, "Content.CreateVersion", infogluePrincipal); 156 } 157 158 return ContentVersionController.getContentVersionController().update(contentId, languageId, contentVersionVO); 159 } 160 161 164 165 public void acDelete(InfoGluePrincipal infogluePrincipal, ContentVersionVO contentVersionVO) throws ConstraintException, SystemException, Bug, Exception 166 { 167 Map hashMap = new HashMap (); 168 hashMap.put("contentVersionId", contentVersionVO.getId()); 169 170 intercept(hashMap, "ContentVersion.Delete", infogluePrincipal); 171 172 ContentVersionController.getContentVersionController().delete(contentVersionVO); 173 } 174 175 176 179 180 public boolean getIsContentProtected(Integer contentId, boolean inherit) 181 { 182 boolean isContentProtected = false; 183 184 logger.info("getIsContentProtected contentId:" + contentId); 185 try 186 { 187 ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId); 188 if(contentVO.getIsProtected() != null) 189 { 190 if(contentVO.getIsProtected().intValue() == NO.intValue()) 191 isContentProtected = false; 192 else if(contentVO.getIsProtected().intValue() == YES.intValue()) 193 isContentProtected = true; 194 else if(contentVO.getIsProtected().intValue() == INHERITED.intValue()) 195 { 196 if(inherit) 197 { 198 ContentVO parentContentVO = ContentController.getParentContent(contentId); 199 if(parentContentVO != null) 200 isContentProtected = getIsContentProtected(parentContentVO.getId(), inherit); 201 } 202 } 203 } 204 205 } 206 catch(Exception e) 207 { 208 logger.warn("An error occurred trying to get if the content was protected:" + e.getMessage(), e); 209 } 210 211 logger.info("isContentProtected:" + isContentProtected); 212 213 return isContentProtected; 214 } 215 216 } 217 | Popular Tags |